/// <summary> /// Returns a list of arguments in order to call the <c>command</c> /// </summary> /// <param name="query">A JSON-object whose properties are the parameters of the command to execute</param> /// <param name="command">The command being executed</param> /// <param name="serializer">A <see cref="PcaJsonSerializer"/> which is used to convert the JSON to values according to metadata/versioning</param> /// <returns>An array of <c>object</c> containing the command's arguments</returns> private object[] GetArgsFromJObject(HttpContext context, JObject query, Metadata.Command command, PcaJsonSerializer serializer) { Func <string, int, JToken> tokenMapper = (name, index) => query[name]; return(serializer.DeserializeArgumentList(tokenMapper, command.Parameters, null, parMeta => { if (parMeta.ParameterType.Type == typeof(HttpContext)) { return context; } else { throw new ServiceException(HttpStatusCode.InternalServerError, $"Unsupported platform specific parameter: {parMeta.Name}"); } })); }
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); }