示例#1
0
        /// <summary>
        /// Returns the text representation of <see cref="ArchiveDataPoint"/> object in the specified <paramref name="format"/>
        /// using the specified <paramref name="provider"/>.
        /// </summary>
        /// <param name="format">Format of text output (I for ID, T for Time, V for Value, Q for Quality).</param>
        /// <param name="provider">An <see cref="IFormatProvider"/> that supplies culture-specific formatting information.</param>
        /// <returns>A <see cref="string"/> value.</returns>
        public virtual string ToString(string format, IFormatProvider provider)
        {
            if (provider == null)
            {
                provider = CultureInfo.InvariantCulture;
            }

            switch (format.ToUpperInvariant())
            {
            case "I":
            case "ID":
                return(m_historianID.ToString(provider));

            case "T":
            case "TIME":
                return(m_time.ToString());

            case "U":
            case "UNIXTIME":
                return((new UnixTimeTag(m_time.ToDateTime())).Value.ToString("0.000", provider));

            case "V":
            case "VALUE":
                return(m_value.ToString(provider));

            case "Q":
            case "QUALITY":
                return(Quality.ToString());

            case "N":
            case "NAME":
                if (Metadata != null)
                {
                    return(Metadata.Name);
                }
                return("");

            case "D":
            case "DESCRIPTION":
                if (Metadata != null)
                {
                    return(Metadata.Description);
                }
                return("");

            case "S":
            case "SOURCE":
                if (Metadata != null)
                {
                    return(Metadata.PlantCode);
                }
                return("");

            case "S1":
            case "SYNONYM1":
                if (Metadata != null)
                {
                    return(Metadata.Synonym1);
                }
                return("");

            case "S2":
            case "SYNONYM2":
                if (Metadata != null)
                {
                    return(Metadata.Synonym2);
                }
                return("");

            case "S3":
            case "SYNONYM3":
                if (Metadata != null)
                {
                    return(Metadata.Synonym3);
                }
                return("");

            default:
                throw new FormatException("Invalid format identifier specified for ArchiveDataPoint: " + format);
            }
        }
示例#2
0
        // 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
                {
                    IDataPoint     currentPoint = m_dataReader.Current;
                    long           timestamp    = currentPoint.Time.ToDateTime().Ticks;
                    MeasurementKey key;

                    if (m_publicationTime == 0)
                    {
                        m_publicationTime = timestamp;
                    }

                    // Set next reasonable publication time
                    while (m_publicationTime < timestamp)
                    {
                        m_publicationTime += m_publicationInterval;
                    }

                    do
                    {
                        // Lookup measurement key for this point
                        key = MeasurementKey.LookUpOrCreate(m_instanceName, unchecked ((uint)currentPoint.HistorianID));

                        // Add current measurement to the collection for publication
                        measurements.Add(new Measurement
                        {
                            Metadata   = key.Metadata,
                            Timestamp  = m_simulateTimestamp ? DateTime.UtcNow.Ticks : timestamp,
                            Value      = currentPoint.Value,
                            StateFlags = currentPoint.Quality.MeasurementQuality()
                        });

                        // Attempt to move to next record
                        if (m_dataReader.MoveNext())
                        {
                            // Read record value
                            currentPoint = m_dataReader.Current;
                            timestamp    = currentPoint.Time.ToDateTime().Ticks;
                        }
                        else
                        {
                            if (timestamp < m_stopTime.ToDateTime().Ticks&& m_startTime.ToDateTime().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 TimeTag(timestamp + Ticks.PerMillisecond);
                                m_dataReader = m_archiveReader.ReadData(m_historianIDs, m_startTime, m_stopTime).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);
            }
        }