Esempio n. 1
0
        public void RunServer(StartOptions options)
        {
            if (options == null)
            {
                return;
            }

            // get existing loader factory services
            string appLoaderFactories;

            if (!options.Settings.TryGetValue(typeof(IAppLoaderFactory).FullName, out appLoaderFactories) ||
                !string.IsNullOrEmpty(appLoaderFactories))
            {
                // use the built-in AppLoaderFactory as the default
                appLoaderFactories = typeof(AppLoaderFactory).AssemblyQualifiedName;
            }

            // prepend with our app loader factory
            options.Settings[typeof(IAppLoaderFactory).FullName] =
                typeof(AppLoaderWrapper).AssemblyQualifiedName + ";" + appLoaderFactories;

            DefaultHost host = null;

            if (options.Settings.ContainsKey("devMode"))
            {
                host = new DefaultHost(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, watchFiles: true);

                host.OnChanged += () =>
                {
                    Environment.Exit(250);
                };
            }
            else
            {
                host = new DefaultHost(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
            }

            using (_hostContainer.AddHost(host))
            {
                WriteLine("Starting with " + GetDisplayUrl(options));

                // Ensure the DefaultHost is available to the AppLoaderWrapper
                IServiceProvider container = ServicesFactory.Create(options.Settings, services =>
                {
                    services.Add(typeof(ITraceOutputFactory), () => new NoopTraceOutputFactory());
                    services.Add(typeof(DefaultHost), () => host);
                });

                IHostingStarter starter = container.GetService <IHostingStarter>();
                using (starter.Start(options))
                {
                    WriteLine("Started successfully");

                    WriteLine("Press Enter to exit");
                    Console.ReadLine();

                    WriteLine("Terminating.");
                }
            }
        }
Esempio n. 2
0
        public void NamedStarterCanBeResolved()
        {
            Func <Type, object> container         = CreateContainer();
            var             hostingStarterFactory = (IHostingStarterFactory)container(typeof(IHostingStarterFactory));
            IHostingStarter hostingStarter        = hostingStarterFactory.Create("Microsoft.Owin.Hosting.Tests");

            hostingStarter.ShouldBeTypeOf <TestHostingStarter>();
        }
Esempio n. 3
0
        /// <summary>
        /// Determines the which IHostingStarter instance to use via the IHostingSterterFactory.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public virtual IDisposable Start(StartOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            string boot;

            options.Settings.TryGetValue("boot", out boot);

            IHostingStarter hostingStarter = _hostingStarterFactory.Create(boot);

            return(hostingStarter.Start(options));
        }
Esempio n. 4
0
        public void Run(
            string rootDirectoryPath,
            string binPath,
            string currentDomainBin,
            int?port)
        {
            System.Console.WriteLine("Starting web server in '{0}'...", binPath);

            var currentDomain = this.CreateAppDomain(
                binPath,
                currentDomainBin);

            this.SetupAppDomain(currentDomain, rootDirectoryPath);

            IServiceProvider services = ServicesFactory.Create();

            IHostingStarter service = services.GetService <IHostingStarter>();

            var startOptions = new StartOptions
            {
                Port          = port.GetValueOrDefault(58080),
                ServerFactory = "Microsoft.Owin.Host.HttpListener",
                AppStartup    = typeof(Base2art.Soufflot.Http.Owin.Startup).FullName
            };

            try
            {
                this.item = service.Start(startOptions);
                Console.WriteLine("Started web server on port '{0}'...", startOptions.Port);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to start application");

                var targetInvocationException = e as TargetInvocationException;
                if (targetInvocationException != null && e.InnerException != null)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine();
                    e = e.InnerException;
                }

                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }