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); }
public object Invoke(IWampClient client, object[] parameters) { var result = mMethod(parameters); OnCallInvoked(client.SessionId); return(result); }
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; } }
public void Unsubscribe(IWampClient client, string topicUri) { mParent.mSubscriptionRemovals.Add(new WampSubscribeRequest <TMessage>() { Client = mClient, TopicUri = topicUri }); }
public object Invoke(IWampClient client, object[] parameters) { object result; result = mMethodInvoke(GetInstance(client), parameters); return(result); }
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); }
private void RaiseSessionClosed(IWampConnection <TMessage> connection) { EventHandler <WampSessionEventArgs> sessionClosed = SessionClosed; if (sessionClosed != null) { IWampClient client = ClientContainer.GetClient(connection); sessionClosed(this, new WampSessionEventArgs(client.SessionId)); } }
private static void HandleException(IWampClient client, string callId, Exception innerException) { if (innerException is WampRpcCallException callException) { HandleWampException(client, callId, callException); } else { HandleNonWampException(client, callId, innerException); } }
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); }
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); }
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); }
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 }); }
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); }
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 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); } } }
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)); }
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; }
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"); } }
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); }
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); }
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); }
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)); }
internal WampRequestContext(IWampClient client) { mClient = client; }
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); }
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; }
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); }
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); }
/// <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); }
public IWampServer GetServerProxy(IWampClient <TMessage> callbackClient) { return(mServerProxyBuilder.Create(callbackClient, mConnection)); }
internal WampRequestContext(IWampClient client) { mClient = client; }