static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += LogUnhandledException; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.Name = "Entry"; Config = args.Length > 0 ? ServerConfig.ReadFile(args[0]) : ServerConfig.ReadFile("server.json"); Environment.SetEnvironmentVariable("ServerLogFolder", Config.serverSettings.logFolder); GlobalContext.Properties["ServerName"] = Config.serverInfo.name; GlobalContext.Properties["ServerType"] = Config.serverInfo.type.ToString(); XmlConfigurator.ConfigureAndWatch(new FileInfo(Config.serverSettings.log4netConfig)); using (Resources = new Resources(Config.serverSettings.resourceFolder)) using (Database = new Database( Config.dbInfo.host, Config.dbInfo.port, Config.dbInfo.auth, Config.dbInfo.index, Resources)) { RequestHandlers.Initialize(Resources); Config.serverInfo.instanceId = Guid.NewGuid().ToString(); ISManager = new ISManager(Database, Config); ISManager.Run(); ChatManager = new ChatManager(ISManager); ISControl = new ISControl(ISManager); Console.CancelKeyPress += delegate { Shutdown.Set(); }; var port = Config.serverInfo.port; using (var server = new HttpServer($"http://{Config.serverInfo.bindAddress}:{port}/")) { foreach (var uri in RequestHandlers.Get.Keys) { server.GET(uri).Subscribe(Response); } foreach (var uri in RequestHandlers.Post.Keys) { server.POST(uri).Subscribe(Response); } Log.Info("Listening at port " + port + "..."); Shutdown.WaitOne(); } Log.Info("Terminating..."); ISManager.Dispose(); } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += LogUnhandledException; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.Name = "Entry"; Config = args.Length > 0 ? ServerConfig.ReadFile(args[0]) : ServerConfig.ReadFile("server.json"); LogManager.Configuration.Variables["logDirectory"] = Config.serverSettings.logFolder + "/server"; LogManager.Configuration.Variables["buildConfig"] = Utils.GetBuildConfiguration(); using (Resources = new Resources(Config.serverSettings.resourceFolder, false)) using (Database = new Database(Resources, Config)) { RequestHandlers.Initialize(Resources); Config.serverInfo.instanceId = Guid.NewGuid().ToString(); ISManager = new ISManager(Database, Config); ISManager.Run(); ChatManager = new ChatManager(ISManager); ISControl = new ISControl(ISManager); LegendSweeper = new LegendSweeper(Database); LegendSweeper.Run(); Console.CancelKeyPress += delegate { Shutdown.Set(); }; var port = Config.serverInfo.port; var address = Config.serverInfo.bindAddress; using (var server = new HttpServer($"http://{address}:{port}/")) { foreach (var uri in RequestHandlers.Get.Keys) { server.GET(uri).Subscribe(Response); } foreach (var uri in RequestHandlers.Post.Keys) { server.POST(uri).Subscribe(Response); } Log.Info("Listening at address {0}:{1}...", address, port); Shutdown.WaitOne(); } Log.Info("Terminating..."); ISManager.Dispose(); } }