private static void StopServers() { Console.WriteLine("Stopping servers..."); _dispatchServer.Stop(); _notificationServer.Stop(); _switchboardServer.Stop(); Console.WriteLine("Save database? Y / D %filename% / N"); String line = Console.ReadLine(); if (line.ToUpperInvariant() == "Y") { Console.WriteLine("Saving Database..."); User.SaveDatabase(_dbPath); } else if (line.StartsWith("D", StringComparison.OrdinalIgnoreCase)) { String path = Path.Combine(Path.GetDirectoryName(_dbPath), line.Substring(2).Trim()); Console.WriteLine("Saving Database to \"{0}\"...", path); User.SaveDatabase(path); } else { Console.WriteLine("Not saving changes"); } Console.WriteLine("Terminating"); }
public void FixtureTeardown() { WebApiServer.Stop(); NotificationServer.Stop(); TestSignalRServer.Stop(); HttpClient.Dispose(); }
private static int Main(string[] args) { var p = new OptionSet { { "u|url=", $"The {{url}} to bind to, including port. (Default: {_url})", v => _url = v }, { "w", $"Flag to indicate that logs should not be written to disk (Default: {_writeToDisk})", v => _writeToDisk = v == null }, { "t|threads=", $"The max number of {{threads}} the server will run on. (Default: {_threads})", v => _threads = int.Parse(v) }, { "v|verbosity=", $"The {{verbosity}} of the server. (Default: {Logger.VerbosityThreshhold})", v => Logger.VerbosityThreshhold = int.Parse(v) }, { "c|clienttest", $"Run a stress test on the server, posing as a client.", v => _clientTest = v != null }, { "h|?|help", "Show this dialog", v => _help = v != null } }; List <string> unknownCommands; try { unknownCommands = p.Parse(args); } catch (Exception e) { Logger.Log($"Unable to parse commands:{e.Message}"); return(1); } if (unknownCommands.Count > 0) { Console.WriteLine($"Unknown commands: {string.Join(", ", unknownCommands)}"); } if (_help) { p.WriteOptionDescriptions(Console.Out); return(0); } if (_clientTest) { RunClientTest(_threads); return(0); } var server = new NotificationServer(_url, _threads, _writeToDisk); #region commands var commands = new Dictionary <string, Action>(); commands.Add("list", () => Console.WriteLine($"Active Notifications: " + $"{Environment.NewLine}{NotificationInfoLoader.ToString()}")); commands.Add("restart", server.Restart); commands.Add("reload", NotificationInfoLoader.Reload); commands.Add("exit", () => { _running = false; }); #if DEBUG commands.Add("help", () => Console.WriteLine($"Commands: {string.Join(", ", commands.Keys)}")); commands.Add("crashall", () => server.CrashServer()); commands.Add("testlog", () => Logger.Log("Test log")); commands.Add("testlogwarning", () => Logger.LogWarning("Test warning log")); commands.Add("testlogerror", () => Logger.LogError("Test error log")); #endif #endregion server.Start(); Thread.Sleep(100); //touchey touchey (Forces static ctor to trigger) NotificationInfoLoader.ToString(); Console.WriteLine(Environment.NewLine + "Type 'help' for a list of commands"); while (_running) { Console.Write('>'); var command = Console.ReadLine()?.ToLower(); if (command == null) { continue; } Console.WriteLine(); if (!commands.TryGetValue(command, out var action)) { action = () => Console.WriteLine("Invalid command. Type 'help' for a list of commands."); } action(); Thread.Sleep(300); } server.Stop(); Logger.Log("Server shut down successfully."); return(0); }