Esempio n. 1
0
        public int Main(string[] args)
        {
            string application;

            string[] arguments;

            if (args.Length >= 1)
            {
                application = args[0];
                arguments   = args.Skip(1).ToArray();
            }
            else
            {
                application = Directory.GetCurrentDirectory();
                arguments   = args;
            }

            try
            {
                var host = new DefaultHost(application);
                using (_container.AddHost(host))
                {
                    return(ExecuteMain(host, arguments));
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(String.Join(Environment.NewLine, GetExceptions(ex)));
                return(-2);
            }
        }
Esempio n. 2
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.");
                }
            }
        }