Exemple #1
0
        /// <summary>
        /// Queues a collection of measurements for processing.
        /// </summary>
        /// <param name="measurements">Collection of measurements to queue for processing.</param>
        /// <remarks>
        /// Measurements are filtered against the defined <see cref="InputMeasurementKeys"/> so we override method
        /// so that dynamic updates to keys will be synchronized with filtering to prevent interference.
        /// </remarks>
        public override void QueueMeasurementsForProcessing(IEnumerable <IMeasurement> measurements)
        {
            if (!m_startTimeSent && (object)measurements != null && measurements.Any())
            {
                m_startTimeSent = true;

                IMeasurement measurement = measurements.FirstOrDefault(m => m != null);
                Ticks        timestamp   = 0;

                if (measurement != null)
                {
                    timestamp = measurement.Timestamp;
                }

                m_parent.SendDataStartTime(m_clientID, timestamp);
            }

            if (ProcessMeasurementFilter)
            {
                lock (this)
                {
                    base.QueueMeasurementsForProcessing(measurements);
                }
            }
            else
            {
                base.QueueMeasurementsForProcessing(measurements);
            }
        }
        /// <summary>
        /// Queues a collection of measurements for processing.
        /// </summary>
        /// <param name="measurements">Collection of measurements to queue for processing.</param>
        /// <remarks>
        /// Measurements are filtered against the defined <see cref="InputMeasurementKeys"/> so we override method
        /// so that dynamic updates to keys will be synchronized with filtering to prevent interference.
        /// </remarks>
        public override void QueueMeasurementsForProcessing(IEnumerable <IMeasurement> measurements)
        {
            if ((object)measurements == null)
            {
                return;
            }

            if (!m_startTimeSent && measurements.Any())
            {
                m_startTimeSent = true;

                IMeasurement measurement = measurements.FirstOrDefault(m => m != null);
                Ticks        timestamp   = 0;

                if ((object)measurement != null)
                {
                    timestamp = measurement.Timestamp;
                }

                m_parent.SendDataStartTime(m_clientID, timestamp);
            }

            if (m_isNaNFiltered)
            {
                measurements = measurements.Where(measurement => !double.IsNaN(measurement.Value));
            }

            // Order measurements by signal type for better compression for non-TSSC compression modes
            if (m_usePayloadCompression && !m_compressionModes.HasFlag(CompressionModes.TSSC))
            {
                base.QueueMeasurementsForProcessing(measurements.OrderBy(m => m.GetSignalType(DataSource)));
            }
            else
            {
                base.QueueMeasurementsForProcessing(measurements);
            }
        }
Exemple #3
0
        /// <summary>
        /// Queues a collection of measurements for processing.
        /// </summary>
        /// <param name="measurements">Collection of measurements to queue for processing.</param>
        /// <remarks>
        /// Measurements are filtered against the defined <see cref="InputMeasurementKeys"/> so we override method
        /// so that dynamic updates to keys will be synchronized with filtering to prevent interference.
        /// </remarks>
        public override void QueueMeasurementsForProcessing(IEnumerable <IMeasurement> measurements)
        {
            if ((object)measurements == null)
            {
                return;
            }

            if (!m_startTimeSent && measurements.Any())
            {
                m_startTimeSent = true;

                IMeasurement measurement = measurements.FirstOrDefault(m => (object)m != null);
                Ticks        timestamp   = 0;

                if ((object)measurement != null)
                {
                    timestamp = measurement.Timestamp;
                }

                m_parent.SendDataStartTime(m_clientID, timestamp);
            }

            if (m_isNaNFiltered)
            {
                measurements = measurements.Where(measurement => !double.IsNaN(measurement.Value));
            }

            if (!measurements.Any() || !Enabled)
            {
                return;
            }

            if (TrackLatestMeasurements)
            {
                double publishInterval;

                // Keep track of latest measurements
                base.QueueMeasurementsForProcessing(measurements);
                publishInterval = (m_publishInterval > 0) ? m_publishInterval : LagTime;

                if (DateTime.UtcNow.Ticks > m_lastPublishTime + Ticks.FromSeconds(publishInterval))
                {
                    List <IMeasurement> currentMeasurements = new List <IMeasurement>();
                    Measurement         newMeasurement;

                    // Create a new set of measurements that represent the latest known values setting value to NaN if it is old
                    foreach (TemporalMeasurement measurement in LatestMeasurements)
                    {
                        newMeasurement = new Measurement
                        {
                            Key        = measurement.Key,
                            Value      = measurement.GetValue(RealTime),
                            Adder      = measurement.Adder,
                            Multiplier = measurement.Multiplier,
                            Timestamp  = measurement.Timestamp,
                            StateFlags = measurement.StateFlags
                        };

                        currentMeasurements.Add(newMeasurement);
                    }

                    // Order measurements by signal type for better compression when enabled
                    if (m_usePayloadCompression)
                    {
                        ProcessMeasurements(currentMeasurements.OrderBy(measurement => measurement.GetSignalType(DataSource)));
                    }
                    else
                    {
                        ProcessMeasurements(currentMeasurements);
                    }
                }
            }
            else
            {
                // Order measurements by signal type for better compression when enabled
                if (m_usePayloadCompression)
                {
                    ProcessMeasurements(measurements.OrderBy(measurement => measurement.GetSignalType(DataSource)));
                }
                else
                {
                    ProcessMeasurements(measurements);
                }
            }
        }
        /// <summary>
        /// Queues a collection of measurements for processing.
        /// </summary>
        /// <param name="measurements">Collection of measurements to queue for processing.</param>
        /// <remarks>
        /// Measurements are filtered against the defined <see cref="InputMeasurementKeys"/> so we override method
        /// so that dynamic updates to keys will be synchronized with filtering to prevent interference.
        /// </remarks>
        // IMPORTANT: TSSC is sensitive to order - always make sure this function gets called sequentially, concurrent
        // calls to this function can cause TSSC parsing to get out of sequence and fail
        public override void QueueMeasurementsForProcessing(IEnumerable <IMeasurement> measurements)
        {
            if ((object)measurements == null)
            {
                return;
            }

            if (!m_startTimeSent && measurements.Any())
            {
                m_startTimeSent = true;

                IMeasurement measurement = measurements.FirstOrDefault(m => (object)m != null);
                Ticks        timestamp   = 0;

                if ((object)measurement != null)
                {
                    timestamp = measurement.Timestamp;
                }

                m_parent.SendDataStartTime(m_clientID, timestamp);
            }

            if (m_isNaNFiltered)
            {
                measurements = measurements.Where(measurement => !double.IsNaN(measurement.Value));
            }

            if (!measurements.Any() || !Enabled)
            {
                return;
            }

            if (TrackLatestMeasurements)
            {
                double publishInterval;

                // Keep track of latest measurements
                base.QueueMeasurementsForProcessing(measurements);
                publishInterval = m_publishInterval > 0 ? m_publishInterval : LagTime;

                if (DateTime.UtcNow.Ticks > m_lastPublishTime + Ticks.FromSeconds(publishInterval))
                {
                    List <IMeasurement> currentMeasurements = new List <IMeasurement>();
                    Measurement         newMeasurement;

                    // Create a new set of measurements that represent the latest known values setting value to NaN if it is old
                    foreach (TemporalMeasurement measurement in LatestMeasurements)
                    {
                        MeasurementStateFlags timeQuality = measurement.Timestamp.TimeIsValid(RealTime, measurement.LagTime, measurement.LeadTime)
                            ? MeasurementStateFlags.Normal
                            : MeasurementStateFlags.BadTime;

                        newMeasurement = new Measurement
                        {
                            Metadata   = measurement.Metadata,
                            Value      = measurement.Value,
                            Timestamp  = measurement.Timestamp,
                            StateFlags = measurement.StateFlags | timeQuality
                        };

                        currentMeasurements.Add(newMeasurement);
                    }

                    ProcessMeasurements(currentMeasurements);
                }
            }
            else
            {
                ProcessMeasurements(measurements);
            }
        }
