Beispiel #1
0
        public void AddRouterFor <TEvent>(IRoute <TEvent> router)
        {
            if (!_routers.ContainsKey(typeof(TEvent)))
            {
                _routers.Add(typeof(TEvent), new List <Action <object> >());
            }

            _routers[typeof(TEvent)].Add(e => router.Handle((TEvent)e));
            _logger.Debug($"Registered router '{router.GetType().Name}' for event type '{typeof(TEvent).Name}'");
        }
Beispiel #2
0
        private void listen()
        {
            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

            byte[] data;
            while (!_token.IsCancellationRequested)
            {
                try
                {
                    data = _client.Receive(ref sender);
                    var packet = new Packet(data, sender);
                    Task.Factory.StartNew(() => _synchronization.Post((_) => _routes.Handle(packet)(), null), _token);
                }
                catch (SocketException ex)
                {
                    if (!serverStopped)
                    {
                        Debug.Fail(Process.GetCurrentProcess().ProcessName + "\n\r" + ex.ToString());
                    }
                    return;
                }
            }
        }
Beispiel #3
0
 public virtual Action Handle(Packet packet)
 {
     return(_next != null?_next.Handle(packet) : null);
 }