public static List<IRarePokemonRepository> CreateRepositories(GlobalSettings globalSettings)
 {
     var rarePokemonRepositories = new List<IRarePokemonRepository>();
     if (GlobalSettings.UsePokeSnipers)
     {
         rarePokemonRepositories.Add(new PokeSniperRarePokemonRepository());
     }
     if (GlobalSettings.UseTrackemon)
     {
         rarePokemonRepositories.Add(new TrackemonRarePokemonRepository());
     }
     if (GlobalSettings.UsePokezz)
     {
         rarePokemonRepositories.Add(new PokezzRarePokemonRepository());
     }
     if (GlobalSettings.UseRareSpawns)
     {
         rarePokemonRepositories.Add(new RareSpawnsRarePokemonRepository());
     }
     if (GlobalSettings.UsePokewatchers)
     {
         rarePokemonRepositories.Add(new PokewatchersRarePokemonRepository());
     }
     if (GlobalSettings.UsePokemonGoIVClub)
     {
         rarePokemonRepositories.Add(new PokemonGoIVClubRarePokemonRepository());
     }
     return rarePokemonRepositories;
 }
Пример #2
0
        public static GlobalSettings Load()
        {
            GlobalSettings settings;

            if (File.Exists(ConfigFile)) {
                SettingsToSave set;
                //if the file exists, load the Settings
                var input = File.ReadAllText(ConfigFile);

                var jsonSettings = new JsonSerializerSettings();
                jsonSettings.Converters.Add(new StringEnumConverter {CamelCaseText = true});
                jsonSettings.ObjectCreationHandling = ObjectCreationHandling.Replace;
                jsonSettings.DefaultValueHandling = DefaultValueHandling.Populate;
                set = JsonConvert.DeserializeObject<SettingsToSave>(input, jsonSettings);
                settings = new GlobalSettings();
                Port = set.Port;
                //UseTrackemon = set.UseTrackemon;
                UseRareSpawns = set.UseRareSpawns;
                UsePokeSnipers = set.UsePokeSnipers;
                UsePokewatchers = set.UsePokewatchers;
                UsePokezz = set.UsePokezz;
                UsePokemonGoIVClub = set.UsePokemonGoIVClub;
                VerifyOnSkiplagged = set.VerifyOnSkiplagged;
                RemoveAfter = set.RemoveAfter;
                ShowLimit = Math.Max(set.ShowLimit, 1);
                PokeSnipers2Exe = set.PokeSnipers2Exe;
                UseFilter = set.UseFilter;
            }
            else
            {
                settings = new GlobalSettings();
            }
            PokekomsToFeedFilter = LoadFilter();
            var firstRun = !File.Exists(ConfigFile);
            Save();

            if (firstRun
                || Port == 0
                )
            {
                Log.Error($"Invalid configuration detected. \nPlease edit {ConfigFile} and try again");
                return null;
            }
            return settings;
        }
Пример #3
0
        private void WebSourcesManager(GlobalSettings settings)
        {
            var rarePokemonRepositories = RarePokemonRepositoryFactory.CreateRepositories(settings);

            var repoTasks = rarePokemonRepositories.Select(rarePokemonRepository => StartPollRarePokemonRepository(settings, rarePokemonRepository)).Cast<Task>().ToList();

            var discordTask = TryStartDiscordReader();

            while (true)
            {
                if (!_clientWriter.Listener.Server.IsBound)
                {
                    Log.Info("Server has lost connection. Restarting...");
                    _clientWriter.StartNet(GlobalSettings.Port);
                }
                try
                {
                    // Manage repo tasks
                    for (var i = 0; i < repoTasks.Count; ++i)
                    {
                        var t = repoTasks[i];
                        if (t.Status != TaskStatus.Running && t.Status != TaskStatus.WaitingToRun && t.Status != TaskStatus.WaitingForActivation)
                        {
                            // Replace broken tasks with a new one
                            repoTasks[i].Dispose();
                            repoTasks[i] = StartPollRarePokemonRepository(settings, rarePokemonRepositories[i]);
                        }
                    }

                    // Manage Discord task
                    if (discordTask.Status != TaskStatus.Running && discordTask.Status != TaskStatus.WaitingToRun && discordTask.Status != TaskStatus.WaitingForActivation)
                    {
                        // Replace broken task with a new one
                        discordTask.Dispose();
                        discordTask = TryStartDiscordReader();
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"Exception in thread manager: {e}");
                    throw;
                }
                Thread.Sleep(20 * 1000);
            }
        }
Пример #4
0
 private async Task<Task> StartPollRarePokemonRepository(GlobalSettings globalSettings, IRarePokemonRepository rarePokemonRepository)
 {
     return await Task.Factory.StartNew(async () => await RareRepoThread(rarePokemonRepository), TaskCreationOptions.LongRunning);
 }