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()); }