public string GetRootPath() { #if DEBUG DirectoryInfo debugDir = new DirectoryInfo(PathHandler.GetAssemblyPath()); return(debugDir.Parent?.Parent?.FullName); #else return(PathHandler.GetAssemblyPath()); #endif }
private static void RunServer() { var uri = new Uri("http://localhost:" + ConfigHandler.WebServerPort + "/"); var config = new HostConfiguration { UrlReservations = { CreateAutomatically = true }, AllowChunkedEncoding = false }; var host = new NancyHost(config, uri); bool isRestart = false; try { host.Start(); Console.Write("Fate / Reborn Stats Page"); Console.Write("\n" + "\t\"" + uri + "\"\n" + $"To quit, input {CMD_TERMINATE}\n" + $"To set maintenance mode, input {CMD_MAINTENANCE}\n" + $"To reload configuration, input {CMD_RELOAD_CONFIG}\n" + $"To restart server, input {CMD_RESTART}\n"); bool terminateServer = false; while (!terminateServer) { Console.Write("> "); string cmd = Console.ReadLine(); switch (cmd) { case CMD_TERMINATE: terminateServer = true; break; case CMD_MAINTENANCE: MainBootstrapper.IsMaintenanceMode = !MainBootstrapper.IsMaintenanceMode; _logger.Info(MainBootstrapper.IsMaintenanceMode ? "Starting maintenance mode" : "Resuming web service"); break; case CMD_RELOAD_CONFIG: LoadConfig(); break; case CMD_RESTART: isRestart = true; terminateServer = true; break; } } } catch (Exception e) { _logger.Error(e); Console.ReadKey(true); } finally { host.Stop(); } if (isRestart) { Console.WriteLine("Restarting Server"); // Starts a new instance of the program itself System.Diagnostics.Process.Start(PathHandler.GetAssemblyPath()); // Closes the current process Environment.Exit(0); } else { Console.WriteLine("Goodbye"); } }