Beispiel #1
0
        public async Task RefreshCriticInfo()
        {
            _logger.LogInformation("Refreshing critic scores");
            var supportedYears = await _interLeagueService.GetSupportedYears();

            var masterGames = await _interLeagueService.GetMasterGames();

            foreach (var masterGame in masterGames)
            {
                if (!masterGame.OpenCriticID.HasValue)
                {
                    continue;
                }

                if (masterGame.DoNotRefreshAnything)
                {
                    continue;
                }

                if (masterGame.IsReleased(_clock) && masterGame.ReleaseDate.HasValue)
                {
                    var year          = masterGame.ReleaseDate.Value.Year;
                    var supportedYear = supportedYears.SingleOrDefault(x => x.Year == year);
                    if (supportedYear != null && supportedYear.Finished)
                    {
                        continue;
                    }
                }

                var openCriticGame = await _openCriticService.GetOpenCriticGame(masterGame.OpenCriticID.Value);

                if (openCriticGame.HasValue)
                {
                    await _interLeagueService.UpdateCriticStats(masterGame, openCriticGame.Value);
                }
                else
                {
                    _logger.LogWarning($"Getting an open critic game failed (empty return): {masterGame.GameName} | [{masterGame.OpenCriticID.Value}]");
                }

                foreach (var subGame in masterGame.SubGames)
                {
                    if (!subGame.OpenCriticID.HasValue)
                    {
                        continue;
                    }

                    var subGameOpenCriticGame = await _openCriticService.GetOpenCriticGame(subGame.OpenCriticID.Value);

                    if (subGameOpenCriticGame.HasValue)
                    {
                        await _interLeagueService.UpdateCriticStats(subGame, subGameOpenCriticGame.Value);
                    }
                }
            }

            _logger.LogInformation("Done refreshing critic scores");
        }
        public async Task <IActionResult> RefreshCriticInfo()
        {
            var supportedYears = await _fantasyCriticService.GetSupportedYears();

            var masterGames = await _fantasyCriticService.GetMasterGames();

            foreach (var masterGame in masterGames)
            {
                if (!masterGame.OpenCriticID.HasValue)
                {
                    continue;
                }

                if (masterGame.IsReleased(_clock) && masterGame.ReleaseDate.HasValue)
                {
                    var year          = masterGame.ReleaseDate.Value.Year;
                    var supportedYear = supportedYears.Single(x => x.Year == year);
                    if (supportedYear.Finished)
                    {
                        continue;
                    }
                }

                var openCriticGame = await _openCriticService.GetOpenCriticGame(masterGame.OpenCriticID.Value);

                if (openCriticGame.HasValue)
                {
                    await _fantasyCriticService.UpdateCriticStats(masterGame, openCriticGame.Value);
                }

                foreach (var subGame in masterGame.SubGames)
                {
                    if (!subGame.OpenCriticID.HasValue)
                    {
                        continue;
                    }

                    var subGameOpenCriticGame = await _openCriticService.GetOpenCriticGame(subGame.OpenCriticID.Value);

                    if (subGameOpenCriticGame.HasValue)
                    {
                        await _fantasyCriticService.UpdateCriticStats(subGame, subGameOpenCriticGame.Value);
                    }
                }
            }

            return(Ok());
        }
Beispiel #3
0
    public async Task RefreshCriticInfo()
    {
        _logger.Info("Refreshing critic scores");
        var systemWideSettings = await _interLeagueService.GetSystemWideSettings();

        if (!systemWideSettings.RefreshOpenCritic)
        {
            _logger.Info("Not refreshing Open Critic scores as the flag is turned off.");
            return;
        }

        var supportedYears = await _interLeagueService.GetSupportedYears();

        var masterGames = await _interLeagueService.GetMasterGames();

        var currentDate         = _clock.GetToday();
        var masterGamesToUpdate = masterGames.Where(x => x.OpenCriticID.HasValue && !x.DoNotRefreshAnything).ToList();

        foreach (var masterGame in masterGamesToUpdate)
        {
            if (masterGame.IsReleased(currentDate) && masterGame.ReleaseDate.HasValue)
            {
                var year          = masterGame.ReleaseDate.Value.Year;
                var supportedYear = supportedYears.SingleOrDefault(x => x.Year == year);
                if (supportedYear != null && supportedYear.Finished)
                {
                    continue;
                }
            }

            var openCriticGame = await _openCriticService.GetOpenCriticGame(masterGame.OpenCriticID !.Value);

            if (openCriticGame is not null)
            {
                await _interLeagueService.UpdateCriticStats(masterGame, openCriticGame);
            }
            else
            {
                _logger.Warn($"Getting an open critic game failed (empty return): {masterGame.GameName} | [{masterGame.OpenCriticID.Value}]");
            }

            foreach (var subGame in masterGame.SubGames)
            {
                if (!subGame.OpenCriticID.HasValue)
                {
                    continue;
                }

                var subGameOpenCriticGame = await _openCriticService.GetOpenCriticGame(subGame.OpenCriticID.Value);

                if (subGameOpenCriticGame is not null)
                {
                    await _interLeagueService.UpdateCriticStats(subGame, subGameOpenCriticGame);
                }
            }
        }

        _logger.Info("Done refreshing critic scores");
    }