Example #1
0
 public virtual void InitParams(Database database, string baseFileName)
 {
     this.DataFileName     = baseFileName + ".data";
     this.BackupFileName   = baseFileName + ".backup";
     this.database         = database;
     this.Fa               = database.logger.GetFileAccess();
     this.CacheFileScale   = database.logger.GetCacheFileScale();
     this.CachedRowPadding = 8;
     if (this.CacheFileScale > 8)
     {
         this.CachedRowPadding = this.CacheFileScale;
     }
     if (this.InitialFreePos < this.CacheFileScale)
     {
         this.InitialFreePos = this.CacheFileScale;
     }
     this.CacheReadonly   = database.logger.PropFilesReadOnly;
     this.MaxCacheRows    = database.logger.PropCacheMaxRows;
     this.MaxCacheBytes   = database.logger.PropCacheMaxSize;
     this.MaxDataFileSize = 0x7fffffffL * this.CacheFileScale;
     this.MaxFreeBlocks   = database.logger.PropMaxFreeBlocks;
     this.DataFile        = null;
     this._shadowFile     = null;
     this.cache           = new Cache(this);
 }
Example #2
0
        private bool RestoreBackupIncremental()
        {
            bool flag;

            try
            {
                if (this.Fa.IsStreamElement(this.BackupFileName))
                {
                    RAShadowFile.RestoreFile(this.database, this.BackupFileName, this.DataFileName);
                    this.DeleteBackup();
                    return(true);
                }
                flag = false;
            }
            catch (IOException exception)
            {
                throw Error.GetError(0x1c4, exception);
            }
            return(flag);
        }
Example #3
0
 public virtual void Close(bool write)
 {
     Monitor.Enter(this.Lock);
     try
     {
         if (this.CacheReadonly)
         {
             if (this.DataFile != null)
             {
                 this.DataFile.Close();
                 this.DataFile = null;
             }
         }
         else
         {
             this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_DataFileCache_close_ + write.ToString() + FwNs.Core.LC.cResources.SR.DataFileCache_Close_____start);
             if (write)
             {
                 this.cache.SaveAll();
                 this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_DataFileCache_close_____save_data);
                 if (this.FileModified || this.FreeBlocks.IsModified())
                 {
                     this.DataFile.Seek(4L);
                     this.DataFile.WriteLong(this.FreeBlocks.GetLostBlocksSize());
                     this.DataFile.Seek(12L);
                     this.DataFile.WriteLong(this.FileFreePosition);
                     this.DataFile.Seek(0x1cL);
                     int i = BitMap.Set(this.DataFile.ReadInt(), 2);
                     this.DataFile.Seek(0x1cL);
                     this.DataFile.WriteInt(i);
                     this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_DataFileCache_close_____flags);
                     this.DataFile.Seek(this.FileFreePosition);
                     this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_DataFileCache_close_____seek_end);
                 }
             }
             if (this.DataFile != null)
             {
                 this.DataFile.Close();
                 this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_DataFileCache_close_____close);
                 this.DataFile = null;
             }
             if (this._shadowFile != null)
             {
                 this._shadowFile.Close();
                 this._shadowFile = null;
             }
             if (this.FileFreePosition == this.InitialFreePos)
             {
                 this.DeleteFile();
                 this.DeleteBackup();
             }
         }
     }
     catch (Exception exception)
     {
         this.database.logger.LogSevereEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Close_Close_failed, exception);
         object[] add = new object[] { exception.Message, this.DataFileName };
         throw Error.GetError(exception, 0x1c4, 0x35, add);
     }
     finally
     {
         Monitor.Exit(this.Lock);
     }
 }
Example #4
0
 public virtual void Open(bool rdy)
 {
     this.FileFreePosition = 0L;
     this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Open_open_start);
     try
     {
         if (rdy || this.database.IsFilesInAssembly())
         {
             this.DataFile = ScaledRAFile.NewScaledRAFile(this.database, this.DataFileName, rdy, this.database.IsFilesInAssembly());
             this.InitBuffers();
         }
         else
         {
             bool flag     = false;
             long lostSize = 0L;
             if (this.Fa.IsStreamElement(this.DataFileName))
             {
                 flag = true;
             }
             this.DataFile = ScaledRAFile.NewScaledRAFile(this.database, this.DataFileName, rdy, this.database.IsFilesInAssembly());
             if (flag)
             {
                 this.DataFile.Seek(0x1cL);
                 int map = this.DataFile.ReadInt();
                 this.database.logger.PropIncrementBackup = BitMap.IsSet(map, 1);
                 if (!BitMap.IsSet(map, 2))
                 {
                     bool flag2;
                     this.DataFile.Close();
                     if (this.database.logger.PropIncrementBackup)
                     {
                         flag2 = this.RestoreBackupIncremental();
                     }
                     else
                     {
                         flag2 = this.RestoreBackup();
                     }
                     this.DataFile = ScaledRAFile.NewScaledRAFile(this.database, this.DataFileName, rdy, this.database.IsFilesInAssembly());
                     if (!flag2)
                     {
                         this.InitNewFile();
                     }
                 }
                 this.DataFile.Seek(4L);
                 lostSize = this.DataFile.ReadLong();
                 this.DataFile.Seek(12L);
                 this.FileFreePosition = this.DataFile.ReadLong();
                 if (this.FileFreePosition < this.InitialFreePos)
                 {
                     this.FileFreePosition = this.InitialFreePos;
                 }
                 if (this.database.logger.PropIncrementBackup && (this.FileFreePosition != this.InitialFreePos))
                 {
                     this._shadowFile = new RAShadowFile(this.database, this.DataFile, this.BackupFileName, this.FileFreePosition, 0x4000);
                 }
             }
             else
             {
                 this.InitNewFile();
             }
             this.InitBuffers();
             this.FileModified = false;
             this.FreeBlocks   = new DataFileBlockManager(this.MaxFreeBlocks, this.CacheFileScale, lostSize);
             this.database.logger.LogInfoEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Open_open_end);
         }
     }
     catch (Exception exception)
     {
         this.database.logger.LogSevereEvent(FwNs.Core.LC.cResources.SR.DataFileCache_Open_open_failed, exception);
         this.Close(false);
         object[] add = new object[] { exception.Message, this.DataFileName };
         throw Error.GetError(exception, 0x1c4, 0x34, add);
     }
 }