/// <summary> /// Creates a new instance of the <see cref="ContainerRecord"/> class. /// </summary> /// <param name="physicalRecord">The physical structure of the container record.</param> private ContainerRecord(Record physicalRecord) { m_physicalRecord = physicalRecord; }
/// <summary> /// Writes the given record to the PQDIF file. /// </summary> /// <param name="record">The record to be written to the file.</param> /// <param name="lastRecord">Indicates whether this record is the last record in the file.</param> public void WriteRecord(Record record, bool lastRecord = false) { byte[] bodyImage; if (m_disposed) throw new ObjectDisposedException(GetType().Name); using (BlockAllocatedMemoryStream bodyStream = new BlockAllocatedMemoryStream()) using (BinaryWriter bodyWriter = new BinaryWriter(bodyStream)) { // Write the record body to the memory stream WriteCollection(bodyWriter, record.Body.Collection); // Read and compress the body to a byte array bodyImage = bodyStream.ToArray(); if (m_compressionAlgorithm == CompressionAlgorithm.Zlib && m_compressionStyle == CompressionStyle.RecordLevel) bodyImage = ZlibStream.CompressBuffer(bodyImage); } // Fix the pointer to the next // record before writing this record if (m_stream.CanSeek && m_stream.Length > 0) { m_writer.Write((int)m_stream.Length); m_stream.Seek(0L, SeekOrigin.End); } // Make sure the header points to the correct location based on the size of the body record.Header.HeaderSize = 64; record.Header.BodySize = bodyImage.Length; record.Header.NextRecordPosition = (int)m_stream.Length + record.Header.HeaderSize + record.Header.BodySize; // Write up to the next record position m_writer.Write(record.Header.RecordSignature.ToByteArray()); m_writer.Write(record.Header.RecordTypeTag.ToByteArray()); m_writer.Write(record.Header.HeaderSize); m_writer.Write(record.Header.BodySize); // The PQDIF standard defines the NextRecordPosition to be 0 for the last record in the file // We treat seekable streams differently because we can go back and fix the pointers later if (m_stream.CanSeek || lastRecord) m_writer.Write(0); else m_writer.Write(record.Header.NextRecordPosition); // Write the rest of the header as well as the body m_writer.Write(record.Header.Checksum); m_writer.Write(record.Header.Reserved); m_writer.Write(bodyImage); // If the stream is seekable, seek to the next record // position so we can fix the pointer if we end up // writing another record to the file if (m_stream.CanSeek) m_stream.Seek(-(24 + record.Header.BodySize), SeekOrigin.Current); // Dispose of the writer if this is the last record if (!m_stream.CanSeek && lastRecord) Dispose(); }
/// <summary> /// Creates a new instance of the <see cref="MonitorSettingsRecord"/> class. /// </summary> /// <param name="physicalRecord">The physical structure of the monitor settings record.</param> private MonitorSettingsRecord(Record physicalRecord) { m_physicalRecord = physicalRecord; }
// Static Methods /// <summary> /// Creates a new container record from the given physical record /// if the physical record is of type container. Returns null if /// it is not. /// </summary> /// <param name="physicalRecord">The physical record used to create the container record.</param> /// <returns>The new container record, or null if the physical record does not define a container record.</returns> public static ContainerRecord CreateContainerRecord(Record physicalRecord) { bool isValidPhysicalRecord = physicalRecord.Header.TypeOfRecord == RecordType.Container; return (isValidPhysicalRecord) ? new ContainerRecord(physicalRecord) : null; }
// Static Methods /// <summary> /// Creates a new monitor settings record from the given physical record /// if the physical record is of type monitor settings. Returns null if /// it is not. /// </summary> /// <param name="physicalRecord">The physical record used to create the monitor settings record.</param> /// <returns>The new monitor settings record, or null if the physical record does not define a monitor settings record.</returns> public static MonitorSettingsRecord CreateMonitorSettingsRecord(Record physicalRecord) { bool isValidMonitorSettingsRecord = physicalRecord.Header.TypeOfRecord == RecordType.MonitorSettings; return isValidMonitorSettingsRecord ? new MonitorSettingsRecord(physicalRecord) : null; }
/// <summary> /// Creates a new instance of the <see cref="DataSourceRecord"/> class. /// </summary> /// <param name="physicalRecord">The physical structure of the data source record.</param> private DataSourceRecord(Record physicalRecord) { m_physicalRecord = physicalRecord; }
// Static Methods /// <summary> /// Creates a new data source record from the given physical record /// if the physical record is of type data source. Returns null if /// it is not. /// </summary> /// <param name="physicalRecord">The physical record used to create the data source record.</param> /// <returns>The new data source record, or null if the physical record does not define a data source record.</returns> public static DataSourceRecord CreateDataSourceRecord(Record physicalRecord) { bool isValidDataSourceRecord = physicalRecord.Header.TypeOfRecord == RecordType.DataSource; return isValidDataSourceRecord ? new DataSourceRecord(physicalRecord) : null; }
/// <summary> /// Creates a new instance of the <see cref="ObservationRecord"/> class. /// </summary> /// <param name="physicalRecord">The physical structure of the observation record.</param> /// <param name="dataSource">The data source record that defines the channels in this observation record.</param> /// <param name="settings">The monitor settings to be applied to this observation record.</param> private ObservationRecord(Record physicalRecord, DataSourceRecord dataSource, MonitorSettingsRecord settings) { m_physicalRecord = physicalRecord; m_dataSource = dataSource; m_settings = settings; }
// Static Methods /// <summary> /// Creates a new observation record from the given physical record /// if the physical record is of type observation. Returns null if /// it is not. /// </summary> /// <param name="physicalRecord">The physical record used to create the observation record.</param> /// <param name="dataSource">The data source record that defines the channels in this observation record.</param> /// <param name="settings">The monitor settings to be applied to this observation record.</param> /// <returns>The new observation record, or null if the physical record does not define a observation record.</returns> public static ObservationRecord CreateObservationRecord(Record physicalRecord, DataSourceRecord dataSource, MonitorSettingsRecord settings) { bool isValidObservationRecord = physicalRecord.Header.TypeOfRecord == RecordType.Observation; return isValidObservationRecord ? new ObservationRecord(physicalRecord, dataSource, settings) : null; }