public void Open(long journalNumber) { if (IsOpen) { throw new IOException(String.Format("Journal file '{0}' is already open.", FilePath)); } if (FileSystem.FileExists(FilePath)) { throw new IOException(String.Format("Journal file '{0}' already exists.", FilePath)); } JournalNumber = journalNumber; File = new StreamFile(FileSystem, FilePath, ReadOnly); #if PCL dataOut = new BinaryWriter(File.FileStream, Encoding.Unicode); #else dataOut = new BinaryWriter(new BufferedStream(File.FileStream), Encoding.Unicode); #endif dataOut.Write(journalNumber); IsOpen = true; }
public StreamFileStream(StreamFile file) { this.file = file; }
internal JournalSummary OpenForRecovery() { if (IsOpen) throw new IOException(String.Format("Journal file '{0}' is already open.", FilePath)); if (!FileSystem.FileExists(FilePath)) throw new IOException(String.Format("Journal file '{0}' does not exists.", FilePath)); // Open the random access file to this journal File = new StreamFile(FileSystem, FilePath, ReadOnly); IsOpen = true; // Create the summary object (by default, not recoverable). var summary = new JournalSummary(this); long endPointer = File.Length; // If end_pointer < 8 then can't recover this journal if (endPointer < 8) { return summary; } // The input stream. using (var reader = new BinaryReader(File.FileStream, Encoding.Unicode)) { // Set the journal number for this JournalNumber = reader.ReadInt64(); long position = 8; var checkpointResList = new List<string>(); // Start scan while (true) { // If we can't Read 12 bytes ahead, return the summary if (position + 12 > endPointer) { return summary; } long type = reader.ReadInt64(); int size = reader.ReadInt32(); position = position + size + 12; bool skipBody = true; // If checkpoint reached then we are recoverable if (type == 100) { summary.LastCheckPoint = position; summary.CanBeRecovered = true; // Add the resources input this check point foreach (var checkpoint in checkpointResList) { summary.Resources.Add(checkpoint); } // And clear the temporary list. checkpointResList.Clear(); } // If end reached, or type is not understood then return else if (position >= endPointer || type < 1 || type > 7) { return summary; } // If we are resource type, then load the resource if (type == 2) { // We don't skip body for this type, we Read the content skipBody = false; long id = reader.ReadInt64(); int strLen = reader.ReadInt32(); StringBuilder str = new StringBuilder(strLen); for (int i = 0; i < strLen; ++i) { str.Append(reader.ReadChar()); } var resourceName = str.ToString(); checkpointResList.Add(resourceName); } if (skipBody) reader.BaseStream.Seek(size, SeekOrigin.Current); } } }
public void Open(long journalNumber) { if (IsOpen) throw new IOException(String.Format("Journal file '{0}' is already open.", FilePath)); if (FileSystem.FileExists(FilePath)) throw new IOException(String.Format("Journal file '{0}' already exists.", FilePath)); JournalNumber = journalNumber; File = new StreamFile(FileSystem, FilePath, ReadOnly); #if PCL dataOut = new BinaryWriter(File.FileStream, Encoding.Unicode); #else dataOut = new BinaryWriter(new BufferedStream(File.FileStream), Encoding.Unicode); #endif dataOut.Write(journalNumber); IsOpen = true; }
internal JournalSummary OpenForRecovery() { if (IsOpen) { throw new IOException(String.Format("Journal file '{0}' is already open.", FilePath)); } if (!FileSystem.FileExists(FilePath)) { throw new IOException(String.Format("Journal file '{0}' does not exists.", FilePath)); } // Open the random access file to this journal File = new StreamFile(FileSystem, FilePath, ReadOnly); IsOpen = true; // Create the summary object (by default, not recoverable). var summary = new JournalSummary(this); long endPointer = File.Length; // If end_pointer < 8 then can't recover this journal if (endPointer < 8) { return(summary); } // The input stream. using (var reader = new BinaryReader(File.FileStream, Encoding.Unicode)) { // Set the journal number for this JournalNumber = reader.ReadInt64(); long position = 8; var checkpointResList = new List <string>(); // Start scan while (true) { // If we can't Read 12 bytes ahead, return the summary if (position + 12 > endPointer) { return(summary); } long type = reader.ReadInt64(); int size = reader.ReadInt32(); position = position + size + 12; bool skipBody = true; // If checkpoint reached then we are recoverable if (type == 100) { summary.LastCheckPoint = position; summary.CanBeRecovered = true; // Add the resources input this check point foreach (var checkpoint in checkpointResList) { summary.Resources.Add(checkpoint); } // And clear the temporary list. checkpointResList.Clear(); } // If end reached, or type is not understood then return else if (position >= endPointer || type < 1 || type > 7) { return(summary); } // If we are resource type, then load the resource if (type == 2) { // We don't skip body for this type, we Read the content skipBody = false; long id = reader.ReadInt64(); int strLen = reader.ReadInt32(); StringBuilder str = new StringBuilder(strLen); for (int i = 0; i < strLen; ++i) { str.Append(reader.ReadChar()); } var resourceName = str.ToString(); checkpointResList.Add(resourceName); } if (skipBody) { reader.BaseStream.Seek(size, SeekOrigin.Current); } } } }