/// <summary> /// Initializes a new instance of the <see cref="SimulationConnector"/> class. /// </summary> /// <param name="manager">The ApplicationManager instance.</param> /// <param name="instanceName">The assigned name for this instance.</param> /// <param name="logger">The logger for this instance.</param> public SimulationConnector(IApplicationManager manager, string instanceName, xLogger logger) { InstanceName = instanceName; this.logger = logger; Manager = manager; Name = "Simulation"; FQN = "OpenIIoT.Plugin.Connector.Simulation"; Version = "1.0.0.0"; PluginType = PluginType.Connector; ItemProviderName = FQN; logger.Info("Initializing " + PluginType + " " + FQN + "." + instanceName); InitializeItems(); random = new Random(); randomValue = 0; rwValue = new ReadWriteValue(); rwValue.Min = 0L; rwValue.Max = 100L; Subscriptions = new Dictionary <Item, List <Action <object> > >(); ConfigureFileWatch(); }
public bool Write(Item item, object value) { bool retVal = default(bool); try { string obj = ((JObject)value).ToString(Formatting.None); logger.Info("Write: " + item + " value: " + obj); rwValue = JsonConvert.DeserializeObject <ReadWriteValue>(obj, new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Error, CheckAdditionalContent = true }); // will fire the Changed event which will cascade the value through the model foreach (Item key in Subscriptions.Keys) { if (key.FQN.Contains("ReadWrite.Read")) { foreach (Action <object> callback in Subscriptions[key]) { callback.Invoke(rwValue); } } } retVal = true; } catch (Exception ex) { logger.Error(ex.Message); } return(retVal); }