Example #1
0
        public async void Call(IWampClient client, string callId, string procUri, params TMessage[] arguments)
#endif
        {
            procUri = ResolveUri(client, procUri);

            IWampRpcMethod method = mRpcMetadataCatalog.ResolveMethodByProcUri(procUri);

            try
            {
                WampRequestContext.Current = new WampRequestContext(client);

                object[] parameters =
                    arguments.Zip(method.Parameters,
                                  (argument, type) =>
                                  mFormatter.Deserialize(type, argument))
                    .ToArray();

#if !NET45
                InnerCall(client, callId, method.InvokeAsync(client, parameters));
            }
#else
                object result = await method.InvokeAsync(client, parameters).ConfigureAwait(false);

                client.CallResult(callId, result);
            }
Example #2
0
        public object Invoke(IWampClient client, object[] parameters)
        {
            var result = mMethod(parameters);

            OnCallInvoked(client.SessionId);
            return(result);
        }
Example #3
0
        public async void Call(IWampClient client, string callId, string procUri, params TMessage[] arguments)
        {
            procUri = ResolveUri(client, procUri);

            IWampRpcMethod method = mRpcMetadataCatalog.ResolveMethodByProcUri(procUri);

            try
            {
                WampRequestContext.Current = new WampRequestContext(client);

                object[] parameters =
                    arguments.Zip(method.Parameters,
                                  (argument, type) =>
                                  mFormatter.Deserialize(type, argument))
                    .ToArray();

                object result = await method.InvokeAsync(client, parameters).ConfigureAwait(false);

                client.CallResult(callId, result);
            }
            catch (Exception ex)
            {
                HandleException(client, callId, ex);
            }
            finally
            {
                WampRequestContext.Current = null;
            }
        }
Example #4
0
 public void Unsubscribe(IWampClient client, string topicUri)
 {
     mParent.mSubscriptionRemovals.Add(new WampSubscribeRequest <TMessage>()
     {
         Client   = mClient,
         TopicUri = topicUri
     });
 }
Example #5
0
        public object Invoke(IWampClient client, object[] parameters)
        {
            object result;

            result = mMethodInvoke(GetInstance(client), parameters);

            return(result);
        }
Example #6
0
        private void RaiseSessionCreated(IWampClient client)
        {
            EventHandler <WampSessionEventArgs> sessionCreated = SessionCreated;

            if (sessionCreated != null)
            {
                sessionCreated(this, new WampSessionEventArgs(client.SessionId));
            }
        }
        public IWampServerProxy Create(IWampClient <TMessage> client, IWampConnection <TMessage> connection)
        {
            IWampOutgoingMessageHandler outgoingMessageHandler = mOutgoingHandlerBuilder.Build(client, connection);

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

            return(result);
        }
Example #8
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));
            }
        }
Example #9
0
 private static void HandleException(IWampClient client, string callId, Exception innerException)
 {
     if (innerException is WampRpcCallException callException)
     {
         HandleWampException(client, callId, callException);
     }
     else
     {
         HandleNonWampException(client, callId, innerException);
     }
 }
Example #10
0
        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);
        }
Example #11
0
        protected override void OnCloseConnection(IWampConnection <TMessage> connection)
        {
            RaiseSessionClosed(connection);

            if (mLogger.IsDebugEnabled())
            {
                IWampClient client = ClientContainer.GetClient(connection);
                mLogger.DebugFormat("Client disconnected, session id: {SessionId}", client.SessionId);
            }

            base.OnCloseConnection(connection);
        }
Example #12
0
        protected override void OnConnectionOpen(IWampConnection <TMessage> connection)
        {
            base.OnConnectionOpen(connection);

            IWampClient client = ClientContainer.GetClient(connection);

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

            client.Welcome(client.SessionId, 1, "WampSharp");

            RaiseSessionCreated(client);
        }
Example #13
0
 private void InnerPublish(IWampClient client, string topicUri, object @event, bool?excludeMe = null, string[] exclude = null, string[] eligible = null)
 {
     mParent.mPublications.Add(new WampPublishRequest <TMessage>()
     {
         Client    = mClient,
         Eligible  = eligible,
         Event     = @event,
         ExcludeMe = excludeMe,
         Exclude   = exclude,
         TopicUri  = topicUri
     });
 }
Example #14
0
        public Task <object> InvokeAsync(IWampClient client, object[] parameters)
        {
            var tcs = new TaskCompletionSource <object>();

            try
            {
                tcs.SetResult(Invoke(client, parameters));
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }
            return(tcs.Task);
        }
