Beispiel #1
0
        public InMemoryHost(FubuRuntime runtime)
        {
            _runtime = runtime;

            _func = FubuOwinHost.ToAppFunc(runtime);

            _services = _runtime.Factory.Get <IServiceLocator>();
        }
Beispiel #2
0
        private void startServer(OwinSettings settings, string physicalPath, int port)
        {
            var parameters = new StartOptions {
                Port = port
            };

            parameters.Urls.Add("http://*:" + port); //for netsh http add urlacl


            if (physicalPath != null)
            {
                FubuMvcPackageFacility.PhysicalRootPath = physicalPath;
            }

            var context = new StartContext(parameters)
            {
                App = FubuOwinHost.ToAppFunc(_runtime, settings),
            };

            settings.EnvironmentData.ToDictionary().Each(pair => context.EnvironmentData.Add(pair));


            settings.EnvironmentData[OwinConstants.AppMode] = FubuMode.Mode().ToLower();
            context.EnvironmentData.AddRange(settings.EnvironmentData.ToDictionary());

            var engine = new HostingEngine(new AppBuilderFactory(), new TraceOutputFactory(),
                                           new AppLoader(new IAppLoaderFactory[0]),
                                           new ServerFactoryLoader(new ServerFactoryActivator(new ServiceProvider())));

            try
            {
                _server = engine.Start(context);
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException != null && e.InnerException.Message.Contains("Access is denied"))
                {
                    throw new KatanaRightsException(e.InnerException);
                }

                throw;
            }
        }
Beispiel #3
0
        public FubuRuntime(FubuRegistry registry)
        {
            _registry = registry;

            _appFunc = new Lazy <AppFunc>(() => FubuOwinHost.ToAppFunc(this));

            RouteTable.Routes.Clear();

            _diagnostics = new ActivationDiagnostics();

            _perfTimer = _diagnostics.Timer;
            _perfTimer.Start("FubuRuntime Bootstrapping");


            var packageAssemblies = AssemblyFinder.FindModuleAssemblies(_diagnostics);

            var applicationPath = registry.RootPath ?? DefaultApplicationPath();

            _files = new FubuApplicationFiles(applicationPath);

            _perfTimer.Record("Applying IFubuRegistryExtension's",
                              () => applyFubuExtensionsFromPackages(_diagnostics, packageAssemblies, registry));

            _container = registry.ToContainer();

            var graph = _perfTimer.Record("Building the BehaviorGraph",
                                          () => BehaviorGraphBuilder.Build(registry, _perfTimer, packageAssemblies, _diagnostics, _files));

            _perfTimer.Record("Registering services into the IoC Container",
                              () => registry.Config.RegisterServices(Mode, _container, graph));

            _factory = new StructureMapServiceFactory(_container);

            var routeTask = _perfTimer.RecordTask("Building Routes", () =>
            {
                var routes = buildRoutes(_factory, graph);
                routes.Each(r => RouteTable.Routes.Add(r));

                return(routes);
            });

            var library = HtmlConventionCollator.BuildHtmlConventions(graph);

            _container.Configure(_ =>
            {
                _.Policies.OnMissingFamily <SettingPolicy>();

                _.For <IFubuApplicationFiles>().Use(_files);
                _.For <IServiceLocator>().Use <StructureMapServiceLocator>();
                _.For <FubuRuntime>().Use(this);
                _.For <IServiceFactory>().Use(_factory);
                _.For <HtmlConventionLibrary>().Use(library);
            });


            Activate();

            _routes = routeTask.Result();



            if (registry.Host != null)
            {
                startHosting();
            }

            _perfTimer.Stop();
            Restarted = DateTime.Now;

            _diagnostics.AssertNoFailures();
        }