Esempio n. 1
0
        private void HandleOnPublish(IWampConnection connection, PublishMessage msg)
        {
            if (!_subscriptions.ContainsKey(msg.TopicUri))
            {
                return;
            }

            var subscriptions = new HashSet <IWampServerConnection>(msg.Eligible == null
                    ? _subscriptions[msg.TopicUri]
                    : _subscriptions[msg.TopicUri].Where(x => msg.Eligible.Contains(x.WebSocketConnectionInfo.Id)));

            if (msg.ExcludeMe.HasValue)
            {
                subscriptions.RemoveWhere(x => x.WebSocketConnectionInfo.Id == connection.WebSocketConnectionInfo.Id);
            }

            if (msg.Exclude != null)
            {
                subscriptions.RemoveWhere(x => msg.Exclude.Contains(x.WebSocketConnectionInfo.Id));
            }

            foreach (var subscription in subscriptions)
            {
                subscription.SendPublish(msg);
            }
        }
Esempio n. 2
0
        private void OnConnectionOpen(object sender, EventArgs e)
        {
            IWampConnection <TMessage> connection = sender as IWampConnection <TMessage>;

            connection.ConnectionOpen -= OnConnectionOpen;
            OnConnectionOpen(connection);
        }
 public IWampIncomingMessageHandler <TMessage> Build(TRawClient client, IWampConnection <TMessage> connection)
 {
     // No dependency injection here.
     return(new WampIncomingMessageHandler <TMessage, object>
                (new WampRequestMapper <TMessage>(client.GetType(), mFormatter),
                new WampMethodBuilder <TMessage, object>(client, mFormatter)));
 }
Esempio n. 4
0
        public IWampClientProxy <TMessage> Create(IWampConnection <TMessage> connection)
        {
            IWampOutgoingMessageHandler outgoingHandler =
                mOutgoingHandlerBuilder.Build(connection);

            WampConnectionMonitor <TMessage> monitor =
                new WampConnectionMonitor <TMessage>(connection);

            IDisposable disposable =
                new WampClientContainerDisposable <TMessage, IWampClientProxy <TMessage> >
                    (mContainer, connection);

            WampClientProxy <TMessage> result =
                new WampClientProxy <TMessage>(outgoingHandler,
                                               mOutgoingSerializer,
                                               monitor,
                                               disposable);

            result.Session = (long)mContainer.GenerateClientId(result);
            result.Binding = mBinding;

            IDetailedWampConnection <TMessage> detailedConnection =
                connection as IDetailedWampConnection <TMessage>;

            if (detailedConnection != null)
            {
                result.TransportDetails =
                    detailedConnection.TransportDetails;
            }

            monitor.Client = result;

            return(result);
        }
Esempio n. 5
0
        private static void OnMessage(IWampConnection connection, string msg)
        {
            var message = JsonConvert.DeserializeObject <IWampMessage>(msg);

            switch (message.MessageType)
            {
            case MessageType.Prefix:
                connection.OnPrefix(message as PrefixMessage);
                break;

            case MessageType.Call:
                connection.OnCall(message as CallMessage);
                break;

            case MessageType.Subscribe:
                connection.OnSubscribe(message as SubscribeMessage);
                break;

            case MessageType.Unsubscribe:
                connection.OnUnsubscribe(message as UnsubscribeMessage);
                break;

            case MessageType.Publish:
                connection.OnPublish(message as PublishMessage);
                break;

            default:
                throw new ArgumentException("msg");
            }
        }
        public TServer Create(TRawClient client, IWampConnection <TMessage> connection)
        {
            IWampOutgoingMessageHandler handler =
                mOutgoingHandlerBuilder.Build(client, connection);

            WampOutgoingInterceptor <TMessage> interceptor =
                new WampOutgoingInterceptor <TMessage>(mOutgoingSerializer,
                                                       handler);

            ProxyGenerationOptions proxyOptions =
                new ProxyGenerationOptions()
            {
                Selector = new WampInterceptorSelector <TMessage>()
            };

            proxyOptions.AddMixinInstance(new DisposableForwarder(connection));

            TServer result =
                (TServer)mProxyGenerator.CreateInterfaceProxyWithoutTarget
                    (typeof(TServer),
                    new Type[] { typeof(IDisposable) },
                    proxyOptions, interceptor);

            return(result);
        }
