internal static async Task InitBots() { if (Bot.Bots.Count != 0) { return; } // Before attempting to connect, initialize our configuration await Bot.InitializeSteamConfiguration(Program.GlobalConfig.SteamProtocols, Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider).ConfigureAwait(false); HashSet <string> botNames; try { botNames = Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.ConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).ToHashSet(); } catch (Exception e) { ArchiLogger.LogGenericException(e); return; } if (botNames.Count == 0) { ArchiLogger.LogGenericWarning(Strings.ErrorNoBotsDefined); return; } if (botNames.Count > MaximumRecommendedBotsCount) { ArchiLogger.LogGenericWarning(string.Format(Strings.WarningExcessiveBotsCount, MaximumRecommendedBotsCount)); await Task.Delay(10000).ConfigureAwait(false); } await Utilities.InParallel(botNames.OrderBy(botName => botName).Select(Bot.RegisterBot)).ConfigureAwait(false); }
internal static async Task InitBots() { if (Bot.Bots.Count != 0) { return; } // Before attempting to connect, initialize our configuration await Bot.InitializeSteamConfiguration(Program.GlobalConfig.SteamProtocols, Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider).ConfigureAwait(false); foreach (string botName in Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*.json").Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).OrderBy(botName => botName)) { Bot.RegisterBot(botName); } if (Bot.Bots.Count == 0) { ArchiLogger.LogGenericWarning(Strings.ErrorNoBotsDefined); } }
internal static async Task InitBots() { if (Bot.Bots.Count != 0) { return; } // Before attempting to connect, initialize our configuration await Bot.InitializeSteamConfiguration(Program.GlobalConfig.SteamProtocols, Program.GlobalDatabase.CellID, Program.GlobalDatabase.ServerListProvider).ConfigureAwait(false); try { IEnumerable <Task> tasks = Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.ConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).OrderBy(botName => botName).Select(Bot.RegisterBot); switch (Program.GlobalConfig.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: foreach (Task task in tasks) { await task.ConfigureAwait(false); } break; default: await Task.WhenAll(tasks).ConfigureAwait(false); break; } } catch (Exception e) { ArchiLogger.LogGenericException(e); return; } if (Bot.Bots.Count == 0) { ArchiLogger.LogGenericWarning(Strings.ErrorNoBotsDefined); } }