Exemple #5
0
        /// <summary>
        /// Queues a collection of measurements for processing.
        /// </summary>
        /// <param name="measurements">Collection of measurements to queue for processing.</param>
        /// <remarks>
        /// Measurements are filtered against the defined <see cref="InputMeasurementKeys"/> so we override method
        /// so that dyanmic updates to keys will be synchronized with filtering to prevent interference.
        /// </remarks>
        public override void QueueMeasurementsForProcessing(IEnumerable <IMeasurement> measurements)
        {
            if (!m_startTimeSent && (object)measurements != null && measurements.Any())
            {
                m_startTimeSent = true;

                IMeasurement measurement = measurements.FirstOrDefault(m => m != null);
                Ticks        timestamp   = 0;

                if (measurement != null)
                {
                    timestamp = measurement.Timestamp;
                }

                m_parent.SendDataStartTime(m_clientID, timestamp);
            }

            if (ProcessMeasurementFilter)
            {
                List <IMeasurement> filteredMeasurements = new List <IMeasurement>();

                lock (this)
                {
                    foreach (IMeasurement measurement in measurements)
                    {
                        if (IsInputMeasurement(measurement.Key))
                        {
                            filteredMeasurements.Add(measurement);
                        }
                    }
                }

                measurements = filteredMeasurements;
            }

            if (measurements.Any() && Enabled)
            {
                if (TrackLatestMeasurements)
                {
                    double publishInterval;

                    // Keep track of latest measurements
                    base.QueueMeasurementsForProcessing(measurements);
                    publishInterval = (m_publishInterval > 0) ? m_publishInterval : LagTime;

                    if (DateTime.UtcNow.Ticks > m_lastPublishTime + Ticks.FromSeconds(publishInterval))
                    {
                        List <IMeasurement> currentMeasurements = new List <IMeasurement>();
                        Measurement         newMeasurement;

                        // Create a new set of measurements that represent the latest known values setting value to NaN if it is old
                        foreach (TemporalMeasurement measurement in LatestMeasurements)
                        {
                            newMeasurement = new Measurement()
                            {
                                ID         = measurement.ID,
                                Key        = measurement.Key,
                                Value      = measurement.GetValue(RealTime),
                                Adder      = measurement.Adder,
                                Multiplier = measurement.Multiplier,
                                Timestamp  = measurement.Timestamp,
                                StateFlags = measurement.StateFlags
                            };

                            currentMeasurements.Add(newMeasurement);
                        }

                        // Publish latest data values...
                        if ((object)m_processQueue != null)
                        {
                            m_processQueue.Enqueue(currentMeasurements);
                        }
                    }
                }
                else
                {
                    // Publish unsynchronized on data receipt otherwise...
                    m_processQueue.Enqueue(measurements);
                }
            }
        }