Example #1
0
        public void Start()
        {
            _finishedWaitHandle.Reset();
            Init();

            _messageBus = new NamedPipeMessageBus(_appPipeName, _hostPipeName);

            _messageBus.Subscribe((ConnectionOpenedMessage msg) =>
            {
                RegisterConnection(new ProxyWebSocketConnection(msg, this));
            });

            _messageBus.Subscribe((ConnectionClosedMessage msg) =>
            {
                UnregisterConnection(msg.ConnectionIdentity);
            });

            _messageBus.Subscribe((DataReceivedMessage msg) =>
            {
                var c = GetConnection(msg.ConnectionIdentity);
                if (c == null)
                {
                    _log.Error("Received message for not existing connection");
                    return;
                }

                OnMessageReceived(new WebSocketMessageEventArgs(c, msg.Data));
            });

            _messageBus.Subscribe((PingReceivedMessage msg) =>
            {
                var c = GetConnection(msg.ConnectionIdentity);
                if (c == null)
                {
                    _log.Error("Received message for not existing connection");
                    return;
                }

                OnPingReceived(new WebSocketConnectionEventArgs(c));
            });

            _messageBus.Subscribe((CloseApplicationMessage msg) =>
            {
                Stop();
            });

            _messageBus.Notify(new ApplicationActivatedMessage());
        }
Example #2
0
 internal void SendMessage(Guid connectionIdentity, string data)
 {
     _messageBus.Notify(new SendDataMessage(connectionIdentity, data));
 }