private void ValidateObservationRecord(ObservationRecord observationRecord) { if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.ObservationNameTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "ObservationNameTag", ObservationRecord.ObservationNameTag)); } if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TimeCreateTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "TimeCreateTag", ObservationRecord.TimeCreateTag)); } if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TimeStartTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "TimeStartTag", ObservationRecord.TimeStartTag)); } if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TriggerMethodTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "TriggerMethodTag", ObservationRecord.TriggerMethodTag)); } if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.ChannelInstancesTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "ChannelInstancesTag", ObservationRecord.ChannelInstancesTag)); } if (observationRecord.ChannelInstances.Count == 0) { m_missingTags.Add(new MissingTag(RecordType.Observation, "OneChannelInstanceTag", ObservationRecord.OneChannelInstanceTag)); } foreach (ChannelInstance channelInstance in observationRecord.ChannelInstances) { if (!channelInstance.PhysicalStructure.GetElementsByTag(ChannelDefinition.ChannelDefinitionIndexTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "ChannelDefinitionIndexTag", ChannelDefinition.ChannelDefinitionIndexTag)); } if (!channelInstance.PhysicalStructure.GetElementsByTag(ChannelInstance.SeriesInstancesTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "SeriesInstancesTag", ChannelInstance.SeriesInstancesTag)); } if (channelInstance.SeriesInstances.Count == 0) { m_missingTags.Add(new MissingTag(RecordType.Observation, "OneSeriesInstanceTag", ChannelInstance.OneSeriesInstanceTag)); } foreach (SeriesInstance seriesInstance in channelInstance.SeriesInstances) { if (!seriesInstance.PhysicalStructure.GetElementsByTag(SeriesInstance.SeriesValuesTag).Any()) { m_missingTags.Add(new MissingTag(RecordType.Observation, "SeriesValuesTag", SeriesInstance.SeriesValuesTag)); } } } }
/// <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 }
/// <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); }
/// <summary> /// Gets the next observation record from the PQDIF file. /// </summary> /// <returns>The next observation record.</returns> public ObservationRecord NextObservationRecord() { ObservationRecord nextObservationRecord; // Call this first to read ahead to the next // observation record if we haven't already HasNextObservationRecord(); // We need to set m_nextObservationRecord to null so that // subsequent calls to HasNextObservationRecord() will // continue to parse new records nextObservationRecord = m_nextObservationRecord; m_nextObservationRecord = null; return(nextObservationRecord); }
private PQio.Model.Event ParseObservationRecord(GSF.PQDIF.Logical.ObservationRecord record, AdoDataConnection connection) { Event evt = new Event(); evt.EventTime = record.StartTime; evt.Name = record.Name; evt.GUID = new Guid().ToString(); //Add Disturbance Category record in GSF GSF.Data.Model.TableOperations <Event> evtTable = new GSF.Data.Model.TableOperations <Event>(connection); evtTable.AddNewRecord(evt); evt.ID = ModelID.GetID <Event>(connection); return(evt); }
private PQds.Model.Event ParseObservationRecord(GSF.PQDIF.Logical.ObservationRecord record) { Event evt = new Event(); evt.EventTime = record.StartTime; evt.Name = record.Name; evt.GUID = new Guid().ToString(); //Add Disturbance Category record in GSF using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.Event> evtTable = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection); evtTable.AddNewRecord(evt); evt.ID = PQds.Model.ModelID.GetID <Event>(connection); } return(evt); }
/// <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); }
// 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); }
/// <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; }
/// <summary> /// Gets the next observation record from the PQDIF file. /// </summary> /// <returns>The next observation record.</returns> public ObservationRecord NextObservationRecord() { ObservationRecord nextObservationRecord; // Call this first to read ahead to the next // observation record if we haven't already HasNextObservationRecord(); // We need to set m_nextObservationRecord to null so that // subsequent calls to HasNextObservationRecord() will // continue to parse new records nextObservationRecord = m_nextObservationRecord; m_nextObservationRecord = null; return nextObservationRecord; }
/// <summary> /// Creates a new instance of the <see cref="ChannelInstance"/> class. /// </summary> /// <param name="physicalStructure">The collection element which is the physical structure of the channel instance.</param> /// <param name="observationRecord">The observation record in which the channel instance resides.</param> public ChannelInstance(CollectionElement physicalStructure, ObservationRecord observationRecord) { m_physicalStructure = physicalStructure; m_observationRecord = observationRecord; }
private void ValidateObservationRecord(ObservationRecord observationRecord) { if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.ObservationNameTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "ObservationNameTag", ObservationRecord.ObservationNameTag)); if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TimeCreateTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "TimeCreateTag", ObservationRecord.TimeCreateTag)); if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TimeStartTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "TimeStartTag", ObservationRecord.TimeStartTag)); if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.TriggerMethodTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "TriggerMethodTag", ObservationRecord.TriggerMethodTag)); if (!observationRecord.PhysicalRecord.Body.Collection.GetElementsByTag(ObservationRecord.ChannelInstancesTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "ChannelInstancesTag", ObservationRecord.ChannelInstancesTag)); if (observationRecord.ChannelInstances.Count == 0) m_missingTags.Add(new MissingTag(RecordType.Observation, "OneChannelInstanceTag", ObservationRecord.OneChannelInstanceTag)); foreach (ChannelInstance channelInstance in observationRecord.ChannelInstances) { if (!channelInstance.PhysicalStructure.GetElementsByTag(ChannelDefinition.ChannelDefinitionIndexTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "ChannelDefinitionIndexTag", ChannelDefinition.ChannelDefinitionIndexTag)); if (!channelInstance.PhysicalStructure.GetElementsByTag(ChannelInstance.SeriesInstancesTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "SeriesInstancesTag", ChannelInstance.SeriesInstancesTag)); if (channelInstance.SeriesInstances.Count == 0) m_missingTags.Add(new MissingTag(RecordType.Observation, "OneSeriesInstanceTag", ChannelInstance.OneSeriesInstanceTag)); foreach (SeriesInstance seriesInstance in channelInstance.SeriesInstances) { if (!seriesInstance.PhysicalStructure.GetElementsByTag(SeriesInstance.SeriesValuesTag).Any()) m_missingTags.Add(new MissingTag(RecordType.Observation, "SeriesValuesTag", SeriesInstance.SeriesValuesTag)); } } }
/// <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); }