static void ReadKeysUntilAbort(string url) { System.Console.TreatControlCAsInput = true; Console.WriteLine("Press enter to launch a browser or ctrl-c to shutdown."); do { ConsoleKeyInfo key = Console.ReadKey(/*intercept*/ true); if (key.Key == ConsoleKey.Enter) { BrowserLauncher.Launch(url); } else if ((key.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control && key.Key == ConsoleKey.C) { return; } // Otherwise keep going. } while (true); }
static void Main(string[] args) { var arguments = new Arguments { ApplicationPath = ConfigurationManager.AppSettings["GitPriseWebPath"] }; var showHelp = false; var p = new OptionSet() { { "a|app|applicationPath:", "path to GitPrise web application", v => arguments.ApplicationPath = v }, { "rn|repositoryName:", "repository name in local browsing mode", v => arguments.RepositoryName = v }, { "rp|repositoryPath:", "repository path in local browsing mode", v => arguments.RepositoryPath = v }, { "p|port:", "server port", (int v) => arguments.Port = v }, { "nb|noBrowser", "doesn't auto start the browser", v => arguments.StartBrowser = (v == null) }, { "h|?|help", "shows help", v => showHelp = (v != null) }, }; try { p.Parse(args); } catch (Exception ex) { Console.WriteLine(string.Format( "Error parsing command line arguments:{0}{1}", Environment.NewLine, ex)); return; } if (showHelp || ArgumentsAreInvalid(arguments)) { ShowHelp(p); return; } var launcher = new BrowserLauncher(arguments.Port, arguments.RepositoryName, arguments.RepositoryPath); var result = GitPriseWebServer.CheckPortAvailability(arguments.Port); if (result == AvailabilityResult.InUseByGitPrise) { launcher.Launch(); return; } if (result == AvailabilityResult.Unknown) { Console.WriteLine("Port is in use by an unknown application - please use a different port or shutdown the application that's using the port."); return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(arguments, launcher)); }
static int Main(string[] args) { Configuration configuration = null; try { configuration = Configuration.Load(); } catch { Console.WriteLine("The configuration.json file could not be read. Please ensure that it is present in\n\n {1}\n\nand has the following schema:\n\n{0}\n", Configuration.Schema, Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); Console.Write("Press any key to exit..."); Console.ReadKey(); return(-1); } string remoteString; if (args.Length < 1 || args[0] == "/ask") { // A debugger string wasn't specified. Prompt for a debug string instead. Console.WriteLine("You can run the following command to create a remote debugging server in WinDbg: '.server npipe:pipe=jsdbg'"); Console.Write("Please specify a debug remote string (e.g. npipe:Pipe=foo,Server=bar):"); remoteString = Console.ReadLine().Trim(); if (remoteString.StartsWith("-remote ")) { remoteString = remoteString.Substring("-remote ".Length).Trim(); } if (remoteString.Length == 0) { return(-1); } } else { remoteString = args[0]; } DebuggerRunner runner; try { Console.Write("Connecting to a debug session at {0}...", remoteString); runner = new DebuggerRunner(remoteString); Console.WriteLine("Connected."); } catch (Exception ex) { Console.WriteLine("Failed: {0}", ex.Message); Console.Write("Press any key to exit..."); Console.ReadKey(); return(-1); } PersistentStore persistentStore = new PersistentStore(); using (WebServer webServer = new WebServer(runner.Debugger, persistentStore, configuration.ExtensionRoot)) { webServer.LoadExtension("default"); SynchronizationContext previousContext = SynchronizationContext.Current; try { SingleThreadSynchronizationContext syncContext = new SingleThreadSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(syncContext); // Run the debugger. If the debugger ends, kill the web server. runner.Run().ContinueWith((Task result) => { webServer.Abort(); }); // The web server ending kills the debugger and completes our SynchronizationContext which allows us to exit. webServer.Listen().ContinueWith(async(Task result) => { await runner.Shutdown(); await Task.Delay(500); syncContext.Complete(); }); JsDbg.Remoting.RemotingServer.RegisterNewInstance(remoteString, () => { BrowserLauncher.Launch(webServer.Url); }); BrowserLauncher.Launch(webServer.Url); // Pressing ctrl-c kills the web server. Task.Run(() => ReadKeysUntilAbort(webServer.Url)).ContinueWith((Task result) => { Console.WriteLine("Shutting down..."); webServer.Abort(); }); // Process requests until the web server is taken down. syncContext.RunOnCurrentThread(); } catch (Exception ex) { Console.WriteLine("Shutting down due to exception: {0}", ex.Message); } finally { SynchronizationContext.SetSynchronizationContext(previousContext); } } return(0); }