public override void Initialize(Dictionary <string, object> settings) { string pluginNamespace = GetContainerNamespace(); //load types specific to this host into TypeContainer TagConfigDatabase tagConfigDatabase = TagConfigDatabase.Instance; tagConfigDatabase.Load(ConfigUtility.ReadFile(settings.GetValueOrNull("OpcTagConfigFile") as string)); TagStateManager tagStateManager = new TagStateManager(tagConfigDatabase); settings["TagStateManager"] = tagStateManager; settings["TagConfigDatabase"] = tagConfigDatabase; //configure receiver TypeContainer tc = TypeContainer.Instance; IProcessor opcReceiver = tc.GetInstance <IReceiver>(pluginNamespace) as IProcessor; IConverter <object, Tag> opcConverter = tc.GetInstance <IConverter <object, Tag> >(pluginNamespace); settings["Logger"] = tc.GetInstance <ILogger>(); settings["OpcTagConverter"] = opcConverter; if (opcReceiver != null) { this.AddReceiver("OpcReceiver", opcReceiver); } //configure IotHub Sender: need "IotHubConfigFile", "TagStateManager", "TagToIotHubMessageConverter" in settings settings["TagToIotHubMessageConverter"] = tc.GetInstance <IConverter <Tag, object> >(pluginNamespace); IProcessor iotHubSender = tc.GetInstance <ISender>(pluginNamespace) as IProcessor; if (iotHubSender != null) { this.AddSender("IotHubSender", iotHubSender); } base.Initialize(settings); }
public void ConstructorTest() { TagConfigDatabase db = TagConfigDatabase.Instance; db.Load(_tagRecords); TagStateManager tsm = new TagStateManager(db); Assert.AreEqual("AirConditioner1.Temperature", tsm.GetTag("AirConditioner1.Temperature").Name); }
public void Initialize(Dictionary <string, object> settings) { string[] fieldNames = new string[] { "IotHubConfigFile", "TagStateManager", "TagToIotHubMessageConverter" }; FieldValidator.CheckMissingFields(settings, fieldNames); string iotHubConfigFile = settings.GetValueOrNull("IotHubConfigFile") as string; _iotHubConfig = ConfigUtility.ReadConfig <IotHubConfig>(iotHubConfigFile); _dataConverter = settings.GetValueOrNull("TagToIotHubMessageConverter") as IConverter <Tag, object>; _tagStateManager = settings.GetValueOrNull("TagStateManager") as TagStateManager; _deviceClienPool = new DeviceClientPool(); _deviceClienPool.Initialize(_iotHubConfig.IotHubHostName, _iotHubConfig.TelemetryDevicePool); }
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); }
/// <summary> /// settings requires the following fields: /// settings.EventHubConfig = "EventHubConfig.json", /// settings.OpcServerConfig = "OpcServerConfig.json", /// settings.OpcNodeSubscriptionConfig = "OpcNodeSubscriptionConfig.json" /// For the format of the json files, check the SDK documentation /// </summary> /// <param name="settings"></param> public void Initialize(Dictionary <string, object> settings) { //ConfigureSettings(settings); //add new entry to fieldNames if a mandatory field is sent through settings string[] fieldNames = new string[] { "OpcServerConfigFile", "OpcTagConfigFile", "Logger", "OpcTagConverter", "TagStateManager" }; //validates missing fields and throws ValidationException in case of errors. Let us not catch it here so as to avoid //passing it through multiple layers FieldValidator.CheckMissingFields(settings, fieldNames); //convert json fields into configuraiton dictionaries string opcServerConfigFile = settings.GetValueOrNull <string, object>("OpcServerConfigFile") as string; _opcServerConfig = ConfigUtility.ReadConfig <Dictionary <string, string> >(opcServerConfigFile); string opcTagConfigFile = settings.GetValueOrNull <string, object>("OpcTagConfigFile") as string; _opcNodeSubscriptionConfig = ConfigUtility.ReadConfig <List <OpcNode> >(opcTagConfigFile); _tagStateManager = settings.GetValueOrNull <string, object>("TagStateManager") as TagStateManager; _opcTagConverter = settings.GetValueOrNull <string, object>("OpcTagConverter") as IConverter <object, Tag>; _logger = settings.GetValueOrNull <string, object>("Logger") as ILogger; }
public OpcSubscriptionHandlers(TagStateManager tagStateManager, IConverter <object, Tag> opcTagConverter, ILogger logger) { this._tagStateManager = tagStateManager; _opcTagConverter = opcTagConverter; this._logger = logger; }