Exemple #1
0
        /// <summary>
        /// Resets the parser to the beginning of the PQDIF file.
        /// </summary>
        public void Reset()
        {
            m_currentDataSourceRecord      = null;
            m_currentMonitorSettingsRecord = null;
            m_nextObservationRecord        = null;

            m_physicalParser.Reset();
            m_physicalParser.NextRecord(); // skip container record
        }
Exemple #2
0
        /// <summary>
        /// Writes the given observation record, as well as its data source
        /// and monitor settings records if necessary, to the file stream.
        /// </summary>
        /// <param name="observationRecord">The observation record to be written to the PQDIF file.</param>
        /// <param name="lastRecord">Indicates whether this observation record is the last record in the file.</param>
        public void Write(ObservationRecord observationRecord, bool lastRecord = false)
        {
            if ((object)observationRecord == null)
            {
                throw new ArgumentNullException("observationRecord");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((object)m_containerRecord == null)
            {
                throw new InvalidOperationException("Container record must be the first record in a PQDIF file.");
            }

            if ((object)observationRecord.DataSource == null)
            {
                throw new InvalidOperationException("An observation record must have a data source.");
            }

            if (!ReferenceEquals(m_currentDataSource, observationRecord.DataSource))
            {
                ValidateDataSourceRecord(observationRecord.DataSource);
            }

            if ((object)observationRecord.Settings != null && !ReferenceEquals(m_currentMonitorSettings, observationRecord.Settings))
            {
                ValidateMonitorSettingsRecord(observationRecord.Settings);
            }

            ValidateObservationRecord(observationRecord);

            if (!ReferenceEquals(m_currentDataSource, observationRecord.DataSource))
            {
                m_currentMonitorSettings = null;
                m_currentDataSource      = observationRecord.DataSource;
                m_physicalWriter.WriteRecord(observationRecord.DataSource.PhysicalRecord);
            }

            if ((object)observationRecord.Settings != null && !ReferenceEquals(m_currentMonitorSettings, observationRecord.Settings))
            {
                m_currentMonitorSettings = observationRecord.Settings;
                m_physicalWriter.WriteRecord(observationRecord.Settings.PhysicalRecord);
            }

            m_physicalWriter.WriteRecord(observationRecord.PhysicalRecord, lastRecord);
        }
Exemple #3
0
        /// <summary>
        /// Determines whether there are any more
        /// <see cref="ObservationRecord"/>s to be
        /// read from the PQDIF file.
        /// </summary>
        /// <returns>true if there is another observation record to be read from PQDIF file; false otherwise</returns>
        public bool HasNextObservationRecord()
        {
            Record     physicalRecord;
            RecordType recordType;

            // Read records from the file until we encounter an observation record or end of file
            while ((object)m_nextObservationRecord == null && m_physicalParser.HasNextRecord())
            {
                physicalRecord = m_physicalParser.NextRecord();
                recordType     = physicalRecord.Header.TypeOfRecord;

                switch (recordType)
                {
                case RecordType.DataSource:
                    // Keep track of the latest data source record in order to associate it with observation records
                    m_currentDataSourceRecord = DataSourceRecord.CreateDataSourceRecord(physicalRecord);
                    m_allDataSourceRecords.Add(m_currentDataSourceRecord);
                    break;

                case RecordType.MonitorSettings:
                    // Keep track of the latest monitor settings record in order to associate it with observation records
                    m_currentMonitorSettingsRecord = MonitorSettingsRecord.CreateMonitorSettingsRecord(physicalRecord);
                    break;

                case RecordType.Observation:
                    // Found an observation record!
                    m_nextObservationRecord = ObservationRecord.CreateObservationRecord(physicalRecord, m_currentDataSourceRecord, m_currentMonitorSettingsRecord);
                    break;

                case RecordType.Container:
                    // The container record is parsed when the file is opened; it should never be encountered here
                    throw new InvalidOperationException("Found more than one container record in PQDIF file.");

                default:
                    // Ignore unrecognized record types as the rest of the file might be valid.
                    //throw new ArgumentOutOfRangeException(string.Format("Unknown record type: {0}", physicalRecord.Header.RecordTypeTag));
                    break;
                }
            }

            return((object)m_nextObservationRecord != null);
        }
Exemple #4
0
        private void ValidateMonitorSettingsRecord(MonitorSettingsRecord monitorSettingsRecord)
        {
            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.EffectiveTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "EffectiveTag", MonitorSettingsRecord.EffectiveTag));
            }

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.TimeInstalledTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "TimeInstalledTag", MonitorSettingsRecord.TimeInstalledTag));
            }

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.UseCalibrationTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "UseCalibrationTag", MonitorSettingsRecord.UseCalibrationTag));
            }

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.UseTransducerTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "UseTransducerTag", MonitorSettingsRecord.UseTransducerTag));
            }

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.ChannelSettingsArrayTag).Any())
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "ChannelSettingsArrayTag", MonitorSettingsRecord.ChannelSettingsArrayTag));
            }

            if (monitorSettingsRecord.ChannelSettings.Count == 0)
            {
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "OneChannelSettingTag", MonitorSettingsRecord.OneChannelSettingTag));
            }

            foreach (ChannelSetting channelSetting in monitorSettingsRecord.ChannelSettings)
            {
                if (!channelSetting.PhysicalStructure.GetElementsByTag(ChannelDefinition.ChannelDefinitionIndexTag).Any())
                {
                    m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "ChannelDefinitionIndexTag", ChannelDefinition.ChannelDefinitionIndexTag));
                }
            }
        }
