Beispiel #1
0
        //public async Task AddTeam(string team)
        //{
        //    teams.Add(team);
        //    var orderedTeam = teams.OrderBy(t => t).ToList();
        //    string json = await Json.StringifyAsync(orderedTeam);
        //    await File.WriteAllTextAsync(BotConfig.TeamsFile, json);
        //}
        #endregion

        #region Private Methods
        private async Task ActivateTimer()
        {
            double   timeSpan = 15;
            TimeSpan diff     = TimeSpan.Zero;

            if (firstRun)
            {
                var json = await File.ReadAllTextAsync(BotConfig.GamesFile);

                var games = await Json.ToObjectAsync <Games>(json);

                this.games = games?.GamesList;

                json = await File.ReadAllTextAsync(BotConfig.TeamsFile);

                this.teams = await Json.ToObjectAsync <HashSet <Team> >(json);

                if ((games != null) && (games.LastUpdated.AddMinutes(timeSpan) > DateTime.Now))
                {
                    diff = (games.LastUpdated - DateTime.Now) + TimeSpan.FromMinutes(timeSpan);
                }
            }

            await LoggindService.Log($"Timer ativado para {diff}", GetType(), Discord.LogSeverity.Info);

            var timer = new Timer(async(e) =>
            {
                await FetchGames();
            }, null, diff, TimeSpan.FromMinutes(timeSpan));

            firstRun   = false;
            this.timer = timer;
        }
        /// <summary>
        /// Creates a file in the given path if not exists.
        /// </summary>
        /// <param name="path"></param>
        /// <returns>True if the file was created. False if already exists.</returns>
        public static async Task <bool> CreateFile(string path)
        {
            if (!File.Exists(path))
            {
                File.Create(path).Dispose();
                await LoggindService.Log($"File \"{Path.GetFileName(path)}\" created.", typeof(StorageService), Discord.LogSeverity.Info);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Creates a directory in the given path if not exists.
        /// </summary>
        /// <param name="path">The path for the directory.</param>
        /// <returns>True if the directory was created. False if already exists.</returns>
        public static async Task <bool> CreateDirectory(string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                await LoggindService.Log($"Directory \"{Path.GetFileName(path)}\" created.", typeof(StorageService), Discord.LogSeverity.Info);

                return(true);
            }

            return(false);
        }
Beispiel #4
0
        public async Task <List <Game> > FetchGames()
        {
            var json = await WebService.GetStringAsync(BaseApi + futureMatch);

            await LoggindService.Log("Jogos atualizados", GetType(), Discord.LogSeverity.Info);

            games = await Json.ToObjectAsync <List <Game> >(json);

            await GetTeams();

            var gamesList = new Games {
                GamesList = games, LastUpdated = DateTime.Now
            };

            OnGotGames(games);

            await File.WriteAllTextAsync(BotConfig.GamesFile, await Json.StringifyAsync(gamesList));

            return(games);
        }