Ejemplo n.º 1
0
        public System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> GetDynamicData(HttpControllerContext controllerContext, string entitySetName, System.Threading.CancellationToken cancellationToken)
        {
            var dynamicController = new Controllers.DynamicController
            {
                ControllerContext = controllerContext
            };

            return(dynamicController.GetDynamicData(entitySetName, cancellationToken));
        }
Ejemplo n.º 2
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);
        }