示例#1
0
 private void HandleError(IWampRawRpcOperationRouterCallback caller, Exception e)
 {
     logger.LogError(e, $"Error executing method {command.Fullname}");
     caller.Error(WampObjectFormatter.Value, new Dictionary <string, object>()
     {
         { "error", e.Message }
     }, "wamp.error.runtime_error",
                  new object[] { e.Message });
 }
        private void InnerInvoke <T>(Func <IRequestContext, IMessage, Task> serviceMethod,
                                     IWampRawRpcOperationRouterCallback caller,
                                     IWampFormatter <T> formatter,
                                     T[] arguments)
        {
            var dummyDetails = new YieldOptions();

            try
            {
                Task.Run(async() =>
                {
                    try
                    {
                        var guid = Guid.NewGuid();

                        Log.Debug($"[{guid}] RPC operation inner invoke");

                        var x = formatter.Deserialize <MessageDto>(arguments[0]);

                        var payload = x.Payload.ToString();

                        var message = new Message
                        {
                            ReplyTo = new WampTransientDestination(x.ReplyTo),
                            Payload = Encoding.UTF8.GetBytes(payload)
                        };

                        var userSession = new UserSession
                        {
                            Username = x.Username
                        };

                        var userContext = new RequestContext(message, userSession);

                        Log.Debug(
                            $"[{guid}] Calling service method from Username: {userSession.Username}, ReplyTo: {message.ReplyTo}, Payload: {payload}");

                        await serviceMethod(userContext, message);

                        Log.Debug($"[{guid}] Service method called with no exceptions");
                    }
                    catch (Exception e1)
                    {
                        Log.Error(e1, "Error processing RPC operation");
                    }
                });

                caller.Result(WampObjectFormatter.Value, dummyDetails);
            }
            catch (Exception e2)
            {
                Log.Error(e2, "Error processing RPC operation");
                caller.Error(WampObjectFormatter.Value, dummyDetails, e2.Message);
            }
        }
        public IWampCancellableInvocation Invoke <TMessage>(IWampRawRpcOperationRouterCallback caller,
                                                            IWampFormatter <TMessage> formatter,
                                                            InvocationDetails details)
        {
            var dummyDetails = new Dictionary <string, object>();

            caller.Error(WampObjectFormatter.Value,
                         dummyDetails,
                         "wamp.error.runtime_error",
                         new object[] { "Expected parameters" });

            // see: http://wampsharp.net/release-notes/wampsharp-v1.2.6.41-beta-release-notes/
            // section: "Internal/Breaking changes"
            return(null);
        }
        private void InvokePattern(IWampRawRpcOperationRouterCallback caller, InvocationDetails details,
                                   Action <InvocationDetails> action)
        {
            mResetEvent.WaitOne();

            if (Interlocked.Read(ref mClientDisconnected) == 0)
            {
                var detailsForCallee = GetInvocationDetails(details);
                action(detailsForCallee);
            }
            else
            {
                caller.Error(WampObjectFormatter.Value,
                             new Dictionary <string, string>(),
                             WampErrors.CalleeDisconnected);
            }
        }