Esempio n. 7
0
 public WampServiceClientContainer(string server, string userName, IConcurrencyService concurrencyService, ILoggerFactory loggerFactory)
 {
     _statusStream       = new BehaviorSubject <ConnectionInfo>(new ConnectionInfo(ConnectionStatus.Uninitialized, server, TransportName));
     _connection         = new WampConnection(server, userName, loggerFactory);
     _server             = server;
     _concurrencyService = concurrencyService;
     _loggerFactory      = loggerFactory;
 }
        /// <summary>
        /// Creates a new instance of <see cref="WampServerProxyHandler{TMessage}"/>.
        /// </summary>
        /// <param name="connection">The connection used to send and receieve <see cref="WampMessage{TMessage}"/>s.</param>
        /// <param name="incomingHandler">The handler used to handle incoming messages.</param>
        public WampServerProxyHandler(IWampConnection <TMessage> connection,
                                      IWampIncomingMessageHandler <TMessage> incomingHandler)
        {
            mConnection      = connection;
            mIncomingHandler = incomingHandler;

            mConnection.MessageArrived += MessageArrived;
        }
 public WampClientConnectionMonitor
     (IWampServerProxyBuilder <TMessage, IWampAuxiliaryClient, IWampServer> serverProxyBuilder,
     IWampConnection <TMessage> connection)
 {
     mProxy = serverProxyBuilder.Create(new WampAuxiliaryClient(this), connection);
     connection.ConnectionClosed += OnConnectionLost;
     connection.ConnectionError  += OnConnectionError;
 }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new WAMP session for provided client connection
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        protected virtual IWampSession InitializeWampSession(IWampConnection connection)
        {
            var session = new WampSession(connection);

            Sessions.AddSession(session);

            return(session);
        }
Esempio n. 11
0
        /// <summary>
        /// Method called when new WAMP client has connected.
        /// </summary>
        /// <param name="connection">Object representing connected WAMP client</param>
        protected virtual void OnConnected(IWampConnection connection)
        {
            var session        = InitializeWampSession(connection);
            var welcomeMessage = new WelcomeMessage(session.SessionId, WampConstants.ProtocolVersion, WampConstants.ServerIdentifier);
            var json           = MessageProvider.SerializeMessage(welcomeMessage);

            session.Connection.Send(json);
        }
Esempio n. 12
0
 public WampRealmProxyFactory(WampChannelBuilder <TMessage> parent,
                              string realmName,
                              IWampConnection <TMessage> connection,
                              IWampClientAuthenticator authenticator)
     : this(parent, realmName, connection)
 {
     mAuthenticator = authenticator;
 }
Esempio n. 13
0
        public dynamic GetDynamicClient(IWampConnection <TMessage> connection)
        {
            IWampRpcClientHandler handler = mClientHandlerBuilder.Build(connection);

            DynamicWampRpcClient client = new DynamicWampRpcClient(handler, mSerializer);

            return(client);
        }
Esempio n. 14
0
        protected override void OpenConnection <TMessage>(SocketData original, IWampConnection <TMessage> connection)
        {
            RawSocketConnection <TMessage> casted = connection as RawSocketConnection <TMessage>;

            Task task = Task.Run(casted.RunAsync);

            original.ReadTask = task;
        }
Esempio n. 15
0
 public WampRealmProxyFactory(WampChannelBuilder <TMessage> parent,
                              string realmName,
                              IWampConnection <TMessage> connection)
 {
     mParent     = parent;
     mRealmName  = realmName;
     mConnection = connection;
 }
