private static bool StartServers() { Console.Write("Loading User Database..."); //String path = @"C:\Documents and Settings\David\My Documents\Visual Studio Projects\W3b.MsnpServer\Data\PinkEgoBox.sqlite"; //String path = @"D:\Users\David\My Documents\Visual Studio Projects\Solutions\W3b.MsnpServer\Data\PinkEgoBox.sqlite"; _dbPath = UtilityMethods.FindFile(new DirectoryInfo(Environment.CurrentDirectory), "PinkEgoBox.sqlite", 5); if (_dbPath == null) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to locate database file"); Console.ResetColor(); return(false); } User.LoadDatabase(_dbPath); Console.WriteLine("Done"); Console.WriteLine("Starting Servers..."); _dispatchServer = DispatchServer.Instance; _dispatchServer.Start(); Console.ForegroundColor = _dispatchServer.ConsoleColor; Console.WriteLine("Dispatch Server started, listening on " + _dispatchServer.EndPoint.ToString2()); ////////////////////// _notificationServer = NotificationServer.Instance; _notificationServer.Start(); Console.ForegroundColor = _notificationServer.ConsoleColor; Console.WriteLine("Notification Server started, listening on " + _notificationServer.EndPoint.ToString2()); ////////////////////// _switchboardServer = SwitchboardServer.Instance; _switchboardServer.Start(); Console.ForegroundColor = _switchboardServer.ConsoleColor; Console.WriteLine("Switchboard Server started, listening on " + _switchboardServer.EndPoint.ToString2()); Console.ResetColor(); return(true); }
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); }