Пример #1
0
        public IWampCancellableInvocation Invoke <TMessage>(
            IWampRawRpcOperationRouterCallback caller, IWampFormatter <TMessage> formatter,
            InvocationDetails details, TMessage[] arguments,
            IDictionary <string, TMessage> argumentsKeywords)
        {
            try
            {
                // Create a separate scope for the duration of a single request
                // Scope will be disposed by the commandInvokerDelegate
                var scope = scopeFactory.CreateScope();

                CancellationTokenSource cancellationTokenSource = null;
                CancellationToken       cancellationToken       = default(CancellationToken);
                if (supportsCancellation)
                {
                    cancellationTokenSource = new CancellationTokenSource();
                    cancellationToken       = cancellationTokenSource.Token;
                }

                // Build the service context
                BuildServiceContext();

                // Fetch the method parameters
                Func <string, int, JToken> tokenMapper = (name, index) =>
                                                         index < arguments.Length ? arguments[index] as JToken : null;
                object[] args = serializer.DeserializeArgumentList(tokenMapper, command.Parameters, cancellationToken, null);

                // Create a service instance
                var serviceInstance = scope.ServiceProvider.GetService(command.Service.Type);

                // Invoke the command
                commandInvokerDelegate.Invoke(scope, caller, serviceInstance, args, cancellationToken);

                if (supportsCancellation)
                {
                    return(new CancellableInvocation(cancellationTokenSource));
                }
            }
            catch (Exception e)
            {
                HandleError(caller, e);
            }
            return(null);
        }