コード例 #1
0
ファイル: Reciever.cs プロジェクト: SlavcheProger/ws06CHAT
        public Reciever()
        {
            logger   = DependencyResolver.Get <ILogger>();
            chatCore = DependencyResolver.Get <IChatCore>();

            self = this as IReciever;
        }
        private static InputHandler NewHandler(
            Stream inputStream,
            IOutputHandler outputHandler,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter requestRouter,
            IResponseRouter responseRouter,
            Action <CancellationTokenSource> action)
        {
            var cts = new CancellationTokenSource();

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                cts.CancelAfter(TimeSpan.FromSeconds(5));
            }
            action(cts);

            var handler = new InputHandler(
                inputStream,
                outputHandler,
                reciever,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                Substitute.For <ILoggerFactory>());

            handler.Start();
            cts.Wait();
            Task.Delay(10).Wait();
            return(handler);
        }
コード例 #3
0
 protected override void Setup()
 {
     _senders      = new ISender[0];
     _recievers    = new IReciever[1];
     _recievers[0] = new UDPOSCReciever(10000)
     {
         IsQueueing = true,
         //onLatestDataRecieved = (msg) =>
         //{
         //    if (msg.IsBundle())
         //    {
         //        //Debug.LogError("Not implemented");
         //        var bundle = msg as OSCBundle;
         //        GetProjectionMatrix(bundle);
         //    }
         //    else
         //    {
         //        Debug.Log($"UDP OSCMessage (Thread) : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
         //    }
         //},
         onDataRecieved = (msg) =>
         {
             if (msg.IsBundle())
             {
                 var bundle = msg as OSCBundle;
                 GetProjectionMatrix(bundle);
             }
             else
             {
                 Debug.Log($"UDP OSCMessage : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
             }
         }
     };
 }
コード例 #4
0
 public InputHandler(
     Stream input,
     IOutputHandler outputHandler,
     IReciever reciever,
     IRequestProcessIdentifier requestProcessIdentifier,
     IRequestRouter <IHandlerDescriptor> requestRouter,
     IResponseRouter responseRouter,
     ILoggerFactory loggerFactory,
     ISerializer serializer
     )
 {
     if (!input.CanRead)
     {
         throw new ArgumentException($"must provide a readable stream for {nameof(input)}", nameof(input));
     }
     _input                    = input;
     _outputHandler            = outputHandler;
     _reciever                 = reciever;
     _requestProcessIdentifier = requestProcessIdentifier;
     _requestRouter            = requestRouter;
     _responseRouter           = responseRouter;
     _serializer               = serializer;
     _logger                   = loggerFactory.CreateLogger <InputHandler>();
     _scheduler                = new ProcessScheduler(loggerFactory);
     _inputThread              = new Thread(ProcessInputStream)
     {
         IsBackground = true, Name = "ProcessInputStream"
     };
 }
コード例 #5
0
 public virtual void Register(IReciever iReciever, ushort[] msgId)
 {
     if (null == iReciever || null == msgId || msgId.Length <= 0)
         return;
     for (int i = 0; i < msgId.Length; i++)
     {
         m_msgSingleRecieverMap[msgId[i]] = iReciever;
     }
 }
コード例 #6
0
ファイル: UserControl1.cs プロジェクト: Curros/testCommand
        private void UserControl1_Load(object sender, EventArgs e)
        {
            Application.AddMessageFilter(this); //Function to check the events.

            calculator = new Calculator(20, 10);

            addCmd = new AddCommand(calculator);
            subCmd = new SubtractCommand(calculator);
            mulCmd = new MultiplyCommand(calculator);
            divCmd = new DividerCommand(calculator);
        }
コード例 #7
0
 public void RegisterDependcy(IReciever regReciever)
 {
     OnRegisterReciever += regReciever.OnRegistered_EventHandler;
     OnRegisterReciever?.Invoke(this, new RegRecieverData()
     {
         owner = this
     });
     OnRegisterReciever -= regReciever.OnRegistered_EventHandler;
     if (regReciever.Owner == this)
     {
         Reciever = regReciever;
     }
 }
コード例 #8
0
 public virtual void RemoveMessage(IReciever iReciever, ushort[] msgId)
 {
     if (null == iReciever || null == msgId || msgId.Length <= 0)
         return;
     lock (m_syncRoot)
     {
         for (int i = 0; i < msgId.Length; i++)
         {
             if (m_msgSingleRecieverMap.ContainsKey(msgId[i]))
                 m_msgSingleRecieverMap.Remove(msgId[i]);
         }
     }
 }
コード例 #9
0
        public ServerConnection(string ip, int port)
        {
            Ip     = ip;
            Port   = port;
            Client = new TcpClient();

            reciever       = DependencyResolver.Get <IReciever>();
            sender         = DependencyResolver.Get <ISender>();
            commandHandler = DependencyResolver.Get <ICommandHandler>();
            disconnector   = DependencyResolver.Get <IDisconnector>();

            timer           = new System.Timers.Timer(60 * 1000);
            timer.Elapsed  += delegate { sender.Ping(); };
            timer.AutoReset = true;
            timer.Start();
        }
コード例 #10
0
        public Connection(
            Stream input,
            IOutputHandler outputHandler,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter requestRouter,
            IResponseRouter responseRouter,
            ILoggerFactory loggerFactory)
        {
            _requestRouter = requestRouter;

            _inputHandler = new InputHandler(
                input,
                outputHandler,
                reciever,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                loggerFactory
                );
        }
コード例 #11
0
        public Connection(
            Stream input,
            IOutputHandler outputHandler,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            IRequestRouter <IHandlerDescriptor> requestRouter,
            IResponseRouter responseRouter,
            ILoggerFactory loggerFactory,
            ISerializer serializer)
        {
            _requestRouter = requestRouter;

            _inputHandler = new InputHandler(
                input,
                outputHandler,
                reciever,
                requestProcessIdentifier,
                requestRouter,
                responseRouter,
                loggerFactory,
                serializer
                );
        }
コード例 #12
0
 public DividerCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #13
0
 public MultiplyCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #14
0
 public AddCommand(IReciever reciever)
     : base(reciever)
 {
 }
 public static JsonRpcServerOptions WithReciever(this JsonRpcServerOptions options, IReciever reciever)
 {
     options.Reciever = reciever;
     return(options);
 }
コード例 #16
0
 public CommandBase(IReciever reciever)
 {
     _reciever = reciever;
 }
コード例 #17
0
 public ACommand(IReciever reciever)
 {
     reciever_ = reciever;
 }
コード例 #18
0
 public Multiply(IReciever reciever) : base(reciever)
 {
 }
コード例 #19
0
 /// <summary>
 /// Unregister a specified reciever
 /// </summary>
 /// <param name="rec">The rec.</param>
 internal void UnRegister(IReciever rec)
 {
     _idToReciever.Remove(rec.getMyName());
 }
コード例 #20
0
 public CreateCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #21
0
 public ReadCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #22
0
 public NetProcessorAbs(IMessageQueue msgQueue, IEngine engine, IReciever reciever)
 {
     RegisterDependcy(msgQueue);
     RegisterDependcy(engine);
     RegisterDependcy(reciever);
 }
コード例 #23
0
 public override void Register(IReciever iReciever, ushort[] msgId)
 {
     base.Register(iReciever, msgId);
 }
コード例 #24
0
 public Command(IReciever reciever)
 {
     this.reciever = reciever;
 }
コード例 #25
0
        protected override void Setup()
        {
            _senders   = new ISender[6];
            _recievers = new IReciever[6];
            // tcp osc
            _senders[0]   = new TCPOSCSender(MY_ADDRESS, 20000);
            _recievers[0] = new TCPOSCReciever(MY_ADDRESS, 20000)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (msg) =>
                {
                    if (msg.IsBundle())
                    {
                        Debug.LogError("Not implemented");
                    }
                    else
                    {
                        Debug.Log($"UDP OSCMessage (Thread) : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
                    }
                },
                onDataRecieved = (msg) =>
                {
                    if (msg.IsBundle())
                    {
                        Debug.LogError("Not implemented");
                    }
                    else
                    {
                        Debug.Log($"UDP OSCMessage : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
                    }
                }
            };
            // udp osc
            _senders[1]   = new UDPOSCSender(MY_ADDRESS, 20001);
            _recievers[1] = new UDPOSCReciever(20001)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (msg) =>
                {
                    if (msg.IsBundle())
                    {
                        Debug.LogError("Not implemented");
                    }
                    else
                    {
                        Debug.Log($"UDP OSCMessage (Thread) : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
                    }
                },
                onDataRecieved = (msg) =>
                {
                    if (msg.IsBundle())
                    {
                        Debug.LogError("Not implemented");
                    }
                    else
                    {
                        Debug.Log($"UDP OSCMessage : Address = {msg.Address} Data = {msg.Data[0].ToString()}");
                    }
                }
            };
            // tcp
            _senders[2]   = new BaseTCPSender(MY_ADDRESS, 20002);
            _recievers[2] = new BaseTCPReciever <string>(MY_ADDRESS, 20002)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (str) =>
                {
                    Debug.Log("(Thread) " + str);
                },
                onDataRecieved = (str) =>
                {
                    Debug.Log(str);
                }
            };
            // udp
            _senders[3]   = new BaseUDPSender(MY_ADDRESS, 20003);
            _recievers[3] = new BaseUDPReciever <string>(20003)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (str) =>
                {
                    Debug.Log("(Thread) " + str);
                },
                onDataRecieved = (str) =>
                {
                    Debug.Log(str);
                }
            };
            // tcp json
            _senders[4]   = new TCPJsonSender(MY_ADDRESS, 20004);
            _recievers[4] = new TCPJsonReciever(MY_ADDRESS, 20004)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (msg) =>
                {
                    var recievedData = JsonUtility.FromJson <BaseJsonData>(msg);

                    switch (recievedData.className)
                    {
                    case nameof(SampleJsonData):
                        var data = JsonUtility.FromJson <SampleJsonData>(msg);
                        Debug.Log($"recieved samplejsondata (thread) : test1 = {data.test1} test2 = {data.test2} test3 = {data.test3} test4 = {data.test4}");
                        break;

                    case nameof(SampleJsonData2):
                        var data2 = JsonUtility.FromJson <SampleJsonData2>(msg);
                        Debug.Log($"recieved samplejsondata2 (thread) : test5 = {data2.test5} test6 = {data2.test6} test7 = {data2.test7} test8 = {data2.test8}");
                        break;
                    }
                },
                onDataRecieved = (msg) =>
                {
                    var recievedData = JsonUtility.FromJson <BaseJsonData>(msg);

                    switch (recievedData.className)
                    {
                    case nameof(SampleJsonData):
                        var data = JsonUtility.FromJson <SampleJsonData>(msg);
                        Debug.Log($"recieved samplejsondata : test1 = {data.test1} test2 = {data.test2} test3 = {data.test3} test4 = {data.test4}");
                        break;

                    case nameof(SampleJsonData2):
                        var data2 = JsonUtility.FromJson <SampleJsonData2>(msg);
                        Debug.Log($"recieved samplejsondata2 : test5 = {data2.test5} test6 = {data2.test6} test7 = {data2.test7} test8 = {data2.test8}");
                        break;
                    }
                }
            };
            // udp json
            _senders[5]   = new UDPJsonSender(MY_ADDRESS, 20005);
            _recievers[5] = new UDPJsonReciever(20005)
            {
                IsQueueing           = true,
                onLatestDataRecieved = (msg) =>
                {
                    var recievedData = JsonUtility.FromJson <BaseJsonData>(msg);

                    switch (recievedData.className)
                    {
                    case nameof(SampleJsonData):
                        var data = JsonUtility.FromJson <SampleJsonData>(msg);
                        Debug.Log($"recieved samplejsondata (thread) : test1 = {data.test1} test2 = {data.test2} test3 = {data.test3} test4 = {data.test4}");
                        break;

                    case nameof(SampleJsonData2):
                        var data2 = JsonUtility.FromJson <SampleJsonData2>(msg);
                        Debug.Log($"recieved samplejsondata2 (thread) : test5 = {data2.test5} test6 = {data2.test6} test7 = {data2.test7} test8 = {data2.test8}");
                        break;
                    }
                },
                onDataRecieved = (msg) =>
                {
                    var recievedData = JsonUtility.FromJson <BaseJsonData>(msg);

                    switch (recievedData.className)
                    {
                    case nameof(SampleJsonData):
                        var data = JsonUtility.FromJson <SampleJsonData>(msg);
                        Debug.Log($"recieved samplejsondata : test1 = {data.test1} test2 = {data.test2} test3 = {data.test3} test4 = {data.test4}");
                        break;

                    case nameof(SampleJsonData2):
                        var data2 = JsonUtility.FromJson <SampleJsonData2>(msg);
                        Debug.Log($"recieved samplejsondata2 : test5 = {data2.test5} test6 = {data2.test6} test7 = {data2.test7} test8 = {data2.test8}");
                        break;
                    }
                }
            };
        }
