public static GetHistorianData ( |
||
connection | openHistorian connection. | |
startTime | System.DateTime | Start time of query. |
stopTime | System.DateTime | Stop time of query. |
measurementIDs | IEnumerable |
Array of measurement IDs to query - or |
resolution | Resolution | Resolution for data query. |
return | IEnumerable |
// Kick start read process for historian private void StartDataReader(object state) { MeasurementKey[] requestedKeys = SupportsTemporalProcessing ? RequestedOutputMeasurementKeys : OutputMeasurements.MeasurementKeys().ToArray(); if (Enabled && (object)m_archiveReader != null && (object)requestedKeys != null && requestedKeys.Length > 0) { m_historianIDs = requestedKeys.Select(key => unchecked ((int)key.ID)).ToArray(); m_publicationTime = 0; // Start data read from historian lock (m_readTimer) { m_startTime = base.StartTimeConstraint <DateTime.MinValue?DateTime.MinValue : base.StartTimeConstraint> DateTime.MaxValue ? DateTime.MaxValue : base.StartTimeConstraint; m_stopTime = base.StopTimeConstraint <DateTime.MinValue?DateTime.MinValue : base.StopTimeConstraint> DateTime.MaxValue ? DateTime.MaxValue : base.StopTimeConstraint; m_currentTimeOffset = 0; m_dataReader = MeasurementAPI.GetHistorianData(m_archiveReader, m_startTime, m_stopTime, m_historianIDs.ToDelimitedString(',')).GetEnumerator(); m_readTimer.Enabled = m_dataReader.MoveNext(); if (m_readTimer.Enabled) { OnStatusMessage(MessageLevel.Info, "Starting historical data read..."); } else { OnStatusMessage(MessageLevel.Warning, "No historical data was available to read for given time-frame."); OnProcessingComplete(); } } } else { m_readTimer.Enabled = false; OnStatusMessage(MessageLevel.Warning, "No measurement keys have been requested for reading, historian reader is idle."); OnProcessingComplete(); } }
// Process next data read private void m_readTimer_Elapsed(object sender, ElapsedEventArgs e) { List <IMeasurement> measurements = new List <IMeasurement>(); if (Monitor.TryEnter(m_readTimer)) { try { IMeasurement currentPoint = m_dataReader.Current; long timestamp = currentPoint.Timestamp; if (m_publicationTime == 0) { m_publicationTime = timestamp; } // Set next reasonable publication time while (m_publicationTime < timestamp) { m_publicationTime += m_publicationInterval; } do { // Add current measurement to the collection for publication measurements.Add(currentPoint); // Attempt to move to next record if (m_dataReader.MoveNext()) { // Read record value currentPoint = m_dataReader.Current; timestamp = currentPoint.Timestamp; } else { if (timestamp < m_stopTime.Ticks && m_startTime.Ticks < timestamp) { // Could be attempting read with a future end time - in these cases attempt to re-read current data // from now to end time in case any new data as been archived in the mean-time m_startTime = new DateTime(timestamp + Ticks.PerMillisecond); m_dataReader = MeasurementAPI.GetHistorianData(m_archiveReader, m_startTime, m_stopTime, m_historianIDs.ToDelimitedString(',')).GetEnumerator(); if (!m_dataReader.MoveNext()) { // Finished reading all available data m_readTimer.Enabled = false; if (m_autoRepeat) { ThreadPool.QueueUserWorkItem(StartDataReader); } else { OnProcessingComplete(); } } } else { // Finished reading all available data m_readTimer.Enabled = false; if (m_autoRepeat) { ThreadPool.QueueUserWorkItem(StartDataReader); } else { OnProcessingComplete(); } } break; } }while (timestamp <= m_publicationTime); } catch (InvalidOperationException) { // Pooled timer thread executed after last read, verify timer has stopped m_readTimer.Enabled = false; } finally { Monitor.Exit(m_readTimer); } } // Publish all measurements for this time interval if (measurements.Count > 0) { OnNewMeasurements(measurements); } }