public OpcStatusCollection DeleteHistory(
            OpcContext context,
            OpcHistoryModificationInfo modificationInfo,
            OpcValueCollection values)
        {
            var results = OpcStatusCollection.Create(OpcStatusCode.Good, values.Count);

            lock (this.syncRoot) {
                for (int index = 0; index < values.Count; index++)
                {
                    var timestamp = OpcHistoryValue.Create(values[index]).Timestamp;
                    var result    = results[index];

                    if (this.History.Contains(timestamp))
                    {
                        var value = this.History[timestamp];
                        this.History.RemoveAt(timestamp);

                        var modifiedValue = value.CreateModified(modificationInfo);
                        this.ModifiedHistory.Add(modifiedValue);
                    }
                    else
                    {
                        result.Update(OpcStatusCode.BadNoEntryExists);
                    }
                }
            }

            return(results);
        }
        public OpcStatusCollection UpdateHistory(
            OpcContext context,
            OpcHistoryModificationInfo modificationInfo,
            OpcValueCollection values)
        {
            var results = OpcStatusCollection.Create(OpcStatusCode.Good, values.Count);

            lock (this.syncRoot) {
                var expectedDataTypeId = this.Node.DataTypeId;

                for (int index = 0; index < values.Count; index++)
                {
                    var result = results[index];
                    var value  = OpcHistoryValue.Create(values[index]);

                    if (value.DataTypeId == expectedDataTypeId)
                    {
                        if (this.History.Contains(value.Timestamp))
                        {
                            var oldValue = this.History[value.Timestamp];
                            this.History.Replace(value);

                            var modifiedValue = oldValue.CreateModified(modificationInfo);
                            this.ModifiedHistory.Add(modifiedValue);

                            result.Update(OpcStatusCode.GoodEntryReplaced);
                        }
                        else
                        {
                            this.History.Add(value);

                            var modifiedValue = value.CreateModified(modificationInfo);
                            this.ModifiedHistory.Add(modifiedValue);

                            result.Update(OpcStatusCode.GoodEntryInserted);
                        }
                    }
                    else
                    {
                        result.Update(OpcStatusCode.BadTypeMismatch);
                    }
                }
            }

            return(results);
        }
        private void HandleNodeBeforeApplyChanges(object sender, OpcNodeChangesEventArgs e)
        {
            var timestamp = this.Node.Timestamp;

            if (timestamp != null && e.IsChangeOf(OpcNodeChanges.Value))
            {
                var value = new OpcHistoryValue(this.Node.Value, timestamp.Value);

                if (this.History.Contains(value.Timestamp))
                {
                    this.History.Replace(value);
                }
                else
                {
                    this.History.Add(value);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the different entries contained in the raw history and modified raw history
        /// of the node historian used.
        /// </summary>
        /// <param name="historian">The <see cref="OpcNodeHistorian"/> its history
        /// entries being created.</param>
        private static void CreateHistoryEntries(OpcNodeHistorian historian)
        {
            for (int second = 0; second < 3600; second++)
            {
                var value = new OpcHistoryValue(
                    1000 + second, DateTime.UtcNow.Date.AddHours(6).AddSeconds(second));

                if ((second % 30) == 0)
                {
                    historian.ModifiedHistory.Add(value.CreateModified(
                                                      OpcHistoryModificationType.Delete, "Anonymous", value.Timestamp));
                }
                else
                {
                    historian.History.Add(value);
                }
            }
        }
Exemplo n.º 5
0
        private static void CreateHistoryEntries <T>(
            SampleHistorian historian,
            Func <int, T> nextValue)
        {
            for (int second = 0; second < 60; second++)
            {
                var timestamp = DateTime.UtcNow.Date.AddHours(6).AddSeconds(second);

                var modifier = Math.Max(10, second) / 10;
                var value    = new OpcHistoryValue(nextValue(modifier), timestamp);

                if ((second % 30) == 0)
                {
                    historian.ModifiedHistory.Add(value.CreateModified(
                                                      OpcHistoryModificationType.Delete, "Anonymous", value.Timestamp));
                }
                else
                {
                    historian.History.Add(value);
                }
            }
        }