当前位置: 首页>>代码示例>>C#>>正文


C# HttpActionDescriptor.ExecuteAsync方法代码示例

本文整理汇总了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;
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:35,代码来源:ApiControllerActionInvoker.cs

示例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;
            }
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:21,代码来源:ApiControllerActionInvoker.cs

示例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;
                }
            }
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:39,代码来源:DomainController.cs

示例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;
                }
            }
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:35,代码来源:DataController.cs


注:本文中的HttpActionDescriptor.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。