public static GlobalSettings Load()
        {
            GlobalSettings settings;
            var configFile = Path.Combine(Directory.GetCurrentDirectory(), "Config", "config.json");

            if (File.Exists(configFile))
            {
                //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;

                settings = JsonConvert.DeserializeObject<GlobalSettings>(input, jsonSettings);
            }
            else
            {
                settings = new GlobalSettings();
            }

            var firstRun = !File.Exists(configFile);
            settings.Save(configFile);

            if (firstRun
                || settings.Port == 0
                )
            {
                Log.Error($"Invalid configuration detected. \nPlease edit {configFile} and try again");
                return null;
            }

            return settings;
        }
 public static List<RarePokemonRepository> createRepositories(GlobalSettings globalSettings)
 {
     List<RarePokemonRepository> rarePokemonRepositories = new List<RarePokemonRepository>();
     List<PokemonId> pokemonIds = RarePokemonsFactory.createRarePokemonList();
     if (globalSettings.usePokeSnipers)
     {
         rarePokemonRepositories.Add(new PokeSniperRarePokemonRepository(pokemonIds));
     }
     if (globalSettings.useTrackemon)
     {
         rarePokemonRepositories.Add(new TrackemonRarePokemonRepository(pokemonIds));
     }
     return rarePokemonRepositories;
 }
        private void PollRarePokemonRepositories(GlobalSettings globalSettings)
        {
            List<RarePokemonRepository> rarePokemonRepositories = RarePokemonRepositoryFactory.createRepositories(globalSettings);

            int delay = 30 * 1000;
            foreach(RarePokemonRepository rarePokemonRepository in rarePokemonRepositories) {
                var cancellationTokenSource = new CancellationTokenSource();
                var token = cancellationTokenSource.Token;
                var listener = Task.Factory.StartNew(async () =>
                {
                    Thread.Sleep(5 * 1000);
                    while (true)
                    {
                        Thread.Sleep(delay);
                        for (int retrys = 0; retrys <= 3; retrys++)
                        {
                            var pokeSniperList = rarePokemonRepository.FindAll();
                            if (pokeSniperList != null)
                            {
                                if (pokeSniperList.Any())
                                {
                                    await feedToClients(pokeSniperList, rarePokemonRepository.GetChannel());
                                }
                                else
                                {
                                    Log.Debug("No new pokemon on {0}", rarePokemonRepository.GetChannel());
                                }
                                break;
                            }
                            if (token.IsCancellationRequested)
                                break;
                            Thread.Sleep(1000);
                        }
                    }

                }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            }
            
        }