Пример #1
0
        public static void Register(Funcis funcis)
        {
            var node = funcis.CreateNode("You", new string[] { "Extendee" });

            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + funcis.sigPath;
            File.WriteAllText(Path.Combine(path, "signalSetup.is"), signalSetup);
            node["Handle"] = new FuncEx((sig, args, cb) =>
            {
                if (args.Count < 3)
                    return;
                string ev = (string)args[0];
                string signal = (string)args[1];
                string name = (string)args[2];
                try
                {
                    if (ev == "loaded")
                    {
                        File.WriteAllText(Path.Combine(funcis.GetWatchedPath(), name), signal);
                    }
                    else if (ev == "removed")
                    {
                        File.Delete(Path.Combine(funcis.GetWatchedPath(), name));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            });
            node["Request"] = new FuncEx((sig, args, cb) =>
            {
                cb(new Newtonsoft.Json.Linq.JArray());
            });
        }
Пример #2
0
        static void Main(string[] argss)
        {
            var url = argss.Count() > 0 ? argss[0] : "http://kod-test.azurewebsites.net/";
            //var url = argss.Count() > 0 ? argss[0] : "http://localhost:3000";
            Console.WriteLine("Proxying to url: " + url);
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                var ex = e.ExceptionObject as Exception;
                Console.WriteLine("Exited by unknown error: " + ex.Message);
                var p = System.Diagnostics.Process.GetCurrentProcess();
                p.Kill();
            };

            KnxServer.Run((gate, writer) =>
            {
                var funcis = new Funcis();
                var node = funcis.CreateNode("KNX", new string[] { "Knx" });
                SignalExtender.Register(funcis);
                node["Listen"] = new FuncEx(new Action<SignalContext, JArray, Action<JArray>>((sig, args, cb) =>
                {
                    if (args.Count < 1)
                        return;
                    EnmxAddress address = (string)args[0];
                    Console.WriteLine("Listen to " + address.Address);
                    gate.ConstructGate<int>(address, new Action<int, GroupTelegram>((val, telegram) =>
                    {
                        Console.WriteLine("Received from " + address.Address + " value of " + val);
                        cb(new JArray(val, telegram.Received));
                    }));
                    sig.OnStop(new Action(() =>
                    {
                        Console.WriteLine("Stop listen to " + address.Address);
                        gate.RemoveGate(address);
                    }));
                }));

                node["Send"] = new FuncEx((sig, args, cb) =>
                {
                    if (args.Count < 2)
                        return;
                    EnmxAddress address = (string)args[0];
                    int val = (int)args[1];
                    Console.WriteLine("Sending to: " + address + " the value of " + val);
                    writer.Write(address, val);
                });
                funcis.AddProxy(url);
                funcis.AddRemoteNode(url, "Central", new string[0]);
                funcis.AddRemoteNode(url, "Me", new string[] { "Extender" });
                var t = funcis.Start();
                t.Wait();
                Console.WriteLine("KnxNode is running");
                funcis.BeginListen();
                while (true)
                {
                    Thread.Sleep(1000);
                }

            }, true);
            return;
        }
Пример #3
0
 static void Main(string[] argss)
 {
     var funcis = new Funcis();
     var nodeA = funcis.CreateNode("Kv", new string[] { "Knx" });
     nodeA["Add"] = new FuncEx((signal, args, cb) =>
     {
         Console.WriteLine("Add");
         cb(new JArray(args[0].Value<int>() + args[1].Value<int>()));
     });
     nodeA["Print"] = new FuncEx((signal, args, cb) =>
     {
         Console.WriteLine(args[0].Value<int>());
     });
     funcis.AddProxy("http://192.168.1.109:3000");
     funcis.AddRemoteNode("http://192.168.1.109:3000", "Central", new string[0]);
     //funcis.Start();
     while (true)
     {
         var t = funcis.Listen();
         t.Wait();
     }
     Console.ReadLine();
 }