Ejemplo n.º 1
0
        public Task <object> Execute(HttpListenerHost appHost, object requestDto, IRequest req)
        {
            req.Dto = requestDto;
            var requestType = requestDto.GetType();

            req.OperationName = requestType.Name;

            var serviceType = appHost.GetServiceTypeByRequest(requestType);

            var service = appHost.CreateInstance(serviceType);

            //var service = typeFactory.CreateInstance(serviceType);

            var serviceRequiresContext = service as IRequiresRequest;

            if (serviceRequiresContext != null)
            {
                serviceRequiresContext.Request = req;
            }

            if (req.Dto == null) // Don't override existing batched DTO[]
            {
                req.Dto = requestDto;
            }

            //Executes the service and returns the result
            return(ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()));
        }
Ejemplo n.º 2
0
        protected static Task <object> CreateContentTypeRequest(HttpListenerHost host, IRequest httpReq, Type requestType, string contentType)
        {
            if (!string.IsNullOrEmpty(contentType) && httpReq.ContentLength > 0)
            {
                var deserializer = RequestHelper.GetRequestReader(host, contentType);
                return(deserializer?.Invoke(requestType, httpReq.InputStream));
            }

            return(Task.FromResult(host.CreateInstance(requestType)));
        }
Ejemplo n.º 3
0
 protected static object CreateContentTypeRequest(HttpListenerHost host, IRequest httpReq, Type requestType, string contentType)
 {
     if (!string.IsNullOrEmpty(contentType) && httpReq.ContentLength > 0)
     {
         var deserializer = RequestHelper.GetRequestReader(host, contentType);
         if (deserializer != null)
         {
             return(deserializer(requestType, httpReq.InputStream));
         }
     }
     return(host.CreateInstance(requestType));
 }
Ejemplo n.º 4
0
        public Task <object> Execute(HttpListenerHost httpHost, object requestDto, IRequest req)
        {
            var requestType = requestDto.GetType();

            req.OperationName = requestType.Name;

            var serviceType = httpHost.GetServiceTypeByRequest(requestType);

            var service = httpHost.CreateInstance(serviceType);

            if (service is IRequiresRequest serviceRequiresContext)
            {
                serviceRequiresContext.Request = req;
            }

            // Executes the service and returns the result
            return(ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()));
        }
Ejemplo n.º 5
0
        public static async Task <object> CreateRequest(HttpListenerHost host, IRequest httpReq, RestPath restPath, ILogger logger)
        {
            var requestType = restPath.RequestType;

            if (RequireqRequestStream(requestType))
            {
                // Used by IRequiresRequestStream
                var requestParams = await GetRequestParams(httpReq).ConfigureAwait(false);

                var request = ServiceHandler.CreateRequest(httpReq, restPath, requestParams, host.CreateInstance(requestType));

                var rawReq = (IRequiresRequestStream)request;
                rawReq.RequestStream = httpReq.InputStream;
                return(rawReq);
            }
            else
            {
                var requestParams = await GetFlattenedRequestParams(httpReq).ConfigureAwait(false);

                var requestDto = await CreateContentTypeRequest(host, httpReq, restPath.RequestType, httpReq.ContentType).ConfigureAwait(false);

                return(CreateRequest(httpReq, restPath, requestParams, requestDto));
            }
        }
Ejemplo n.º 6
0
        private static IRequiresRequestStream CreateRequiresRequestStreamRequest(HttpListenerHost host, IRequest req, Type requestType)
        {
            var restPath = GetRoute(req);
            var request  = ServiceHandler.CreateRequest(req, restPath, GetRequestParams(req), host.CreateInstance(requestType));

            var rawReq = (IRequiresRequestStream)request;

            rawReq.RequestStream = req.InputStream;
            return(rawReq);
        }
Ejemplo n.º 7
0
        public static object CreateRequest(HttpListenerHost host, IRequest httpReq, RestPath restPath, ILogger logger)
        {
            var requestType = restPath.RequestType;

            if (RequireqRequestStream(requestType))
            {
                // Used by IRequiresRequestStream
                var request = ServiceHandler.CreateRequest(httpReq, restPath, GetRequestParams(httpReq), host.CreateInstance(requestType));

                var rawReq = (IRequiresRequestStream)request;
                rawReq.RequestStream = httpReq.InputStream;
                return(rawReq);
            }

            var requestParams = GetFlattenedRequestParams(httpReq);

            return(CreateRequest(host, httpReq, restPath, requestParams));
        }