private static async Task<HttpResponseMessage> InvokeUsingActionResultAsync(HttpActionContext actionContext, HttpActionDescriptor actionDescriptor, CancellationToken cancellationToken) { Contract.Assert(actionContext != null); HttpControllerContext controllerContext = actionContext.ControllerContext; object result = await actionDescriptor.ExecuteAsync(controllerContext, actionContext.ActionArguments, cancellationToken); if (result == null) { throw new InvalidOperationException(SRResources.ApiControllerActionInvoker_NullHttpActionResult); } IHttpActionResult actionResult = result as IHttpActionResult; if (actionResult == null) { throw new InvalidOperationException(Error.Format( SRResources.ApiControllerActionInvoker_InvalidHttpActionResult, result.GetType().Name)); } HttpResponseMessage response = await actionResult.ExecuteAsync(cancellationToken); if (response == null) { throw new InvalidOperationException( SRResources.ResponseMessageResultConverter_NullHttpResponseMessage); } response.EnsureResponseHasRequest(actionContext.Request); return response; }
private void InvokeAction(HttpActionDescriptor action, object[] parameters, ChangeSetEntry changeSetEntry) { try { Collection <HttpParameterDescriptor> pds = action.GetParameters(); Dictionary <string, object> paramMap = new Dictionary <string, object>(pds.Count); for (int i = 0; i < pds.Count; i++) { paramMap.Add(pds[i].ParameterName, parameters[i]); } // TODO this method is not correctly observing the execution results, the catch block below is wrong. 385801 action.ExecuteAsync(ActionContext.ControllerContext, paramMap); } catch (TargetInvocationException tie) { ValidationException vex = tie.GetBaseException() as ValidationException; if (vex != null) { ValidationResultInfo error = new ValidationResultInfo(vex.Message, 0, String.Empty, vex.ValidationResult.MemberNames); if (changeSetEntry.ValidationErrors != null) { changeSetEntry.ValidationErrors = changeSetEntry.ValidationErrors.Concat(new ValidationResultInfo[] { error }).ToArray(); } else { changeSetEntry.ValidationErrors = new ValidationResultInfo[] { error }; } } else { throw; } } }
public async Task <HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) { // TODO: Validate only registered once? var request = controllerContext.Request; if (request != null) { request.RegisterForDispose(this); } HttpControllerDescriptor controllerDescriptor = controllerContext.ControllerDescriptor; ServicesContainer services = controllerDescriptor.Configuration.Services; HttpActionDescriptor httpActionDescriptor = s_actionSelector.SelectAction(controllerContext); var binder = (IActionValueBinder)services.GetService(typeof(IActionValueBinder)); var binding = binder.GetBinding(httpActionDescriptor); ActionContext = new HttpActionContext(controllerContext, httpActionDescriptor); // Parses method arguments await binding.ExecuteBindingAsync(ActionContext, cancellationToken); Initialize(controllerContext); // Invoker handlers result conversion var result = await httpActionDescriptor.ExecuteAsync(controllerContext, ActionContext.ActionArguments, cancellationToken); // Format result return(httpActionDescriptor.ResultConverter.Convert(controllerContext, result)); }
private static async Task<HttpResponseMessage> InvokeUsingResultConverterAsync(HttpActionContext actionContext, HttpActionDescriptor actionDescriptor, CancellationToken cancellationToken) { Contract.Assert(actionContext != null); HttpControllerContext controllerContext = actionContext.ControllerContext; try { object actionResult = await actionDescriptor.ExecuteAsync(controllerContext, actionContext.ActionArguments, cancellationToken); return actionDescriptor.ResultConverter.Convert(controllerContext, actionResult); } catch (HttpResponseException httpResponseException) { HttpResponseMessage response = httpResponseException.Response; response.EnsureResponseHasRequest(actionContext.Request); return response; } }
private void InvokeAction(HttpActionDescriptor action, object[] parameters, ChangeSetEntry changeSetEntry) { try { Collection <HttpParameterDescriptor> pds = action.GetParameters(); Dictionary <string, object> paramMap = new Dictionary <string, object>(pds.Count); for (int i = 0; i < pds.Count; i++) { paramMap.Add(pds[i].ParameterName, parameters[i]); } // TODO - Issue #103 // This method is not correctly observing the execution results, the catch block below is wrong. // Submit should be Task<bool>, not bool, and should model bind for the CancellationToken which would then // be propagated through to all the helper methods (one or more of which might also need to be made async, // once we start respecting the fact that the read/write actions should be allowed to be async). action.ExecuteAsync(ActionContext.ControllerContext, paramMap, CancellationToken.None); } catch (TargetInvocationException tie) { ValidationException vex = tie.GetBaseException() as ValidationException; if (vex != null) { ValidationResultInfo error = new ValidationResultInfo(vex.Message, 0, String.Empty, vex.ValidationResult.MemberNames); if (changeSetEntry.ValidationErrors != null) { changeSetEntry.ValidationErrors = changeSetEntry.ValidationErrors.Concat(new ValidationResultInfo[] { error }).ToArray(); } else { changeSetEntry.ValidationErrors = new ValidationResultInfo[] { error }; } } else { throw; } } }
public override Task <object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary <string, object> arguments) { return(_traceWriter.TraceBeginEndAsync <object>( controllerContext.Request, TraceCategories.ActionCategory, TraceLevel.Info, _innerDescriptor.GetType().Name, ExecuteMethodName, beginTrace: (tr) => { tr.Message = Error.Format(SRResources.TraceInvokingAction, FormattingUtilities.ActionInvokeToString(ActionName, arguments)); }, execute: () => { return _innerDescriptor.ExecuteAsync(controllerContext, arguments); }, endTrace: (tr, value) => { tr.Message = Error.Format(SRResources.TraceActionReturnValue, FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture)); }, errorTrace: null)); }
private void InvokeAction(HttpActionDescriptor action, object[] parameters, ChangeSetEntry changeSetEntry) { try { Collection<HttpParameterDescriptor> pds = action.GetParameters(); Dictionary<string, object> paramMap = new Dictionary<string, object>(pds.Count); for (int i = 0; i < pds.Count; i++) { paramMap.Add(pds[i].ParameterName, parameters[i]); } // TODO - Issue #103 // This method is not correctly observing the execution results, the catch block below is wrong. // Submit should be Task<bool>, not bool, and should model bind for the CancellationToken which would then // be propagated through to all the helper methods (one or more of which might also need to be made async, // once we start respecting the fact that the read/write actions should be allowed to be async). action.ExecuteAsync(ActionContext.ControllerContext, paramMap, CancellationToken.None); } catch (TargetInvocationException tie) { ValidationException vex = tie.GetBaseException() as ValidationException; if (vex != null) { ValidationResultInfo error = new ValidationResultInfo(vex.Message, 0, String.Empty, vex.ValidationResult.MemberNames); if (changeSetEntry.ValidationErrors != null) { changeSetEntry.ValidationErrors = changeSetEntry.ValidationErrors.Concat(new ValidationResultInfo[] { error }).ToArray(); } else { changeSetEntry.ValidationErrors = new ValidationResultInfo[] { error }; } } else { throw; } } }
private void InvokeAction(HttpActionDescriptor action, object[] parameters, ChangeSetEntry changeSetEntry) { try { Collection<HttpParameterDescriptor> pds = action.GetParameters(); Dictionary<string, object> paramMap = new Dictionary<string, object>(pds.Count); for (int i = 0; i < pds.Count; i++) { paramMap.Add(pds[i].ParameterName, parameters[i]); } // TODO this method is not correctly observing the execution results, the catch block below is wrong. 385801 action.ExecuteAsync(ActionContext.ControllerContext, paramMap); } catch (TargetInvocationException tie) { ValidationException vex = tie.GetBaseException() as ValidationException; if (vex != null) { ValidationResultInfo error = new ValidationResultInfo(vex.Message, 0, String.Empty, vex.ValidationResult.MemberNames); if (changeSetEntry.ValidationErrors != null) { changeSetEntry.ValidationErrors = changeSetEntry.ValidationErrors.Concat(new ValidationResultInfo[] { error }).ToArray(); } else { changeSetEntry.ValidationErrors = new ValidationResultInfo[] { error }; } } else { throw; } } }
public override Task <object> ExecuteAsync(HttpControllerContext controllerContext, IDictionary <string, object> arguments) { return(_innerDescriptor.ExecuteAsync(controllerContext, arguments)); }