Task <HttpResponseMessage> IHttpActionInvoker.InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException("actionContext");
            }

            return(_traceWriter.TraceBeginEndAsync <HttpResponseMessage>(
                       actionContext.ControllerContext.Request,
                       TraceCategories.ActionCategory,
                       TraceLevel.Info,
                       _innerInvoker.GetType().Name,
                       InvokeActionAsyncMethodName,

                       beginTrace: (tr) =>
            {
                tr.Message = Error.Format(
                    SRResources.TraceActionInvokeMessage,
                    FormattingUtilities.ActionInvokeToString(actionContext));
            },

                       execute: () => (Task <HttpResponseMessage>)_innerInvoker.InvokeActionAsync(actionContext, cancellationToken),

                       endTrace: (tr, result) =>
            {
                HttpResponseMessage response = result;
                if (response != null)
                {
                    tr.Status = response.StatusCode;
                }
            },

                       errorTrace: null));
        }
示例#2
0
 public Task <HttpResponseMessage> InvokeActionAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
 {
     if (actionContext.Request.IsInspectRequest())
     {
         var inspectData = new InspectData(actionContext.Request);
         inspectData.RealHttpStatus = HttpStatusCode.OK;
         return(Task.FromResult <HttpResponseMessage>(actionContext.Request.CreateResponse <InspectData>(
                                                          HttpStatusCode.OK, inspectData)));
     }
     else
     {
         return(_innerInvoker.InvokeActionAsync(actionContext, cancellationToken));
     }
 }
示例#3
0
        /// <summary>
        /// Executes asynchronously the HTTP operation.
        /// </summary>
        /// <param name="actionContext">The execution context.</param>
        /// <param name="cancellationToken">The cancellation token assigned for the HTTP operation.</param>
        /// <returnsThe newly started task.></returns>
        public System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> InvokeActionAsync(HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken)
        {
            System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> result = null;

            try
            {
                if (_innerInvoker != null)
                {
                    var controllerContext = actionContext.ControllerContext;
                    if (controllerContext.Controller is RestierController)
                    {
                        var       request   = controllerContext.Request;
                        ODataPath odataPath = request.ODataProperties().Path;
                        var       routeData = controllerContext.RouteData;

                        if (routeData != null)
                        {
                            var actionMethodName = routeData.Values["action"] as string;
                            if (actionMethodName == cPostActionName)
                            {
                                if (odataPath.Segments.Last() is UnboundActionPathSegment actionPathSegment)
                                {
                                    IEdmModel           model   = request.ODataProperties().Model;
                                    Stream              stream  = request.Content.ReadAsStreamAsync().Result;
                                    ODataMessageWrapper message = new ODataMessageWrapper(stream);
                                    message.SetHeader("Content-Type", request.Content.Headers.ContentType.MediaType);
                                    ODataMessageReader       reader      = new ODataMessageReader(message as IODataRequestMessage, new ODataMessageReaderSettings(), model);
                                    ODataDeserializerContext readContext = new ODataDeserializerContext {
                                        Path = odataPath, Model = model
                                    };
                                    ODataActionParameters payload = ReadParams(reader, actionPathSegment.Action.Operation, readContext);

                                    var dynamicController = new Controllers.DynamicController
                                    {
                                        ControllerContext = controllerContext
                                    };
                                    result = dynamicController.CallAction(actionPathSegment.ActionName, payload, cancellationToken);
                                }
                            }

                            if (odataPath != null && odataPath.Segments.Count == 3 &&
                                odataPath.Segments[0].ToString() == Controllers.MediaDataController.cFilesEntityName &&
                                odataPath.Segments.Last() is ValuePathSegment)
                            {
                                var mediaDataController = new Controllers.MediaDataController
                                {
                                    ControllerContext = controllerContext
                                };
                                var keyValuePathSegment = odataPath.Segments.First(x => x is KeyValuePathSegment);
                                int key = int.Parse(((KeyValuePathSegment)keyValuePathSegment).Value);

                                if (actionMethodName.Equals(System.Net.WebRequestMethods.Http.Get, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    result = mediaDataController.GetMediaResource(key);
                                }
                                else if (actionMethodName.Equals(cPostActionName, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    result = mediaDataController.PostMediaResource(key);
                                }
                            }
                        }
                    }

                    if (result == null)
                    {
                        result = _innerInvoker.InvokeActionAsync(actionContext, cancellationToken);
                    }
                }
            }
            catch (Exception exception)
            {
                DynamicLogger.Instance.WriteLoggerLogError("InvokeActionAsync", exception);
                throw;
            }

            return(result);
        }
示例#4
0
 public Task <System.Net.Http.HttpResponseMessage> InvokeActionAsync(HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken)
 {
     return(httpActionInvoker.InvokeActionAsync(actionContext, cancellationToken));
 }