示例#1
0
        protected void CallResult(IWampRawRpcOperationRouterCallback caller, object result, IDictionary <string, object> outputs)
        {
            YieldOptions options = new YieldOptions();

            object[] resultArguments = mEmptyResult;

            if (this.HasResult)
            {
                if (this.CollectionResultTreatment == CollectionResultTreatment.Multivalued)
                {
                    resultArguments = GetFlattenResult((dynamic)result);
                }
                else
                {
                    resultArguments = new object[] { result };
                }
            }

            if (outputs != null)
            {
                caller.Result(ObjectFormatter, options, resultArguments, outputs);
            }
            else if (!this.HasResult)
            {
                caller.Result(ObjectFormatter, options);
            }
            else
            {
                caller.Result(ObjectFormatter, options, resultArguments);
            }
        }
示例#2
0
            public IWampCancellableInvocation Invoke <TMessage>(IWampRawRpcOperationRouterCallback caller, IWampFormatter <TMessage> formatter,
                                                                InvocationDetails details,
                                                                TMessage[] arguments)
            {
                TMessage number = arguments[0];
                int      n      = formatter.Deserialize <int>(number);

                bool endWithError = arguments.Length > 1 && formatter.Deserialize <bool>(arguments[1]);

                for (int i = 0; i < n; i++)
                {
                    caller.Result(WampObjectFormatter.Value,
                                  new YieldOptions {
                        Progress = true
                    },
                                  new object[] { i });
                }

                if (endWithError)
                {
                    caller.Error(WampObjectFormatter.Value,
                                 new Dictionary <string, string>(),
                                 "Something bad happened");
                }
                else
                {
                    caller.Result(WampObjectFormatter.Value,
                                  new YieldOptions(),
                                  new object[] { n });
                }

                return(null);
            }
示例#3
0
 private void HandleObservableResult <T>(IServiceScope serviceScope, IWampRawRpcOperationRouterCallback caller, IObservable <T> result, CancellationToken cancellationToken)
 {
     result.Subscribe(
         next =>
     {
         JToken token = serializer.Serialize(next, command.ReturnType);
         caller.Result(WampObjectFormatter.Value, new YieldOptions {
             Progress = true
         }, new object[] { token });
     },
         error =>
     {
         HandleError(caller, error);
     },
         (/*completed*/) =>
     {
         // The final result is empty and should not be used
         JToken token = serializer.Serialize(default(T), command.ReturnType);
         caller.Result(WampObjectFormatter.Value, new YieldOptions {
             Progress = false
         }, new object[] { token });
         serviceScope?.Dispose();
     },
         cancellationToken
         );
 }
示例#4
0
 protected void CallResult(IWampRawRpcOperationRouterCallback caller, YieldOptions options, object[] arguments, IDictionary <string, object> argumentKeywords)
 {
     if (argumentKeywords != null)
     {
         caller.Result(ObjectFormatter, options, arguments, argumentKeywords);
     }
     else if (!this.HasResult)
     {
         caller.Result(ObjectFormatter, options);
     }
     else
     {
         caller.Result(ObjectFormatter, options, arguments);
     }
 }
示例#5
0
 protected override IWampCancellableInvocation InnerInvoke <TMessage>
     (IWampRawRpcOperationRouterCallback caller, IWampFormatter <TMessage> formatter, InvocationDetails details, TMessage[] arguments, IDictionary <string, TMessage> argumentsKeywords)
 {
     mAction();
     caller.Result(formatter, new YieldOptions());
     return(null);
 }
        protected override IWampCancellableInvocation OnResult(IWampRawRpcOperationRouterCallback caller, object result, IDictionary <string, object> outputs)
        {
            var ctSource = new CancellationTokenSource();

            ((IObservable <T>)result).Subscribe(
                it => CallResult(caller, it, outputs, new YieldOptions {
                Progress = true
            }),
                ex =>
            {
                if (ex is WampException wampex)
                {
                    HandleException(caller, wampex);
                }
                else
                {
                    HandleException(caller, ex);
                }
            },
                // An observable does not emit any value when completing, so result without arguments
                () => caller.Result(ObjectFormatter, new YieldOptions()),
                ctSource.Token
                );
            return(new CancellationTokenSourceInvocation(ctSource));
        }