コード例 #26
0
 public SubtractCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #27
0
 /// <summary>
 /// Registers the specified reciever.
 /// </summary>
 /// <param name="rec">The rec.</param>
 internal void Register(IReciever rec)
 {
     _idToReciever.Add(rec.getMyName(), rec);
 }
コード例 #28
0
 public UndoCommand(IReciever reciever)
 {
     _reciever = reciever;
 }
コード例 #29
0
 public DMCommand1(IReciever receiver)
 {
     this.receiver = receiver;
 }
コード例 #30
0
 public void AddReciever(IReciever Reciever)
 {
     this.recievers.Add(Reciever);
 }
コード例 #31
0
 public override void RemoveMessage(IReciever iReciever, ushort[] msgId)
 {
     base.RemoveMessage(iReciever, msgId);
 }
コード例 #32
0
 public UpdateCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #33
0
        internal JsonRpcServer(
            Stream input,
            Stream output,
            IReciever reciever,
            IRequestProcessIdentifier requestProcessIdentifier,
            ILoggerFactory loggerFactory,
            ISerializer serializer,
            IServiceCollection services,
            IEnumerable <Assembly> assemblies)
        {
            var outputHandler = new OutputHandler(output, serializer);

            services.AddLogging();
            _reciever   = reciever;
            _serializer = serializer;
            _collection = new HandlerCollection();

            services.AddSingleton <IOutputHandler>(outputHandler);
            services.AddSingleton(_collection);
            services.AddSingleton(_serializer);
            services.AddSingleton <OmniSharp.Extensions.JsonRpc.ISerializer>(_serializer);
            services.AddSingleton(requestProcessIdentifier);
            services.AddSingleton(_reciever);
            services.AddSingleton(loggerFactory);

            services.AddJsonRpcMediatR(assemblies);
            services.AddSingleton <IJsonRpcServer>(this);
            services.AddSingleton <IRequestRouter, RequestRouter>();
            services.AddSingleton <IReciever, Reciever>();
            services.AddSingleton <IResponseRouter, ResponseRouter>();

            var foundHandlers = services
                                .Where(x => typeof(IJsonRpcHandler).IsAssignableFrom(x.ServiceType) && x.ServiceType != typeof(IJsonRpcHandler))
                                .ToArray();

            // Handlers are created at the start and maintained as a singleton
            foreach (var handler in foundHandlers)
            {
                services.Remove(handler);

                if (handler.ImplementationFactory != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationFactory));
                }
                else if (handler.ImplementationInstance != null)
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationInstance));
                }
                else
                {
                    services.Add(ServiceDescriptor.Singleton(typeof(IJsonRpcHandler), handler.ImplementationType));
                }
            }

            _serviceProvider = services.BuildServiceProvider();

            var handlers = _serviceProvider.GetServices <IJsonRpcHandler>().ToArray();

            _collection.Add(handlers);

            _requestRouter  = _serviceProvider.GetRequiredService <IRequestRouter>();
            _responseRouter = _serviceProvider.GetRequiredService <IResponseRouter>();
            _connection     = ActivatorUtilities.CreateInstance <Connection>(_serviceProvider, input);
        }
コード例 #34
0
 public DeleteCommand(IReciever reciever)
     : base(reciever)
 {
 }
コード例 #35
0
 public void AddReciever(IReciever Reciever)
 {
     this.recievers.Add(Reciever);
 }