コード例 #1
0
        /// <summary>
        /// Finds the endpoint and executes the request onto it.
        /// Handles errors and disposes of the endpoint when completed.
        /// </summary>
        public async Task InvokeAsync(IHttpRequestReader requestReader, IHttpRequestResponder responder, IRequestContext context)
        {
            var response = new Response(requestReader.ResourcePath);
            var builder  = new ResponseBuilder(response, _services.Modifiers);

            var reader = new RequestReader(requestReader, _services.NameSwitcher, _services.QueryCreator);
            var writer = new ResponseWriter(responder, response, _services.NameSwitcher);

            try
            {
                var           navigator = new EndpointNavigator(context, _startResourceFactory, _services);
                IRestEndpoint endpoint  = navigator.GetEndpointFromPath(requestReader.ResourcePath);
                IExecutor     executor  = _services.ExecutorFactory.GetExecutor(endpoint);

                await executor.ExecuteAsync(reader, builder);

                await writer.WriteAsync();
            }
            catch (Exception ex)
            {
                var errorInfo = new ExceptionErrorInfo(ex);
                builder.AddError(errorInfo);

                await writer.WriteAsync();
            }
            finally
            {
                context.Dispose();
            }
        }
コード例 #2
0
        /// <summary>
        /// Initialize the classes that can only be determined once we have a requested passed to us by the web server.
        /// </summary>
        /// <param name="context"></param>
        private void Initialize(HttpContextBase context)
        {
            if (_webServerType == WebServerType.NotSet)
            {
                _webServerType = WebServerDetector.DetectWebServerType(context);
            }

            if (_httpResponseHeaderHelper == null)
            {
                _httpResponseHeaderHelper = new HttpResponseHeaderHelper(_webServerType);
            }

            if (_httpRequestResponder == null)
            {
                _httpRequestResponder = new HttpRequestResponder(_httpRequestHeaderHelper, _httpResponseHeaderHelper);
            }
        }
コード例 #3
0
 public ResponseWriter(IHttpRequestResponder responder, Response response, INamingConventionSwitcher nameSwitcher)
 {
     _responder    = responder;
     _response     = response;
     _nameSwitcher = nameSwitcher;
 }
コード例 #4
0
        /// <summary>
        /// Initialize the classes that can only be determined once we have a requested passed to us by the web server.
        /// </summary>
        /// <param name="context"></param>
        private void Initialize(HttpContextBase context)
        {
            if (_webServerType == WebServerType.NotSet)
            {
                _webServerType = WebServerDetector.DetectWebServerType(context);
            }

            if (_httpResponseHeaderHelper == null)
            {
                _httpResponseHeaderHelper = new HttpResponseHeaderHelper(_webServerType);
            }

            if (_httpRequestResponder == null)
            {
                _httpRequestResponder = new HttpRequestResponder(_httpRequestHeaderHelper, _httpResponseHeaderHelper);
            }
        }