Exemplo n.º 1
0
        public void Configuration(IAppBuilder app)
        {
            string path = app.BaseDirectory();

            var config = this.CreateConfiguration(path);

            IApplication application = ApplicationFinder.FindApplication(path, config);
            var          manager     = new ControllerExecutionManager(application, application.CreateRouter());
            var          salt        = this.GetSalt(application);
            ILogger      logger      = this.GetLogger(application);
            var          appWireUps  = application.CreateInstances(Class.GetClass <IApplicationExtender>(), true) ?? new IApplicationExtender[0];

            foreach (var wireUp in appWireUps)
            {
                if (wireUp != null)
                {
                    wireUp.Configure(app);
                }
            }

            app.Run(context =>
            {
                var content = context.ProcessRequest(manager, salt, logger);
                if (content == null)
                {
                    return(context.Response.WriteAsync("Error..."));
                }
                return(context.Response.WriteAsync(content.Content.Body));
            });
        }
Exemplo n.º 2
0
        public void ShouldLoadController()
        {
            var     router = FakeRouter.Create(typeof(MappedController).GetClass().As <IRenderingController>());
            var     a      = new ControllerExecutionManager(new Application(ApplicationMode.Prod, Environment.CurrentDirectory, null), router);
            IResult rezult = a.ExecuteController(this.CreateContext(a.Application));

            rezult.Content.BodyAsString.Should().Be("Content For @{MonkeyTail}");
        }
Exemplo n.º 3
0
        private static ControllerExecutionManager CreateManager(ApplicationMode applicationMode)
        {
            IApplication app = new Application(applicationMode, Environment.CurrentDirectory, null);
            var          m   = new ControllerExecutionManager(
                app,
                new FunctionalRouter(new[] { new FunctionalRenderingControllerSearchDelegate(MapPath) }, null));

            return(m);
        }
Exemplo n.º 4
0
        public static IResult ProcessRequest(
            this IOwinContext context,
            ControllerExecutionManager manager,
            IHttpUserLookup instance,
            string salt,
            ILogger logger)
        {
            var httpContext = new HttpContext(
                manager.Application,
                logger,
                instance,
                context,
                new HttpContextSettings {
                ApplicationSaltSettings = salt
            });

            CurrentHttpContextProvider.ThreadSpecificHttpContext = httpContext;
            httpContext.Unpack();


            logger.Log(
                string.Format("{0} {1}: {2}", context.Request.Scheme, context.Request.Method, context.Request.Path),
                LogLevels.ApplicationInfo);

            IResult result;

            try
            {
                result = manager.ExecuteController(httpContext);
            }
            catch (Exception e)
            {
                //                var st = new System.Diagnostics.StackTrace(e, true);
                //                string text = string.Concat(e.Message, st);

                logger.Log(e.ToString(), LogLevels.ApplicationError);

                if (httpContext.ApplicationInstance.Mode == ApplicationMode.Prod)
                {
                    throw;
                }

                result = new ResponseResult(httpContext.Response, new SimpleContent
                {
                    BodyContent = e.ToString(),
                    ContentType = "text/plain"
                });
            }


            httpContext.Pack();
            CurrentHttpContextProvider.ThreadSpecificHttpContext = null;
            return(result);
        }
Exemplo n.º 5
0
 public static IResult ProcessRequest(
     this IOwinContext context,
     ControllerExecutionManager manager,
     string salt,
     ILogger logger)
 {
     return(context.ProcessRequest(
                manager,
                manager.Application.CreateInstance <IHttpUserLookup>(Class.GetClass <IHttpUserLookup>(), true),
                salt,
                logger));
 }
Exemplo n.º 6
0
 protected void ClearManager()
 {
     this.manager = null;
 }