Ejemplo n.º 1
0
        public object Execute(IRequest req, bool applyFilters)
        {
            try
            {
                req.SetInProcessRequest();

                var restPath = req is IHttpRequest httpReq
                    ? RestHandler.FindMatchingRestPath(httpReq, out _)
                    : RestHandler.FindMatchingRestPath(req.Verb, req.PathInfo, out _);

                //req.SetRoute(restPath as RestPath);
                //req.OperationName = restPath.RequestType.GetOperationName();
                var requestDto = RestHandler.CreateRequestAsync(req, restPath).Result;
                //req.Dto = requestDto;

                if (applyFilters)
                {
                    //requestDto = appHost.ApplyRequestConvertersAsync(req, requestDto).Result;

                    //appHost.ApplyRequestFiltersAsync(req, req.Response, requestDto).Wait();
                    //if (req.Response.IsClosed)
                    //    return null;
                }

                var response = Execute(requestDto, req);

                return(applyFilters
                    ? ApplyResponseFiltersAsync(response, req).Result
                    : response);
            }
            finally
            {
                req.ReleaseIfInProcessRequest();
            }
        }
        public object Execute(IRequest req, bool applyFilters)
        {
            try
            {
                req.SetInProcessRequest();

                var restPath = HostContext.ServiceController.GetRestPathForRequest(req.Verb, req.PathInfo, req as IHttpRequest);

                req.OperationName = restPath.RequestType.GetOperationName();
                var task = RestHandler.CreateRequestAsync(req, restPath);
                task.Wait();
                var requestDto = task.Result;
                req.Dto = requestDto;

                if (applyFilters)
                {
                    requestDto = AppHost.ApplyRequestConverters(req, requestDto);

                    AppHost.ApplyRequestFiltersAsync(req, req.Response, requestDto).Wait();
                    if (req.Response.IsClosed)
                    {
                        return(null);
                    }
                }

                var response = Execute(requestDto, req);

                return(applyFilters
                    ? ApplyResponseFilters(response, req)
                    : response);
            }
            finally
            {
                req.ReleaseIfInProcessRequest();
            }
        }