/[RomCheater]/trunk/RomCheater/Serialization/SearchResultWriter.cs
ViewVC logotype

Diff of /trunk/RomCheater/Serialization/SearchResultWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 445 by william, Sun Jun 2 19:21:16 2013 UTC revision 491 by william, Mon Jun 3 21:32:55 2013 UTC
# Line 1  Line 1 
1  ´╗┐using System;  ´╗┐#region Logging Defines
2    // include this any class or method that required logging, and comment-out what is not needed
3    
4    #region Enabled logging levels
5    #define LOGGING_ENABLE_INFO
6    #define LOGGING_ENABLE_WARN
7    #define LOGGING_ENABLE_DEBUG
8    #define LOGGING_ENABLE_VERBOSEDEBUG
9    #define LOGGING_ENABLE_ERROR
10    #define LOGGING_ENABLE_VERBOSEERROR
11    #define LOGGING_ENABLE_PROFILER
12    #endregion
13    #endregion
14    using System;
15  using System.Collections.Generic;  using System.Collections.Generic;
16  using System.Linq;  using System.Linq;
17  using System.Text;  using System.Text;
# Line 15  namespace RomCheater.Serialization Line 28  namespace RomCheater.Serialization
28      {      {
29    
30          private int ResultsWritten = 0;          private int ResultsWritten = 0;
31            protected override string TemporaryFolder { get { return SearchResultsConstants.SearchResultsFolder; } }
32          //public SearchResultWriter() : base() { }          //public SearchResultWriter() : base() { }
33          public SearchResultWriter(int resultCount, Guid guid) : base(resultCount, guid) { WriteHeader(guid); }          public SearchResultWriter(int resultCount, Guid guid) : this(resultCount, guid,false) {  }
34            public SearchResultWriter(int resultCount, Guid guid, bool delete) : base(resultCount, guid,delete) { WriteHeader(guid); }
35          //public SearchResultWriter(string filename, Guid guid) : base(CreateFileName(filename,guid), guid) { WriteHeader(guid); }          //public SearchResultWriter(string filename, Guid guid) : base(CreateFileName(filename,guid), guid) { WriteHeader(guid); }
36          //public SearchResultWriter(string filename, int resultCount, Guid guid) : base(filename, resultCount, guid, false) { WriteHeader(guid); }          //public SearchResultWriter(string filename, int resultCount, Guid guid) : base(filename, resultCount, guid, false) { WriteHeader(guid); }
37          //public SearchResultWriter(string filename, int resultCount, Guid guid, bool delete) : base(filename, resultCount, guid, delete) { WriteHeader(guid); }                //public SearchResultWriter(string filename, int resultCount, Guid guid, bool delete) : base(filename, resultCount, guid, delete) { WriteHeader(guid); }      
# Line 65  namespace RomCheater.Serialization Line 79  namespace RomCheater.Serialization
79          }          }
80          #endregion          #endregion
81    
82            long ResultCountOffset = 0;
83          private void WriteHeader(Guid guid)          private void WriteHeader(Guid guid)
84          {          {
85              try              try
# Line 86  namespace RomCheater.Serialization Line 101  namespace RomCheater.Serialization
101                  }                  }
102                  // write count (int)                  // write count (int)
103                  binWriter.Write(ResultCount);                  binWriter.Write(ResultCount);
104                    ResultCountOffset = binWriter.BaseStream.Position - sizeof(int);
105              }              }
106              catch (Exception ex)              catch (Exception ex)
107              {              {
# Line 95  namespace RomCheater.Serialization Line 111  namespace RomCheater.Serialization
111    
112          protected override void Dispose(bool disposing)          protected override void Dispose(bool disposing)
113          {          {
114                if (Cancelled) { binWriter.Close(); fileStream.Close(); return; }
115              try              try
116              {              {
117                  base.Dispose(disposing);                
118                  // ensure ResultCount and ResultsWritten are equal                              //// ensure ResultCount and ResultsWritten are equal            
119                    //if (ResultCount != ResultsWritten)
120                    //{
121                    //    string message = string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8} -- offset: 0x{2:x8}", ResultCount, ResultsWritten, ResultCount - ResultsWritten);
122                    //    Logging.logger.Error.WriteLine(message);
123                    //    throw new InvalidOperationException(message);
124                    //}
125                  if (ResultCount != ResultsWritten)                  if (ResultCount != ResultsWritten)
126                  {                  {
127                      string message = string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8} -- offset: 0x{2:x8}", ResultCount, ResultsWritten, ResultCount - ResultsWritten);                      // update the number of results written
128                      Logging.logger.Error.WriteLine(message);                      binWriter.BaseStream.Seek(ResultCountOffset, SeekOrigin.Begin);
129                      throw new InvalidOperationException(message);                      binWriter.Write(ResultsWritten);
130                  }                  }
131                    base.Dispose(disposing);
132              }              }
133              catch (Exception ex)              catch (Exception ex)
134              {              {

Legend:
Removed from v.445  
changed lines
  Added in v.491

  ViewVC Help
Powered by ViewVC 1.1.22