public void UpdateTagTest() { TagConfigDatabase db = TagConfigDatabase.Instance; db.Load(_tagRecords); TagStateManager tsm = new TagStateManager(db); Dictionary <string, object> fields = new Dictionary <string, object> { { "Quality", "1" } }; tsm.UpdateTag <double>("AirConditioner1.Temperature", DateTime.UtcNow, 77.5D, fields); tsm.UpdateTag <double>("AirConditioner1.Temperature", DateTime.UtcNow, 79.4D, fields); var tag = tsm.GetTag("AirConditioner1.Temperature"); DataPoint <double> dp = (DataPoint <double>)tag.DataPoints["AirConditioner1.Temperature"]; Assert.AreEqual(79.4D, dp.Val); }
public void Subscription_DataChanged(Subscription subscription, DataChangedEventArgs e) { foreach (DataChange change in e.DataChanges) { string timeStamp = ((change.Value.SourceTimestamp != DateTime.MinValue) ? change.Value.SourceTimestamp : change.Value.ServerTimestamp).ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss.fff"); string typeInfo = change.Value.WrappedValue.TypeInfo.ToString(); string wrappedValue = change.Value.WrappedValue.ToString(); //string tagName = change.MonitoredItem.NodeId.Identifier.ToString(); string tagName = change.MonitoredItem.NodeId.ToString(); WriteLog(string.Format("{{tagName: \"{0}\", timeStamp: \"{1}\", typeInfo: \"{2}\", wrappedValue: {3}}}", tagName, timeStamp, typeInfo, wrappedValue)); //write the changed state to the state manager. OpcTag opcGeneratedTag = new OpcTag() { Id = tagName, TagType = typeInfo, TagQuality = "0", TagValue = wrappedValue, Timestamp = DateTime.Parse(timeStamp) }; Tag tag = _opcTagConverter.Convert(opcGeneratedTag); _tagStateManager.UpdateTag <string>(tag.Name, tag.GetTimestamp(), wrappedValue, tag.Other); } }