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); }
public void Close() { if (this._dest != null) { this._dest.Synch(); this._dest.Close(); this._dest = null; } }
private void OpenFile() { try { string name = this._database.GetPath() + ".lobs"; bool rdy = this._database.IsReadOnly(); this._file = ScaledRAFile.NewScaledRAFile(this._database, name, rdy, this._database.IsFilesInAssembly()); } catch (Exception exception) { throw Error.GetError(0x1d2, exception); } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (this._shadowFile != null) { this._shadowFile.Dispose(); } ((RowInputBinaryDecode)this.RowIn).Dispose(); ((RowOutputBinaryEncode)this.RowOut).Dispose(); if (this.DataFile != null) { this.DataFile.Dispose(); this.DataFile = null; } } }
public static void RestoreFile(Database database, string sourceName, string destName) { using (IScaledRAInterface interface2 = ScaledRAFile.NewScaledRAFile(database, sourceName, true, database.IsFilesInAssembly())) { using (IScaledRAInterface interface3 = ScaledRAFile.NewScaledRAFile(database, destName, false, database.IsFilesInAssembly())) { while (interface2.GetFilePointer() != interface2.Length()) { int length = interface2.ReadInt(); long position = interface2.ReadLong(); byte[] b = new byte[length]; interface2.Read(b, 0, length); interface3.Seek(position); interface3.Write(b, 0, length); } } } }
public void Process() { bool flag = false; Error.PrintSystemOut(FwNs.Core.LC.cResources.SR.DataFileDefrag_Process_Defrag_process_begins); this._transactionRowLookup = this._database.TxManager.GetTransactionIDList(); Error.PrintSystemOut(FwNs.Core.LC.cResources.SR.DataFileDefrag_Process_transaction_count__ + this._transactionRowLookup.Size()); List <Table> allTables = this._database.schemaManager.GetAllTables(); this._rootsList = new int[allTables.Count][]; IScaledRAInterface interface2 = null; try { Stream stream = this._database.logger.GetFileAccess().OpenOutputStreamElement(this._dataFileName + ".new"); this._fileStreamOut = new BufferedStream(stream, 0x1000); for (int i = 0; i < this._cache.InitialFreePos; i++) { this._fileStreamOut.WriteByte(0); } this._fileOffset = this._cache.InitialFreePos; int index = 0; int count = allTables.Count; while (index < count) { Table table = allTables[index]; if (table.GetTableType() == 5) { this._rootsList[index] = this.WriteTableToDataFile(table); } else { this._rootsList[index] = null; } Error.PrintSystemOut(FwNs.Core.LC.cResources.SR.DataFileDefrag_WriteTableToDataFile_table__ + table.GetName().Name + FwNs.Core.LC.cResources.SR.DataFileDefrag_Process__complete); index++; } this._fileStreamOut.Flush(); this._fileStreamOut.Close(); this._fileStreamOut = null; interface2 = ScaledRAFile.NewScaledRAFile(this._database, this._dataFileName + ".new", false, this._database.IsFilesInAssembly()); interface2.Seek(12L); interface2.WriteLong(this._fileOffset); int map = 0; if (this._database.logger.PropIncrementBackup) { map = BitMap.Set(map, 1); } map = BitMap.Set(BitMap.Set(map, 4), 2); interface2.Seek(0x1cL); interface2.WriteInt(map); int num4 = 0; int length = this._rootsList.Length; while (num4 < length) { int[] s = this._rootsList[num4]; if (s != null) { Error.PrintSystemOut(FwNs.Core.LC.cResources.SR.DataFileDefrag_Process_roots__ + StringUtil.GetList(s, ",", "")); } num4++; } flag = true; } catch (IOException exception) { throw Error.GetError(0x1c4, exception); } catch (OutOfMemoryException exception2) { throw Error.GetError(460, exception2); } catch (Exception exception3) { throw Error.GetError(0x1ca, exception3); } finally { try { if (this._fileStreamOut != null) { this._fileStreamOut.Close(); } if (interface2 != null) { interface2.Dispose(); } } catch (Exception exception4) { this._database.logger.LogSevereEvent(FwNs.Core.LC.cResources.SR.DataFileDefrag_Process_backupFile_failed, exception4); } if (!flag) { this._database.logger.GetFileAccess().RemoveElement(this._dataFileName + ".new"); } } Error.PrintSystemOut(FwNs.Core.LC.cResources.SR.DataFileDefrag_Process_Defrag_transfer_complete__ + this._stopw.ElapsedTime()); }
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); } }
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); } }
private void Open() { this._dest = ScaledRAFile.NewScaledRAFile(this._database, this._pathName, false, this._database.IsFilesInAssembly()); }