Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }