public ExampleDSLink(Configuration config) : base(config) { _rngValues = new Dictionary <string, Value>(); _random = new Random(); Responder.AddNodeClass("rngAdd", delegate(Node node) { node.Configs.Set(ConfigType.DisplayName, new Value("Create RNG")); node.AddParameter(new Parameter { Name = "rngName", ValueType = Nodes.ValueType.String }); node.SetAction(new ActionHandler(Permission.Config, _createRngAction)); }); Responder.AddNodeClass("rng", delegate(Node node) { node.Configs.Set(ConfigType.Writable, new Value(Permission.Read.Permit)); node.Configs.Set(ConfigType.ValueType, Nodes.ValueType.Number.TypeValue); node.Value.Set(0); lock (_rngValues) { _rngValues.Add(node.Name, node.Value); } }); Task.Run(() => _updateRandomNumbers()); }
public ExampleDSLink(Configuration config) : base(config) { Responder.AddNodeClass("testAction", delegate(Node node) { node.AddParameter(new Parameter("string", "string")); node.AddParameter(new Parameter("int", "int")); node.AddParameter(new Parameter("number", "number")); node.AddColumn(new Column("success", "bool")); var handler = new ActionHandler(Permission.Write, async(request) => { await request.UpdateTable(new Table { new Row { true } }); await request.Close(); }); node.SetAction(handler); }); Responder.AddNodeClass("rng", delegate(Node node) { node.Writable = Permission.Read; node.ValueType = ValueType.Number; node.Value.Set(0.1); lock (_values) { _values.Add(node.Value); } }); Task.Run(async() => { await Task.Delay(5000); UpdateRandomNumbers(); }); }
public ExampleDSLink(Configuration config) : base(config) { Task.Run(async() => { var a = await Requester.Subscribe("/data/Test", (update) => { Debug.WriteLine("A: " + update.Value); }); await Task.Delay(5000); var b = await Requester.Subscribe("/data/Test", (update) => { Debug.WriteLine("B: " + update.Value); }); await Task.Delay(5000); await Requester.Unsubscribe(a); await Task.Delay(5000); await Requester.Unsubscribe(b); }); Responder.AddNodeClass("testAction", delegate(Node node) { node.AddParameter(new Parameter("string", "string")); node.AddParameter(new Parameter("int", "int")); node.AddParameter(new Parameter("number", "number")); node.AddColumn(new Column("success", "bool")); ActionHandler handler = new ActionHandler(Permission.Write, async(request) => { await request.UpdateTable(new Table { new Row { true } }); await request.Close(); }); node.SetAction(handler); }); List <Value> rngs = new List <Value>(); Responder.AddNodeClass("rng", delegate(Node node) { node.Writable = Permission.Read; node.ValueType = ValueType.Number; node.Value.Set(0.1); rngs.Add(node.Value); }); /*Task.Run(async () => * { * await Task.Delay(5000); * int num = 0; * * while (true) * { * foreach (var rng in rngs) * { * rng.Set(num++); * } * } * });*/ }
public SensolusLink(Configuration config, CommandLineArguments cmdLineOptions) : base(config) { //Perform any configuration overrides from command line options if (cmdLineOptions.BrokerUrl != null) { config.BrokerUrl = cmdLineOptions.BrokerUrl; } if (cmdLineOptions.Token != null) { config.Token = cmdLineOptions.Token; } if (cmdLineOptions.NodesFileName != null) { config.NodesFilename = cmdLineOptions.NodesFileName; } if (cmdLineOptions.KeysFolder != null) { config.KeysFolder = cmdLineOptions.KeysFolder; } Responder.AddNodeClass("connNode", delegate(Node node) { node.CreateChild("Remove", "removeNode").BuildNode(); }); Responder.AddNodeClass("removeNode", delegate(Node node) { node.SetAction(new ActionHandler(Permission.Config, (InvokeRequest request) => { lock (connCfgs) { connCfgs.Remove(node.Parent.Name.ToLower()); } SaveData(); })); }); Responder.AddNodeClass("handleActivity", delegate(Node node) { node.Configs.Set(ConfigType.DisplayName, new Value("Handle Activity Notification")); node.AddParameter(new Parameter { Name = SensolusConstants.PATH, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.SERIAL, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_ID, ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_TIME, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_INSERTTIME, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_STATE, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_LAT, ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_LON, ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_SRC, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_ACCURACY, ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_ADDRESS, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.ACTIVITY_GEOZONE, ValueType = DSLink.Nodes.ValueType.String }); node.SetAction(new ActionHandler(Permission.Config, _handleActivityNotification)); }); Responder.AddNodeClass("handleAlert", delegate(Node node) { node.Configs.Set(ConfigType.DisplayName, new Value("Handle Alert Notification")); node.AddParameter(new Parameter { Name = SensolusConstants.PATH, ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = SensolusConstants.SERIAL, ValueType = DSLink.Nodes.ValueType.String }); node.SetAction(new ActionHandler(Permission.Config, _handleAlertNotification)); }); Responder.AddNodeClass("connAdd", delegate(Node node) { node.Configs.Set(ConfigType.DisplayName, new Value("Add Connection")); node.AddParameter(new Parameter { Name = "Name", ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = "apiKey", ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = "DB Address", ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = "DB Port", ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = "DB Name", ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = "DB User", ValueType = DSLink.Nodes.ValueType.String }); node.AddParameter(new Parameter { Name = "DB Password", ValueType = DSLink.Nodes.ValueType.String, Editor = EditorType.Password }); node.AddParameter(new Parameter { Name = "Interval (minutes)", ValueType = DSLink.Nodes.ValueType.Number }); node.AddParameter(new Parameter { Name = "Pool", ValueType = DSLink.Nodes.ValueType.Boolean }); node.AddParameter(new Parameter { Name = "Old Data", ValueType = DSLink.Nodes.ValueType.Boolean }); node.AddParameter(new Parameter { Name = "Context", ValueType = DSLink.Nodes.ValueType.String }); node.SetAction(new ActionHandler(Permission.Config, _createConnection)); }); Task.Run(() => { long i = 0; while (true) { lock (connCfgs) { foreach (var key in connCfgs.Keys) { var cfg = connCfgs[key]; if (i % cfg.Interval == 0) { Task.Run(() => { var copyCfg = cfg; copyCfg.Clean = false; DataProcessor dp = new DataProcessor(copyCfg); dp.Run(NpgsqlFactory.Instance); cfg.LastExecute = DateTime.Now; connCfgs[key] = cfg; }); } } } ++i; Thread.Sleep(TimeSpan.FromMinutes(1)); } }); }