Example #1
0
 private static void StartInBrowser(Options options)
 {
     try
     {
         if (Environment.UserInteractive && options.StartInBrowser)
         {
             Process.Start(String.Format("http://localhost:{0}", options.Port));
         }
     }
     catch (Exception ex)
     {
         log.DebugException("Unable to start in browser", ex);
     }
 }
Example #2
0
        private static void Main(string[] args)
        {
            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                exitLatch.Set();
            };

            try
            {
                var options = new Options();
                if (Parser.Default.ParseArguments(args, options))
                {
                    log.Info("Port:", options.Port);
                    log.Info("Webroot:", options.WebRoot);
                    log.Info("Runtime:", options.RuntimeVersion);
                }
                else
                {
                    Environment.Exit(1);
                }

                ConfigSettings settings;
                var configGenerator = new ConfigGenerator(options.WebRoot);
                switch (options.RuntimeVersion)
                {
                    case "2":
                    case "2.0":
                        settings = configGenerator.Create(
                            options.Port,
                            Constants.FrameworkPaths.TwoDotZeroWebConfig,
                            Constants.RuntimeVersion.VersionTwoDotZero,
                            Constants.PipelineMode.Integrated, options.UserName, options.Password);
                        break;
                    default:
                        settings = configGenerator.Create(
                            options.Port,
                            Constants.FrameworkPaths.FourDotZeroWebConfig,
                            Constants.RuntimeVersion.VersionFourDotZero,
                            Constants.PipelineMode.Integrated, options.UserName, options.Password);
                        break;
                }

                log.Info("starting web server instance...");
                using (var webServer = new WebServer(settings))
                {
                    webServer.Start();
                    Console.WriteLine("Server Started.... press CTRL + C to stop");

                    StartInBrowser(options);

                    exitLatch.WaitOne();
                    Console.WriteLine("Server shutting down, please wait...");
                    webServer.Stop();
                }

                if (File.Exists("iishost_stop"))
                {
                    File.Delete("iishost_stop");
                }
            }
            catch (Exception ex)
            {
                log.ErrorException("Error on startup.", ex);
                Environment.Exit(2);
            }
        }