本文整理汇总了C#中HttpActionDescriptor.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpActionDescriptor.ExecuteAsync方法的具体用法?C# HttpActionDescriptor.ExecuteAsync怎么用?C# HttpActionDescriptor.ExecuteAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpActionDescriptor
的用法示例。
在下文中一共展示了HttpActionDescriptor.ExecuteAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeUsingActionResultAsync
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;
}
示例2: InvokeUsingResultConverterAsync
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;
}
}
示例3: InvokeAction
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;
}
}
}
示例4: InvokeAction
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;
}
}
}