/// <summary>
        /// Processes the HTTP request for controllers.
        /// </summary>
        /// <param name="resolver">THE DI container resolver</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public RequestHandlingResult ProcessRequest(IDIResolver resolver, HttpContext context)
        {
            var result = _controllersProcessor.ProcessControllers(resolver, context);

            switch (result)
            {
            case ControllersProcessorResult.Ok:
                return(_pageProcessor.ProcessPage(resolver, context));

            case ControllersProcessorResult.Http401:
                context.Response.StatusCode = 401;
                _redirector.SetLoginReturnUrlFromCurrentUri();
                break;

            case ControllersProcessorResult.Http403:
                context.Response.StatusCode = 403;
                break;

            case ControllersProcessorResult.Http404:
                if (ApplicationBuilderExtensions.TerminalMiddleware)
                {
                    context.Response.StatusCode = 404;
                }
                else
                {
                    return(RequestHandlingResult.UnhandledResult());
                }
                break;
            }

            return(RequestHandlingResult.HandledResult());
        }
        public static RequestHandlingResult Invoke(HttpContext context)
        {
            using var scope = BootstrapperFactory.ContainerProvider.BeginLifetimeScope();

            try
            {
                return(scope.StartMeasurements()
                       .Trace(context, OnTrace)
                       .SetupProviders(context)
                       .ProcessRequest(context));
            }
            catch (Exception e)
            {
                try
                {
                    context.Response.StatusCode = 500;

                    ProcessOnException(e);
                }
                catch (Exception exception)
                {
                    return(RequestHandlingResult.HandledResult(
                               context.Response.WriteAsync(ExceptionInfoPageGenerator.Generate(exception,
                                                                                               scope.Resolver.Resolve <ISimplifyWebSettings>().HideExceptionDetails))));
                }

                return
                    (RequestHandlingResult.HandledResult(context.Response.WriteAsync(
                                                             ExceptionInfoPageGenerator.Generate(e,
                                                                                                 scope.Resolver.Resolve <ISimplifyWebSettings>().HideExceptionDetails))));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes (build web-page and send to client, process current page state) the current web-page
        /// </summary>
        /// <param name="resolver">The DI container resolver.</param>
        /// <param name="context">The context.</param>
        public RequestHandlingResult ProcessPage(IDIResolver resolver, HttpContext context)
        {
            context.Response.ContentType = "text/html";
            _redirector.PreviousPageUrl  = context.Request.GetEncodedUrl();

            return(RequestHandlingResult.HandledResult(_responseWriter.WriteAsync(_pageBuilder.Build(resolver),
                                                                                  context.Response)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes the HTTP request for static files.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public RequestHandlingResult ProcessRequest(HttpContext context)
        {
            var relativeFilePath     = _fileHandler.GetRelativeFilePath(context.Request);
            var lastModificationTime = _fileHandler.GetFileLastModificationTime(relativeFilePath);
            var response             = _responseFactory.Create(context.Response);

            return(_fileHandler.IsFileCanBeUsedFromCache(context.Request.Headers["Cache-Control"],
                                                         _fileHandler.GetIfModifiedSinceTime(context.Request.Headers), lastModificationTime)
                                ? RequestHandlingResult.HandledResult(response.SendNotModified(lastModificationTime, relativeFilePath))
                                : RequestHandlingResult.HandledResult(response.SendNew(_fileHandler.GetFileData(relativeFilePath), lastModificationTime, relativeFilePath)));
        }
        public void ProcessRequest_Ok_PageBuiltWithOutput()
        {
            // Assign
            var handledResult = RequestHandlingResult.HandledResult();

            _controllersProcessor.Setup(x => x.ProcessControllers(It.IsAny <IDIContainerProvider>(), It.IsAny <HttpContext>())).Returns(ControllersProcessorResult.Ok);
            _pageProcessor.Setup(x => x.ProcessPage(It.IsAny <IDIContainerProvider>(), It.IsAny <HttpContext>())).Returns(handledResult);

            // Act
            var result = _requestHandler.ProcessRequest(null, _context.Object);

            // Assert
            Assert.AreEqual(handledResult, result);
            _pageProcessor.Verify(x => x.ProcessPage(It.IsAny <IDIContainerProvider>(), It.IsAny <HttpContext>()));
        }
        /// <summary>
        /// Process an individual request.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static RequestHandlingResult Invoke(HttpContext context)
        {
            using (var scope = DIContainer.Current.BeginLifetimeScope())
            {
                try
                {
                    // Starts execution measurement
                    scope.Resolver.Resolve <IStopwatchProvider>().StartMeasurement();

                    // Tracing

                    var settings = scope.Resolver.Resolve <ISimplifyWebSettings>();

                    if (settings.ConsoleTracing)
                    {
                        TraceToConsole(context);
                    }

                    OnTrace?.Invoke(context);

                    // Setup providers

                    var webContextProvider      = scope.Resolver.Resolve <IWebContextProvider>();
                    var languageManagerProvider = scope.Resolver.Resolve <ILanguageManagerProvider>();
                    var templateFactory         = scope.Resolver.Resolve <ITemplateFactory>();
                    var fileReader  = scope.Resolver.Resolve <IFileReader>();
                    var stringTable = scope.Resolver.Resolve <IStringTable>();

                    webContextProvider.Setup(context);
                    languageManagerProvider.Setup(context);
                    templateFactory.Setup();
                    fileReader.Setup();
                    stringTable.Setup();

                    // Run request process pipeline

                    var requestHandler = scope.Resolver.Resolve <IRequestHandler>();
                    return(requestHandler.ProcessRequest(scope.Resolver, context));
                }
                catch (Exception e)
                {
                    try
                    {
                        context.Response.StatusCode = 500;

                        ProcessOnException(e);
                    }
                    catch (Exception exception)
                    {
                        return(RequestHandlingResult.HandledResult(
                                   context.Response.WriteAsync(ExceptionInfoPageGenerator.Generate(exception,
                                                                                                   scope.Resolver.Resolve <ISimplifyWebSettings>().HideExceptionDetails))));
                    }

                    return
                        (RequestHandlingResult.HandledResult(context.Response.WriteAsync(
                                                                 ExceptionInfoPageGenerator.Generate(e,
                                                                                                     scope.Resolver.Resolve <ISimplifyWebSettings>().HideExceptionDetails))));
                }
            }
        }