public void Init() { // Configure Log4Net XmlConfigurator.Configure(new FileInfo(Constants.LOG_CONFIG_PATH)); // Set CWD so that native libs are found. Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); // Load INI stuff var configSource = new ArgvConfigSource(new string[] { }); // Configure nIni aliases and locale Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true); configSource.Alias.AddAlias("On", true); configSource.Alias.AddAlias("Off", false); configSource.Alias.AddAlias("True", true); configSource.Alias.AddAlias("False", false); configSource.Alias.AddAlias("Yes", true); configSource.Alias.AddAlias("No", false); // Read in the ini file configSource.Merge(new IniConfigSource(Constants.INI_PATH)); // Prep cache folder try { Directory.Delete(Constants.TEST_CACHE_PATH, true); } catch (DirectoryNotFoundException) { // Skip. } Directory.CreateDirectory(Constants.TEST_CACHE_PATH); // Start booting server var pidFileManager = new PIDFileManager(Constants.PID_FILE_PATH); var chattelConfigRead = new ChattelConfiguration(Constants.TEST_CACHE_PATH); LocalStorage = new AssetStorageSimpleFolderTree(chattelConfigRead); var chattelReader = new ChattelReader(chattelConfigRead, LocalStorage); _service = new F_Stop( Constants.SERVICE_URI, Constants.SERVICE_ADMIN_TOKEN, TimeSpan.FromSeconds(Constants.SERVICE_NC_LIFETIME_SECONDS), chattelReader, new List <sbyte> { 0, 12, /*18, 19,*/ 49 } ); _service.Start(); }
public static int Main(string[] args) { // First line, hook the appdomain to the crash reporter AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; var createdNew = true; var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "70a9f94f-59e8-4073-93ab-00aaacc26111", out createdNew); if (!createdNew) { LOG.Error("Server process already started, please stop that server first."); return(2); } // Add the arguments supplied when running the application to the configuration var configSource = new ArgvConfigSource(args); // Commandline switches configSource.AddSwitch("Startup", "inifile"); configSource.AddSwitch("Startup", "logconfig"); configSource.AddSwitch("Startup", "pidfile"); var startupConfig = configSource.Configs["Startup"]; var pidFileManager = new PIDFileManager(startupConfig.GetString("pidfile", string.Empty)); // Configure Log4Net var logConfigFile = startupConfig.GetString("logconfig", string.Empty); if (string.IsNullOrEmpty(logConfigFile)) { XmlConfigurator.Configure(); LogBootMessage(); LOG.Info("Configured log4net using ./WHIP_LRU.exe.config as the default."); } else { XmlConfigurator.Configure(new FileInfo(logConfigFile)); LogBootMessage(); LOG.Info($"Configured log4net using \"{logConfigFile}\" as configuration file."); } // Configure nIni aliases and locale Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true); configSource.Alias.AddAlias("On", true); configSource.Alias.AddAlias("Off", false); configSource.Alias.AddAlias("True", true); configSource.Alias.AddAlias("False", false); configSource.Alias.AddAlias("Yes", true); configSource.Alias.AddAlias("No", false); var isRunning = true; F_Stop f_stop = null; // Handlers for signals. Console.CancelKeyPress += (sender, cargs) => { LOG.Debug("CTRL-C pressed, terminating."); isRunning = false; f_stop?.Stop(); cargs.Cancel = true; waitHandle.Set(); }; // TODO: incorporate UNIX signals for reloading etc, once the crossplatform kinks have been worked out in WHIP-LRU. while (isRunning) { // Read in the ini file ReadConfigurationFromINI(configSource); var configRead = configSource.Configs["AssetsRead"]; var serversRead = GetServers(configSource, configRead, _assetServersByName); var chattelConfigRead = GetConfig(configRead, serversRead); var chattelReader = new ChattelReader(chattelConfigRead); var serverConfig = configSource.Configs["Server"]; var address = serverConfig?.GetString("Address", F_Stop.DEFAULT_ADDRESS) ?? F_Stop.DEFAULT_ADDRESS; if (address == "*") { address = "localhost"; } var port = (uint?)serverConfig?.GetInt("Port", (int)F_Stop.DEFAULT_PORT) ?? F_Stop.DEFAULT_PORT; var useSSL = serverConfig?.GetBoolean("UseSSL", F_Stop.DEFAULT_USE_SSL) ?? F_Stop.DEFAULT_USE_SSL; var adminToken = serverConfig?.GetString("AdminToken", F_Stop.DEFAULT_ADMIN_TOKEN) ?? F_Stop.DEFAULT_ADMIN_TOKEN; var validAssetTypes = serverConfig?.GetString("AllowedAssetTypes", F_Stop.DEFAULT_VALID_ASSET_TYPES) ?? F_Stop.DEFAULT_VALID_ASSET_TYPES; var cacheConfig = configSource.Configs["Cache"]; var negativeCacheItemLifetime = TimeSpan.FromSeconds((uint?)cacheConfig?.GetInt("NegativeCacheItemLifetimeSeconds", (int)F_Stop.DEFAULT_NC_LIFETIME_SECONDS) ?? F_Stop.DEFAULT_NC_LIFETIME_SECONDS); var protocol = useSSL ? "https" : "http"; var uri = new Uri($"{protocol}://{address}:{port}"); f_stop = new F_Stop( uri, adminToken, negativeCacheItemLifetime, chattelReader, validAssetTypes.Split(',').Select(type => sbyte.Parse(type)) ); f_stop.Start(); waitHandle.WaitOne(); } return(0); }