示例#7
0
        private static void InnerInvoke <T>(Func <IRequestContext, IMessage, Task <TResponse> > serviceMethod,
                                            IWampRawRpcOperationRouterCallback caller,
                                            IWampFormatter <T> formatter,
                                            T[] arguments)
        {
            var dummyDetails = new YieldOptions();

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

                var message = new Message
                {
                    ReplyTo = new WampTransientDestination(x.ReplyTo),
                    Payload = Encoding.UTF8.GetBytes(x.Payload.ToString()) // TODO need to stop this from deserializing
                };

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

                var userContext = new RequestContext(message, userSession);

                var response = serviceMethod(userContext, message).Result;


                caller.Result(WampObjectFormatter.Value, dummyDetails, new object[] { response });
            }
            catch (Exception e)
            {
                Log.Error(e);
                caller.Error(WampObjectFormatter.Value, dummyDetails, e.Message);
            }
        }
示例#8
0
        private void HandleSyncResult <T>(IServiceScope serviceScope, IWampRawRpcOperationRouterCallback caller, T result)
        {
            JToken token = serializer.Serialize(result, command.ReturnType);

            caller.Result(WampObjectFormatter.Value, new YieldOptions(), new object[] { token });
            serviceScope?.Dispose();
        }
示例#9
0
 public void Report(T value)
 {
     mCaller.Result(WampObjectFormatter.Value,
                    new YieldOptions {
         Progress = true
     },
                    new object[] { value });
 }
示例#10
0
 protected override void InnerInvoke <TMessage>
     (IWampRawRpcOperationRouterCallback caller,
     IWampFormatter <TMessage> formatter,
     InvocationDetails details,
     TMessage[] arguments,
     IDictionary <string, TMessage> argumentsKeywords)
 {
     mAction(this, details);
     caller.Result(formatter, new YieldOptions());
 }
        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);
            }
        }
示例#12
0
            public void Invoke <TMessage>(IWampRawRpcOperationRouterCallback caller, IWampFormatter <TMessage> formatter,
                                          InvocationDetails details,
                                          TMessage[] arguments)
            {
                TMessage number = arguments[0];
                int      n      = formatter.Deserialize <int>(number);

                for (int i = 0; i < n; i++)
                {
                    caller.Result(WampObjectFormatter.Value,
                                  new YieldOptions {
                        Progress = true
                    },
                                  new object[] { i });
                }

                caller.Result(WampObjectFormatter.Value,
                              new YieldOptions(),
                              new object[] { n });
            }
示例#13
0
 private void HandleVoidAsyncResult(IServiceScope serviceScope, IWampRawRpcOperationRouterCallback caller, Task result)
 {
     result.ContinueWith(t =>
     {
         if (t.Exception != null)
         {
             var e = t.Exception.InnerException;
             HandleError(caller, e);
         }
         else
         {
             caller.Result(WampObjectFormatter.Value, new YieldOptions(), new object[0]);
         }
         serviceScope?.Dispose();
     });
 }
示例#14
0
 private void HandleAsyncResult <T>(IServiceScope serviceScope, IWampRawRpcOperationRouterCallback caller, Task <T> result)
 {
     result.ContinueWith(t =>
     {
         if (t.Exception != null)
         {
             var e = t.Exception.InnerException;
             HandleError(caller, e);
         }
         else
         {
             JToken token = serializer.Serialize(t.Result, command.ReturnType);
             caller.Result(WampObjectFormatter.Value, new YieldOptions(), new object[] { token });
         }
         serviceScope?.Dispose();
     });
 }
示例#15
0
        // Response handlers

        private void HandleVoidSyncResult(IServiceScope serviceScope, IWampRawRpcOperationRouterCallback caller)
        {
            caller.Result(WampObjectFormatter.Value, new YieldOptions(), new object[0]);
            serviceScope?.Dispose();
        }