Example #15
0
        private Mock <IWampServer <JToken> > CallHandleOnMock(IWampClient client, string message)
        {
            Mock <IWampServer <JToken> > mock =
                new Mock <IWampServer <JToken> >();

            JToken raw = JToken.Parse(message);

            IWampIncomingMessageHandler <JToken, IWampClient> handler =
                GetHandler(mock.Object);

            handler.HandleMessage(client, mMessageFormatter.Parse(raw));

            return(mock);
        }
Example #16
0
        public void Publish(IWampClient client, string topicUri, TMessage @event)
        {
            string resolvedTopicUri = ResolveUri(client, topicUri);
            WampCraAuthenticator <TMessage> wampAuth = GetOrCreateWampAuthenticatorForClient(client);

            if (wampAuth.IsAuthenticated)
            {
                WampPubSubPermissions pubSubPerm = wampAuth.CraPermissionsMapper.LookupPubSubPermissions(resolvedTopicUri);
                if (pubSubPerm != null && pubSubPerm.pub)
                {
                    mPubSubServer.Publish(client, resolvedTopicUri, @event);
                }
            }
        }
Example #17
0
        public void Welcome()
        {
            MockConnection <MockRaw> connection = new MockConnection <MockRaw>(mFormatter);
            IWampClient client = mBuilder.Create(connection.SideAToSideB);

            client.Welcome("v59mbCGDXZ7WTyxB", 1, "Autobahn/0.5.1");

            WampMessage <MockRaw> serialized =
                mOutgoingMessageHandler.Message;

            WampMessage <MockRaw> raw =
                WampV1Messages.Welcome("v59mbCGDXZ7WTyxB", 1, "Autobahn/0.5.1");

            Assert.That(serialized, Is.EqualTo(raw).Using(mComparer));
        }
Example #18
0
        public Task<object> InvokeAsync(IWampClient client, object[] parameters)
        {
            TaskCompletionSource<object> result =
                new TaskCompletionSource<object>();

            if (Error == null)
            {
                result.SetResult(Result);
            }
            else
            {
                result.SetException(Error);
            }

            return result.Task;
        }
Example #19
0
        public void Call(IWampClient client, string callId, string procUri, params TMessage[] arguments)
        {
            string resolvedUri = ResolveUri(client, procUri);
            WampCraAuthenticator <TMessage> wampAuth = GetOrCreateWampAuthenticatorForClient(client);

            WampRpcPermissions rpcPerm = wampAuth.CraPermissionsMapper.LookupRpcPermissions(resolvedUri);

            if (rpcPerm != null && rpcPerm.call)
            {
                mRpcServer.Call(client, callId, resolvedUri, arguments);
            }
            else
            {
                client.CallError(callId, "http://api.wamp.ws/error#not_authorized", "No permissions");
            }
        }
Example #20
0
        public Task <object> InvokeAsync(IWampClient client, object[] parameters)
        {
            TaskCompletionSource <object> result =
                new TaskCompletionSource <object>();

            if (Error == null)
            {
                result.SetResult(Result);
            }
            else
            {
                result.SetException(Error);
            }

            return(result.Task);
        }
Example #21
0
        public Task <object> InvokeAsync(IWampClient client, object[] parameters)
        {
            Task <object> result = null;

            if (!typeof(Task).IsAssignableFrom(MethodInfo.ReturnType))
            {
                result = Task.Factory.StartNew(() => Invoke(client, parameters));
            }
            else
            {
                Task task = (Task)Invoke(client, parameters);

                result = task.CastTask();
            }

            return(result);
        }
        public void Publish(IWampClient client, string topicUri, TMessage @event, bool excludeMe)
        {
            string[] exclude;

            if (!excludeMe)
            {
                exclude = new string[0];
            }
            else
            {
                exclude = new[] { client.SessionId };
            }

            string resolvedUri = ResolveUri(client, topicUri);

            Publish(client, resolvedUri, @event, exclude);
        }