Esempio n. 16
0
        protected override void OpenConnection <TMessage>(WebSocketData original, IWampConnection <TMessage> connection)
        {
            IWampWebSocketWrapperConnection casted = connection as IWampWebSocketWrapperConnection;

            Task task = Task.Run(casted.RunAsync);

            original.ReadTask = task;
        }
        public WampConnectionMonitor(IWampConnection <TMessage> connection)
        {
            mConnected  = true;
            mConnection = connection;

            mConnection.ConnectionError  += OnConnectionError;
            mConnection.ConnectionClosed += OnConnectionClosed;
        }
Esempio n. 18
0
 public WampServiceClient(IWampConnection connection, string serviceType, IScheduler scheduler, ILoggerFactory loggerFactory)
 {
     _log         = loggerFactory.Create(typeof(WampServiceClient));
     _connection  = connection;
     _serviceType = serviceType;
     _serviceInstanceStreamCache = CreateServiceInstanceDictionaryStream(serviceType, scheduler)
                                   .Multicast(new BehaviorSubject <IDictionary <string, ILastValueObservable <ServiceInstanceStatus> > >(
                                                  new Dictionary <string, ILastValueObservable <ServiceInstanceStatus> >()));
 }
Esempio n. 19
0
        private void HandleOnSubscribe(IWampConnection connection, SubscribeMessage msg)
        {
            if (!_subscriptions.ContainsKey(msg.TopicUri))
            {
                return;
            }

            _subscriptions[msg.TopicUri].Add(connection);
        }
Esempio n. 20
0
        private void OnConnectionClosed(object sender)
        {
            IWampConnection <TMessage> connection = sender as IWampConnection <TMessage>;

            connection.ConnectionClosed -= OnConnectionClose;
            connection.MessageArrived   -= OnNewMessage;
            connection.ConnectionError  -= OnConnectionError;
            OnCloseConnection(connection);
        }
        public IWampServerProxy Create(IWampClient <TMessage> client, IWampConnection <TMessage> connection)
        {
            IWampOutgoingMessageHandler outgoingMessageHandler = mOutgoingHandlerBuilder.Build(client, connection);

            WampServerProxy result =
                new WampServerProxy(outgoingMessageHandler, mSerializer, connection);

            return(result);
        }
Esempio n. 22
0
        protected virtual void OnNewMessage(IWampConnection <TMessage> connection, WampMessage <TMessage> message)
        {
            TClient client = ClientContainer.GetClient(connection);

            using (IDisposable sessionIdMappedContext = SessionIdMappedContext(client))
            {
                mHandler.HandleMessage(client, message);
            }
        }
Esempio n. 23
0
        private void OnNewConnection(IWampConnection <TMessage> connection)
        {
            mSubject.OnNext(connection);

            // Yuck
            IControlledWampConnection <TMessage> casted = connection as IControlledWampConnection <TMessage>;

            casted.Connect();
        }
Esempio n. 24
0
        protected virtual void OnNewConnection(IWampConnection <TMessage> connection)
        {
            TClient client = ClientContainer.GetClient(connection);

            connection.MessageArrived   += OnNewMessage;
            connection.ConnectionOpen   += OnConnectionOpen;
            connection.ConnectionError  += OnConnectionError;
            connection.ConnectionClosed += OnConnectionClose;
        }
Esempio n. 25
0
        protected override void OnNewConnection(IWampConnection <TMessage> connection)
        {
            base.OnNewConnection(connection);

            IWampClientProxy <TMessage> client = ClientContainer.GetClient(connection);

            mLogger.DebugFormat("Client connected, session id: {SessionId}", client.Session);

            mSessionHandler.OnNewClient(client);
        }
