Ejemplo n.º 1
0
        public async Task <object> GetInvoker(IDictionary <string, object> input)
        {
            var service   = (string)input["service"];
            var callbacks = (IDictionary <string, object>)input["callbacks"];
            var server    = new MyServer(service, callbacks);

            return((Func <object, Task <object> >)(async(i) =>
            {
                var opts = (IDictionary <string, object>)i;
                var method = (string)opts["method"];
                var topic = opts.ContainsKey("topic") ? (string)opts["topic"] : null;
                var item = opts.ContainsKey("item") ? (string)opts["item"] : null;

                switch (method)
                {
                case "Register":
                    server.Register();
                    break;

                case "Unregister":
                    server.Unregister();
                    break;

                case "Advise":
                    await Task.Run(() => server.Advise(topic, item));
                    break;

                case "Disconnect":
                    server.Disconnect();
                    break;

                case "Pause":
                    server.Pause();
                    break;

                case "Resume":
                    server.Resume();
                    break;

                case "Dispose":
                    server.Dispose();
                    break;

                case "Service":
                    return server.Service;

                case "IsRegistered":
                    return server.IsRegistered;
                }

                return null;
            }));
        }
Ejemplo n.º 2
0
 static Thread listenThread; // потока для прослушивания
 static void Main(string[] args)
 {
     try
     {
         server       = new MyServer();
         listenThread = new Thread(new ThreadStart(server.Listen));
         listenThread.Start(); //старт потока
     }
     catch (Exception ex)
     {
         server.Disconnect();
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 3
0
        public async Task<object> GetInvoker(IDictionary<string, object> input)
        {
            var service = (string)input["service"];
            var callbacks = (IDictionary<string, object>)input["callbacks"];
            var server = new MyServer(service, callbacks);

            return (Func<object, Task<object>>)(async (i) =>
            {
                var opts = (IDictionary<string, object>)i;
                var method = (string)opts["method"];
                var topic = opts.ContainsKey("topic") ? (string)opts["topic"] : null;
                var item = opts.ContainsKey("item") ? (string)opts["item"] : null;

                switch (method)
                {
                    case "Register":
                        server.Register();
                        break;
                    case "Unregister":
                        server.Unregister();
                        break;
                    case "Advise":
                        await Task.Run(() => server.Advise(topic, item));
                        break;
                    case "Disconnect":
                        server.Disconnect();
                        break;
                    case "Pause":
                        server.Pause();
                        break;
                    case "Resume":
                        server.Resume();
                        break;
                    case "Dispose":
                        server.Dispose();
                        break;
                    case "Service":
                        return server.Service;
                    case "IsRegistered":
                        return server.IsRegistered;
                }

                return null;
            });
        }