Exemple #5
0
        // Static Methods

        /// <summary>
        /// Creates a new monitor settings record from scratch.
        /// </summary>
        /// <returns>The new monitor settings record.</returns>
        public static MonitorSettingsRecord CreateMonitorSettingsRecord()
        {
            Guid   recordTypeTag  = Record.GetTypeAsTag(RecordType.MonitorSettings);
            Record physicalRecord = new Record(recordTypeTag);
            MonitorSettingsRecord monitorSettingsRecord = new MonitorSettingsRecord(physicalRecord);

            DateTime now = DateTime.UtcNow;

            monitorSettingsRecord.Effective      = now;
            monitorSettingsRecord.TimeInstalled  = now;
            monitorSettingsRecord.UseCalibration = false;
            monitorSettingsRecord.UseTransducer  = false;

            CollectionElement bodyElement = physicalRecord.Body.Collection;

            bodyElement.AddElement(new CollectionElement()
            {
                TagOfElement = ChannelSettingsArrayTag
            });

            return(monitorSettingsRecord);
        }
Exemple #6
0
 /// <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;
 }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
        // Static Methods

        /// <summary>
        /// Creates a new observation record from scratch with the given data source and settings.
        /// </summary>
        /// <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.</returns>
        public static ObservationRecord CreateObservationRecord(DataSourceRecord dataSource, MonitorSettingsRecord settings)
        {
            Guid              recordTypeTag     = Record.GetTypeAsTag(RecordType.Observation);
            Record            physicalRecord    = new Record(recordTypeTag);
            ObservationRecord observationRecord = new ObservationRecord(physicalRecord, dataSource, settings);

            DateTime now = DateTime.UtcNow;

            observationRecord.Name          = now.ToString();
            observationRecord.CreateTime    = now;
            observationRecord.StartTime     = now;
            observationRecord.TriggerMethod = TriggerMethod.None;

            CollectionElement bodyElement = physicalRecord.Body.Collection;

            bodyElement.AddElement(new CollectionElement()
            {
                TagOfElement = ChannelInstancesTag
            });

            return(observationRecord);
        }
Exemple #9
0
 /// <summary>
 /// Creates a new instance of the <see cref="ChannelSetting"/> class.
 /// </summary>
 /// <param name="physicalStructure">The collection element which is the physical structure of the channel setting.</param>
 /// <param name="monitorSettingsRecord">The monitor settings record in which the channel setting resides.</param>
 public ChannelSetting(CollectionElement physicalStructure, MonitorSettingsRecord monitorSettingsRecord)
 {
     m_physicalStructure     = physicalStructure;
     m_monitorSettingsRecord = monitorSettingsRecord;
 }
Exemple #10
0
        /// <summary>
        /// Determines whether there are any more
        /// <see cref="ObservationRecord"/>s to be
        /// read from the PQDIF file.
        /// </summary>
        /// <returns>true if there is another observation record to be read from PQDIF file; false otherwise</returns>
        public bool HasNextObservationRecord()
        {
            Record physicalRecord;
            RecordType recordType;

            // Read records from the file until we encounter an observation record or end of file
            while ((object)m_nextObservationRecord == null && m_physicalParser.HasNextRecord())
            {
                physicalRecord = m_physicalParser.NextRecord();
                recordType = physicalRecord.Header.TypeOfRecord;

                switch (recordType)
                {
                    case RecordType.DataSource:
                        // Keep track of the latest data source record in order to associate it with observation records
                        m_currentDataSourceRecord = DataSourceRecord.CreateDataSourceRecord(physicalRecord);
                        break;

                    case RecordType.MonitorSettings:
                        // Keep track of the latest monitor settings record in order to associate it with observation records
                        m_currentMonitorSettingsRecord = MonitorSettingsRecord.CreateMonitorSettingsRecord(physicalRecord);
                        break;

                    case RecordType.Observation:
                        // Found an observation record!
                        m_nextObservationRecord = ObservationRecord.CreateObservationRecord(physicalRecord, m_currentDataSourceRecord, m_currentMonitorSettingsRecord);
                        break;

                    case RecordType.Container:
                        // The container record is parsed when the file is opened; it should never be encountered here
                        throw new InvalidOperationException("Found more than one container record in PQDIF file.");

                    default:
                        // Ignore unrecognized record types as the rest of the file might be valid.
                        //throw new ArgumentOutOfRangeException(string.Format("Unknown record type: {0}", physicalRecord.Header.RecordTypeTag));
                        break;
                }
            }

            return (object)m_nextObservationRecord != null;
        }
