internal static void InitHistoryLogger() { if (LogManager.Configuration == null) { return; } HistoryTarget historyTarget = LogManager.Configuration.AllTargets.OfType <HistoryTarget>().FirstOrDefault(); if ((historyTarget == null) && !IsUsingCustomConfiguration) { historyTarget = new HistoryTarget("History") { Layout = GeneralLayout, MaxCount = 20 }; LogManager.Configuration.AddTarget(historyTarget); LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, historyTarget)); LogManager.ReconfigExistingLoggers(); } ArchiKestrel.OnNewHistoryTarget(historyTarget); }
internal static async Task Init() { WebBrowser = new WebBrowser(ArchiLogger, GlobalConfig.WebProxy, true); await UpdateAndRestart().ConfigureAwait(false); if (!Core.InitPlugins()) { await Task.Delay(10000).ConfigureAwait(false); } await Core.OnASFInitModules(GlobalConfig.AdditionalProperties).ConfigureAwait(false); StringComparer botsComparer = await Core.GetBotsComparer().ConfigureAwait(false); InitBotsComparer(botsComparer); if (GlobalConfig.IPC) { await ArchiKestrel.Start().ConfigureAwait(false); } await RegisterBots(botsComparer).ConfigureAwait(false); InitEvents(); }
private static async Task <bool> InitShutdownSequence() { if (ShutdownSequenceInitialized) { return(false); } ShutdownSequenceInitialized = true; // Sockets created by IPC might still be running for a short while after complete app shutdown // Ensure that IPC is stopped before we finalize shutdown sequence await ArchiKestrel.Stop().ConfigureAwait(false); if (Bot.Bots.Count > 0) { // Stop() function can block due to SK2 sockets, don't forget a maximum delay await Task.WhenAny(Utilities.InParallel(Bot.Bots.Values.Select(bot => Task.Run(() => bot.Stop(true)))), Task.Delay(Bot.Bots.Count *WebBrowser.MaxTries * 1000)).ConfigureAwait(false); // Extra second for Steam requests to go through await Task.Delay(1000).ConfigureAwait(false); } LogManager.Flush(); return(true); }
internal static async Task Init() { if (!PluginsCore.InitPlugins()) { await Task.Delay(10000).ConfigureAwait(false); } WebBrowser = new WebBrowser(ArchiLogger, GlobalConfig.WebProxy, true); await UpdateAndRestart().ConfigureAwait(false); await PluginsCore.OnASFInitModules(GlobalConfig.AdditionalProperties).ConfigureAwait(false); StringComparer botsComparer = await PluginsCore.GetBotsComparer().ConfigureAwait(false); InitBotsComparer(botsComparer); if (!GlobalConfig.Headless && !Console.IsInputRedirected) { Logging.StartInteractiveConsole(); } if (GlobalConfig.IPC) { await ArchiKestrel.Start().ConfigureAwait(false); } await RegisterBots().ConfigureAwait(false); InitEvents(); }
private static async Task InitGlobalDatabaseAndServices() { string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName); if (!File.Exists(globalDatabaseFile)) { ASF.ArchiLogger.LogGenericInfo(Strings.Welcome); await Task.Delay(10 * 1000).ConfigureAwait(false); ASF.ArchiLogger.LogGenericWarning(Strings.WarningPrivacyPolicy); await Task.Delay(5 * 1000).ConfigureAwait(false); } GlobalDatabase = await GlobalDatabase.Load(globalDatabaseFile).ConfigureAwait(false); if (GlobalDatabase == null) { ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile)); await Task.Delay(5 * 1000).ConfigureAwait(false); await Exit(1).ConfigureAwait(false); return; } // If debugging is on, we prepare debug directory prior to running if (Debugging.IsUserDebugging) { ASF.ArchiLogger.LogGenericDebug(SharedInfo.GlobalDatabaseFileName + ": " + JsonConvert.SerializeObject(GlobalDatabase, Formatting.Indented)); Logging.EnableTraceLogging(); if (Directory.Exists(SharedInfo.DebugDirectory)) { try { Directory.Delete(SharedInfo.DebugDirectory, true); await Task.Delay(1000).ConfigureAwait(false); // Dirty workaround giving Windows some time to sync } catch (IOException e) { ASF.ArchiLogger.LogGenericException(e); } } Directory.CreateDirectory(SharedInfo.DebugDirectory); DebugLog.AddListener(new Debugging.DebugListener()); DebugLog.Enabled = true; } WebBrowser.Init(); WebBrowser = new WebBrowser(ASF.ArchiLogger, GlobalConfig.WebProxy, true); if (GlobalConfig.IPC) { await ArchiKestrel.Start().ConfigureAwait(false); } }
private static void OnConfigurationChanged(object?sender, LoggingConfigurationChangedEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } InitConsoleLoggers(); if (IsWaitingForUserInput) { OnUserInputStart(); } HistoryTarget?historyTarget = LogManager.Configuration.AllTargets.OfType <HistoryTarget>().FirstOrDefault(); ArchiKestrel.OnNewHistoryTarget(historyTarget); }
private static void OnConfigurationChanged(object sender, LoggingConfigurationChangedEventArgs e) { if ((sender == null) || (e == null)) { ASF.ArchiLogger.LogNullError(nameof(sender) + " || " + nameof(e)); return; } InitConsoleLoggers(); if (IsWaitingForUserInput) { OnUserInputStart(); } HistoryTarget historyTarget = LogManager.Configuration.AllTargets.OfType <HistoryTarget>().FirstOrDefault(); ArchiKestrel.OnNewHistoryTarget(historyTarget); }
private static async Task <bool> InitShutdownSequence() { if (ShutdownSequenceInitialized) { return(false); } ShutdownSequenceInitialized = true; // Sockets created by IPC might still be running for a short while after complete app shutdown // Ensure that IPC is stopped before we finalize shutdown sequence await ArchiKestrel.Stop().ConfigureAwait(false); if (Bot.Bots.Count > 0) { IEnumerable <Task> tasks = Bot.Bots.Values.Select(bot => Task.Run(() => bot.Stop(true))); switch (GlobalConfig.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: foreach (Task task in tasks) { await Task.WhenAny(task, Task.Delay(WebBrowser.MaxTries * 1000)).ConfigureAwait(false); } break; default: await Task.WhenAny(Task.WhenAll(tasks), Task.Delay(Bot.Bots.Count *WebBrowser.MaxTries * 1000)).ConfigureAwait(false); break; } // Extra second for Steam requests to go through await Task.Delay(1000).ConfigureAwait(false); } LogManager.Flush(); return(true); }
internal static async Task Init() { WebBrowser = new WebBrowser(ArchiLogger, Program.GlobalConfig.WebProxy, true); if (Program.GlobalConfig.IPC) { await ArchiKestrel.Start().ConfigureAwait(false); } await UpdateAndRestart().ConfigureAwait(false); if (!Core.InitPlugins()) { await Task.Delay(10000).ConfigureAwait(false); } await Core.OnASFInitModules(Program.GlobalConfig.AdditionalProperties).ConfigureAwait(false); await InitBots().ConfigureAwait(false); InitEvents(); }
private static async Task OnChangedConfigFile(string name) { if (string.IsNullOrEmpty(name)) { ArchiLogger.LogNullError(nameof(name)); return; } if (!name.Equals(SharedInfo.IPCConfigFile) || (GlobalConfig?.IPC != true)) { return; } if (!await CanHandleWriteEvent(name).ConfigureAwait(false)) { return; } ArchiLogger.LogGenericInfo(Strings.IPCConfigChanged); await ArchiKestrel.Stop().ConfigureAwait(false); await ArchiKestrel.Start().ConfigureAwait(false); }