Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScrambleServerGenerator"/> class.
 /// </summary>
 public ScrambleServerGenerator(
     IHttpClientFactory httpClientFactory,
     IHttpResponseHandler httpResponseHandler)
 {
     _httpClientFactory   = httpClientFactory;
     _httpResponseHandler = httpResponseHandler;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IRegisterRepository"/> class.
 /// </summary>
 public RegisterServerRepository(
     IHttpClientFactory httpClientFactory,
     IHttpResponseHandler httpResponseHandler)
 {
     _httpClientFactory   = httpClientFactory;
     _httpResponseHandler = httpResponseHandler;
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="handler"></param>
        public void SetHandler <T>(IHttpResponseHandler handler) where T : Link, new()
        {
            var t   = new T();
            var reg = _LinkRegistry[t.Relation];

            reg.ResponseHandler = handler;
        }
Esempio n. 4
0
 public RoomServerService(
     IHttpClientFactory httpClientFactory,
     IHttpResponseHandler httpResponseHandler)
 {
     _httpClientFactory   = httpClientFactory;
     _httpResponseHandler = httpResponseHandler;
     _subject             = new Subject <RoomNotification>();
 }
Esempio n. 5
0
        private IHttpResponseHandler GetHttpResponseHandler(HttpFunctionDefinition httpFunctionDefinition)
        {
            IHttpResponseHandler httpResponseHandler = httpFunctionDefinition.HasHttpResponseHandler
                ? (IHttpResponseHandler)ServiceProvider.GetRequiredService(httpFunctionDefinition.HttpResponseHandlerType)
                : new DefaultHttpResponseHandler();

            return(httpResponseHandler);
        }
 public ResponderMiddleware(RequestDelegate nextStep, IHttpStatusCodeHandler httpStatusCodeHandler,
                            IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
 {
     _nextStep              = nextStep;
     _httpContextAccessor   = httpContextAccessor;
     _httpStatusCodeHandler = httpStatusCodeHandler;
     _httpResponseHandler   = new HttpResponseHandler();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SessionsServerRepository"/> class.
 /// </summary>
 public SessionsServerRepository(
     IHttpClientFactory httpClientFactory,
     IUserClient userClient,
     IHttpResponseHandler httpResponseHandler)
 {
     _httpClientFactory   = httpClientFactory;
     _userClient          = userClient;
     _httpResponseHandler = httpResponseHandler;
 }
Esempio n. 8
0
        /// <summary>
        /// Runs a command through the IActionResult ASP.Net pathways and returns a HTTP response.
        /// This is useful for testing end to end HTTP triggered functions without having to actually host the
        /// function app.
        /// A method only needs specifying in the function supports multiple methods.
        /// </summary>
        public async Task <HttpResponse> ExecuteHttpAsync <TResult>(ICommand <TResult> command, HttpMethod method = null)
        {
            HttpFunctionDefinition httpFunctionDefinition = FindHttpFunctionDefinition(command);
            ActionContext          actionContext          = _aspNetRuntime.PrepareToExecuteHttp(command, httpFunctionDefinition, method);
            IHttpResponseHandler   httpResponseHandler    = GetHttpResponseHandler(httpFunctionDefinition);
            HttpDispatcher         httpDispatcher         = new HttpDispatcher(Dispatcher, ServiceProvider);

            IActionResult actionResult = await httpDispatcher.DispatchAndConvertToActionResult(command, httpResponseHandler, httpFunctionDefinition);

            return(await _aspNetRuntime.CreateHttpResponse(actionContext, actionResult));
        }
Esempio n. 9
0
 public HttpApiEndpoint(
     HttpUrlDescriptor url,
     HttpMethod method,
     Dictionary<string, IHttpArgumentHandler> argumentHandlers,
     IHttpResponseHandler responseHandler,
     IEnumerable<HttpHeader> headers)
 {
     Url = url;
     Method = method;
     ArgumentHandlers = argumentHandlers;
     ResponseHandler = responseHandler;
     Headers = headers.ToList();
 }
Esempio n. 10
0
 public HttpApiEndpoint(
     MethodInfo method,
     HttpUrlDescriptor url,
     HttpMethod httpMethod,
     Dictionary <string, IHttpArgumentHandler> argumentHandlers,
     IHttpResponseHandler responseHandler,
     IEnumerable <HttpHeader> headers, bool isAsync = true)
 {
     Method           = method;
     Url              = url;
     HttpMethod       = httpMethod;
     ArgumentHandlers = argumentHandlers;
     ResponseHandler  = responseHandler;
     Headers          = headers.ToList();
 }
Esempio n. 11
0
        public async Task <IActionResult> DispatchAndConvertToActionResult <TResult>(
            ICommand <TResult> command,
            IHttpResponseHandler httpResponseHandler,
            HttpFunctionDefinition httpFunctionDefinition)
        {
            IActionResult actionResult = null;

            try
            {
                TResult result = await _dispatcher.DispatchAsync(command);

                // TODO: Handle validation here
                Task <IActionResult> responseHandlerTask = httpResponseHandler.CreateResponse(command, result);
                if (responseHandlerTask != null)
                {
                    actionResult = await responseHandlerTask;
                }

                if (actionResult == null)
                {
                    actionResult = CreateResponse(200, result, httpFunctionDefinition);
                }
            }
            catch (ValidationException vex)
            {
                actionResult = await CreateValidationResponse(command, vex.ValidationResult, httpFunctionDefinition, httpResponseHandler);
            }
            catch (Exception ex)
            {
                Task exceptionResponseHandlerTask = httpResponseHandler.CreateResponseFromException(command, ex);
                if (exceptionResponseHandlerTask != null)
                {
                    actionResult = await httpResponseHandler.CreateResponseFromException(command, ex);
                }

                if (actionResult == null)
                {
                    actionResult = CreateResponse(500, "Unexpected error", httpFunctionDefinition);
                }
            }

            return(actionResult);
        }
Esempio n. 12
0
 public HttpResponseParser(IHttpResponseHandler handler)
 {
     _handler = handler;
     _parseBuffer = new byte[64*1024];
 }
Esempio n. 13
0
 public IHttpRequest OnBadRequest <T>(Action <T, HttpStatusCode, string> action)
 {
     BadRequestResponseHandler = new BadRequestHttpResponseHandler <T>(action);
     return(this);
 }
Esempio n. 14
0
 public HttpResponseParser(IHttpResponseHandler handler)
 {
     this.handler     = handler;
     this.parseBuffer = new byte[64 * 1024];
 }
Esempio n. 15
0
 public IHttpRequest Always <T>(Action <T, HttpStatusCode> action)
 {
     UnconditionalResponseHandler = new UnconditionalHttpResponseHandler <T>(action);
     return(this);
 }
Esempio n. 16
0
 public HttpResponseParser(IHttpResponseHandler handler)
 {
     this.handler = handler;
     this.parseBuffer = new byte[64 * 1024];
 }
Esempio n. 17
0
 public HttpResponseParser(IHttpResponseHandler handler)
 {
     _handler     = handler;
     _parseBuffer = new byte[64 * 1024];
 }
Esempio n. 18
0
        private async Task <IActionResult> CreateValidationResponse(ICommand command, ValidationResult validationResult, HttpFunctionDefinition httpFunctionDefinition, IHttpResponseHandler responseHandler)
        {
            IActionResult        actionResult = null;
            Task <IActionResult> validationResponseHandlerTask = responseHandler.CreateValidationFailureResponse(command, validationResult);

            if (validationResponseHandlerTask != null)
            {
                actionResult = await validationResponseHandlerTask;
            }

            return(actionResult ?? (CreateResponse(400, validationResult, httpFunctionDefinition)));
        }
Esempio n. 19
0
 public IHttpRequest OnOK <T>(Action <T> action)
 {
     OkResponseHandler = new OkHttpResponseHandler <T>(action);
     return(this);
 }