Exemple #11
0
        /// <summary>
        /// Resets the parser to the beginning of the PQDIF file.
        /// </summary>
        public void Reset()
        {
            m_currentDataSourceRecord = null;
            m_currentMonitorSettingsRecord = null;
            m_nextObservationRecord = null;

            m_physicalParser.Reset();
            m_physicalParser.NextRecord(); // skip container record
        }
Exemple #12
0
        private void ValidateMonitorSettingsRecord(MonitorSettingsRecord monitorSettingsRecord)
        {
            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.EffectiveTag).Any())
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "EffectiveTag", MonitorSettingsRecord.EffectiveTag));

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.TimeInstalledTag).Any())
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "TimeInstalledTag", MonitorSettingsRecord.TimeInstalledTag));

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.UseCalibrationTag).Any())
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "UseCalibrationTag", MonitorSettingsRecord.UseCalibrationTag));

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.UseTransducerTag).Any())
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "UseTransducerTag", MonitorSettingsRecord.UseTransducerTag));

            if (!monitorSettingsRecord.PhysicalRecord.Body.Collection.GetElementsByTag(MonitorSettingsRecord.ChannelSettingsArrayTag).Any())
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "ChannelSettingsArrayTag", MonitorSettingsRecord.ChannelSettingsArrayTag));

            if (monitorSettingsRecord.ChannelSettings.Count == 0)
                m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "OneChannelSettingTag", MonitorSettingsRecord.OneChannelSettingTag));

            foreach (ChannelSetting channelSetting in monitorSettingsRecord.ChannelSettings)
            {
                if (!channelSetting.PhysicalStructure.GetElementsByTag(ChannelDefinition.ChannelDefinitionIndexTag).Any())
                    m_missingTags.Add(new MissingTag(RecordType.MonitorSettings, "ChannelDefinitionIndexTag", ChannelDefinition.ChannelDefinitionIndexTag));
            }
        }
Exemple #13
0
        /// <summary>
        /// Writes the given observation record, as well as its data source
        /// and monitor settings records if necessary, to the file stream.
        /// </summary>
        /// <param name="observationRecord">The observation record to be written to the PQDIF file.</param>
        /// <param name="lastRecord">Indicates whether this observation record is the last record in the file.</param>
        public void Write(ObservationRecord observationRecord, bool lastRecord = false)
        {
            if ((object)observationRecord == null)
                throw new ArgumentNullException("observationRecord");

            if (m_disposed)
                throw new ObjectDisposedException(GetType().Name);

            if ((object)m_containerRecord == null)
                throw new InvalidOperationException("Container record must be the first record in a PQDIF file.");

            if ((object)observationRecord.DataSource == null)
                throw new InvalidOperationException("An observation record must have a data source.");

            if (!ReferenceEquals(m_currentDataSource, observationRecord.DataSource))
                ValidateDataSourceRecord(observationRecord.DataSource);

            if ((object)observationRecord.Settings != null && !ReferenceEquals(m_currentMonitorSettings, observationRecord.Settings))
                ValidateMonitorSettingsRecord(observationRecord.Settings);

            ValidateObservationRecord(observationRecord);

            if (!ReferenceEquals(m_currentDataSource, observationRecord.DataSource))
            {
                m_currentMonitorSettings = null;
                m_currentDataSource = observationRecord.DataSource;
                m_physicalWriter.WriteRecord(observationRecord.DataSource.PhysicalRecord);
            }

            if ((object)observationRecord.Settings != null && !ReferenceEquals(m_currentMonitorSettings, observationRecord.Settings))
            {
                m_currentMonitorSettings = observationRecord.Settings;
                m_physicalWriter.WriteRecord(observationRecord.Settings.PhysicalRecord);
            }

            m_physicalWriter.WriteRecord(observationRecord.PhysicalRecord, lastRecord);
        }
Exemple #14
0
 /// <summary>
 /// Creates a new instance of the <see cref="ChannelSetting"/> class.
 /// </summary>
 /// <param name="physicalStructure">The collection element which is the physical structure of the channel setting.</param>
 /// <param name="monitorSettingsRecord">The monitor settings record in which the channel setting resides.</param>
 public ChannelSetting(CollectionElement physicalStructure, MonitorSettingsRecord monitorSettingsRecord)
 {
     m_physicalStructure = physicalStructure;
     m_monitorSettingsRecord = monitorSettingsRecord;
 }
Exemple #15
0
 /// <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;
 }
Exemple #16
0
        // 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;
        }