Exemplo n.º 1
0
        /// <summary>
        /// Queues a new data change.
        /// </summary>
        public void QueueValue(DataValue value, ServiceResult error)
        {
            lock (_lock) {
                // check if value has changed.
                if (!AlwaysReportUpdates)
                {
                    if (!MonitoredItem.ValueChanged(value, error, _lastValue, _lastError, DataChangeFilter, _range))
                    {
                        return;
                    }
                }

                // make a shallow copy of the value.
                if (value != null)
                {
                    var copy = new DataValue {
                        WrappedValue      = value.WrappedValue,
                        StatusCode        = value.StatusCode,
                        SourceTimestamp   = value.SourceTimestamp,
                        SourcePicoseconds = value.SourcePicoseconds,
                        ServerTimestamp   = value.ServerTimestamp,
                        ServerPicoseconds = value.ServerPicoseconds
                    };

                    value = copy;

                    // ensure the data value matches the error status code.
                    if (error != null && error.StatusCode.Code != 0)
                    {
                        value.StatusCode = error.StatusCode;
                    }
                }

                _lastValue = value;
                _lastError = error;

                // queue value.
                if (_queue != null)
                {
                    _queue.QueueValue(value, error);
                }

                // flag the item as ready to publish.
                _readyToPublish = true;
                _readyToTrigger = true;
            }
        }