Example #23
0
        public IWampClient Create(IWampConnection <TMessage> connection)
        {
            WampOutgoingInterceptor <TMessage> wampOutgoingInterceptor =
                new WampOutgoingInterceptor <TMessage>
                    (mOutgoingSerializer,
                    mOutgoingHandlerBuilder.Build(connection));

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

            proxyGenerationOptions.AddMixinInstance
                (new WampClientContainerDisposable <TMessage, IWampClient>
                    (mContainer, connection));

            // This is specific to WAMPv1. In WAMPv2 I think no curies
            // will be supported.
            proxyGenerationOptions.AddMixinInstance(new WampCurieMapper());

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

            proxyGenerationOptions.AddMixinInstance(monitor);

            SessionIdPropertyInterceptor sessionIdPropertyInterceptor =
                new SessionIdPropertyInterceptor();

            IWampClient result =
                mGenerator.CreateInterfaceProxyWithoutTarget <IWampClient>
                    (proxyGenerationOptions, wampOutgoingInterceptor,
                    sessionIdPropertyInterceptor,
                    new WampCraAuthenticatorPropertyInterceptor());

            monitor.Client = result;

            object sessiondId = mContainer.GenerateClientId(result);

            sessionIdPropertyInterceptor.SessionId = (string)sessiondId;

            return(result);
        }
Example #24
0
        private WampListener<JToken> GetListener(IWampConnectionListener<JToken> listener, IWampClient wampClient)
        {
            Mock<IWampServer<JToken>> mock = new Mock<IWampServer<JToken>>();

            Mock<IWampClientBuilder<JToken, IWampClient>> clientBuilderMock =
                new Mock<IWampClientBuilder<JToken, IWampClient>>();

            clientBuilderMock.Setup
                (x => x.Create(It.IsAny<IWampConnection<JToken>>()))
                             .Returns(wampClient);

            IWampIncomingMessageHandler<JToken, IWampClient> handler = GetHandler(mock.Object);

            Mock<IWampClientBuilderFactory<JToken, IWampClient>> factory =
                new Mock<IWampClientBuilderFactory<JToken, IWampClient>>();

            factory.Setup(x => x.GetClientBuilder(It.IsAny<IWampClientContainer<JToken, IWampClient>>()))
                .Returns(clientBuilderMock.Object);

            return new WampListener<JToken>
                (listener,
                 handler,
                 new WampClientContainer<JToken, IWampClient>(factory.Object));
        }
Example #25
0
 internal WampRequestContext(IWampClient client)
 {
     mClient = client;
 }
Example #26
0
        private Mock<IWampServer<JToken>> CallHandleOnMock(IWampClient client, string message)
        {
            Mock<IWampServer<JToken>> mock =
                new Mock<IWampServer<JToken>>();

            JToken raw = JToken.Parse(message);

            IWampIncomingMessageHandler<JToken, IWampClient> handler =
                GetHandler(mock.Object);

            handler.HandleMessage(client, mMessageFormatter.Parse(raw));

            return mock;
        }
        public void Prefix(IWampClient client, string prefix, string uri)
        {
            IWampCurieMapper mapper = client as IWampCurieMapper;

            mapper.Map(prefix, uri);
        }
Example #28
0
 public object Invoke(IWampClient client, object[] parameters)
 {
     return InvokeAsync(client, parameters).Result;
 }
        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;
        }
Example #30
0
 public override object GenerateClientId(IWampClient client)
 {
     return(mMapper.Add(client));
 }
 public void Publish(IWampClient client, string topicUri, TMessage @event, string[] exclude)
 {
     Publish(client, topicUri, @event, exclude, new string[] {});
 }
 public void Publish(IWampClient client, string topicUri, TMessage @event)
 {
     Publish(client, topicUri, @event, true);
 }
        public void Publish(IWampClient client, string topicUri, TMessage @event, string[] exclude, string[] eligible)
        {
            string resolvedUri = ResolveUri(client, topicUri);

            mContainer.Publish(resolvedUri, @event, exclude, eligible);
        }
Example #34
0
 public override object GetInstance(IWampClient client)
 {
     return client.CraAuthenticator;
 }
        public void Prefix(IWampClient client, string prefix, string uri)
        {
            IWampCurieMapper mapper = client as IWampCurieMapper;

            mapper.Map(prefix, uri);
        }
Example #36
0
 /// <summary>
 /// Gets the instance used for <see cref="System.Reflection.MethodInfo.Invoke(object, object[])"></see>
 /// call.
 /// </summary>
 /// <param name="client">The <see cref="IWampClient"/> requesting this call.</param>
 /// <returns>The instance to use for invocation.</returns>
 protected virtual object GetInstance(IWampClient client)
 {
     return(mInstance);
 }
Example #37
0
 public IWampServer GetServerProxy(IWampClient <TMessage> callbackClient)
 {
     return(mServerProxyBuilder.Create(callbackClient, mConnection));
 }
Example #38
0
 internal WampRequestContext(IWampClient client)
 {
     mClient = client;
 }