Esempio n. 26
0
        private void RaiseSessionClosed(IWampConnection <TMessage> connection)
        {
            EventHandler <WampSessionEventArgs> sessionClosed = SessionClosed;

            if (sessionClosed != null)
            {
                IWampClient client = ClientContainer.GetClient(connection);
                sessionClosed(this, new WampSessionEventArgs(client.SessionId));
            }
        }
Esempio n. 27
0
        public void OnNext(IWampConnection <TMessage> value)
        {
            mSubject.OnNext(value);

            // Yuck

            if (value is IControlledWampConnection <TMessage> casted)
            {
                casted.Connect();
            }
        }
Esempio n. 28
0
        protected override void OnCloseConnection(IWampConnection <TMessage> connection)
        {
            if (ClientContainer.TryGetClient(connection, out IWampClientProxy <TMessage> client))
            {
                mLogger.DebugFormat("Client disconnected, session id: {SessionId}", client.Session);

                mSessionHandler.OnClientDisconnect(client);
            }

            base.OnCloseConnection(connection);
        }
Esempio n. 29
0
        public override void RemoveClient(IWampConnection <TMessage> connection)
        {
            bool clientProxyFound = TryGetClient(connection, out IWampClientProxy <TMessage> clientProxy);

            base.RemoveClient(connection);

            if (clientProxyFound)
            {
                mSessionIdMap.ReleaseSession(clientProxy.Session);
            }
        }
Esempio n. 30
0
        private void HandleOnPrefix(IWampConnection connection, PrefixMessage msg)
        {
            if (!Prefixes.ContainsKey(connection))
            {
                Prefixes.Add(connection, new Dictionary <string, Uri>());
            }

            var prefixes = Prefixes[connection];

            prefixes[msg.Prefix] = msg.Uri;
        }
        private IWampServer GetClient(IWampConnection<JToken> connection, IWampClient<JToken> wampClient)
        {
            var serverProxyBuilder = new WampServerProxyBuilder<JToken, IWampClient<JToken>, IWampServer>
                (new WampOutgoingRequestSerializer<JToken>(mFormatter),
                 new WampServerProxyOutgoingMessageHandlerBuilder<JToken, IWampClient<JToken>>
                     (GetHandlerBuilder()));

            var proxy =
                serverProxyBuilder.Create(wampClient, connection);

            return proxy;
        }
Esempio n. 32
0
        /// <summary>
        /// Method called when new WAMP client has connected.
        /// </summary>
        /// <param name="connection">Object representing connected WAMP client</param>
        protected virtual void OnConnected(IWampConnection connection)
        {
            var session = InitializeWampSession(connection);
            var welcomeMessage = new WelcomeMessage(session.SessionId, WampConstants.ProtocolVersion, WampConstants.ServerIdentifier);
            var json = MessageProvider.SerializeMessage(welcomeMessage);

            session.Connection.Send(json);
        }
Esempio n. 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WampSession"/> class.
 /// </summary>
 /// <param name="connection"></param>
 public WampSession(IWampConnection connection)
 {
     Connection = connection;
     Prefixes = new PrefixMap();
     SessionId = IdGenerator.GenerateSessionId();
 }
Esempio n. 34
0
        /// <summary>
        /// Initalizes a new WAMP session.
        /// </summary>
        /// <param name="connection"><see cref="AlchemyWampConnection"/> instance</param>
        /// <returns></returns>
        protected override IWampSession InitializeWampSession(IWampConnection connection)
        {
            var alchemyConnection = connection as AlchemyWampConnection;
            if (alchemyConnection == null)
            {
                throw new ArgumentException("Provided WAMP connection was not of type AlchemyWampConnection");
            }

            var session = base.InitializeWampSession(connection);
            _endpointSessions.Add(alchemyConnection.Context.ClientAddress, session);

            return session;
        }
Esempio n. 35
0
        /// <summary>
        /// Initializes a new WAMP session for provided client connection
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        protected virtual IWampSession InitializeWampSession(IWampConnection connection)
        {
            var session = new WampSession(connection);
            Sessions.AddSession(session);

            return session;
        }