/// <summary> /// Writes the contents of the sector container objects to the sector information file. /// </summary> /// <exception cref="SectorContainerWriteException">Error encountered writing sector container</exception> internal void Write() { try { using ( BinaryWriter binaryWriter = FileHelper.GetBinaryWriter(Chassis.FullWritePath, TmlSectorInfoFile, Path.Combine(Chassis.FullWritePath, TmlSectorInfoBackupFile), Encoding.GetEncoding( Constants.FileEncodingCodePageNumber))) { InformationHeader.SectorCount = Count; InformationHeader.Write(binaryWriter); // Calculate length of Sector Information collection int sectorInformationCollectionSize = this.Sum(sectorInformation => sectorInformation.FileRecordSize()); long sectorInformationPositionItemsCurrentIndex = binaryWriter.BaseStream.Position + sectorInformationCollectionSize; // Iterate through the sector information collection and set the notes length and offset values foreach (SectorInformation sectorInformation in this) { int notesLength = sectorInformation.Notes.Length; sectorInformation.SectorDescription.NotesOffset = (int)sectorInformationPositionItemsCurrentIndex; sectorInformation.SectorDescription.NotesLength = notesLength; sectorInformationPositionItemsCurrentIndex += notesLength; } foreach (SectorInformation sectorInformation in this) { sectorInformation.Write(binaryWriter); } } DumpSectorData(RiskBasedFilename(TmsSectorDumpWriteFilename), RiskBasedFilename(TmsSectorDumpWriteBackupFilename)); } catch (Exception eek) { const string message = "Error encountered writing sector container"; Chassis.Logger.ErrorException(message, eek); throw new SectorContainerWriteException(message, eek); } try { DumpSectorData(RiskBasedFilename(TmsSectorDumpWriteFilename), RiskBasedFilename(TmsSectorDumpWriteBackupFilename)); } catch (Exception eek) { Chassis.Logger.ErrorException("Error encountered dumping sector data", eek); } }
/// <summary> /// Populates properties on the current object reading information from the /// provided binary reader. /// </summary> internal void Read() { using ( BinaryReader binaryReader = FileHelper.GetBinaryReader(Chassis.FullReadPath, TmlSectorInfoFile, Encoding.GetEncoding( Constants.FileEncodingCodePageNumber)) ) { InformationHeader.Read(binaryReader); for (int sectorIndex = 0; sectorIndex < InformationHeader.SectorCount; sectorIndex++) { var sectorInformation = new SectorInformation(); sectorInformation.Read(binaryReader); Add(sectorInformation); } DumpSectorData(RiskBasedFilename(TmsSectorDumpReadFilename), RiskBasedFilename(TmsSectorDumpReadBackupFilename)); } }