コード例 #1
0
ファイル: DayStatsRunner.cs プロジェクト: geddar2010/new
        protected override async Task ProcessAsync(DateArgs args, Result result)
        {
            var url = string.Format("Sport/3/Game/{0:yyyy-M-d}", args.Date);

            var fetch = await GetAsync(url);

            if (fetch.Count > 0)
            {
                #region countries

                var countries = fetch.Select(x => x.StageDto.CountryId).Union(fetch.SelectMany(x => x.Games)
                                                                              .SelectMany(x =>
                                                                                          new[] { x.CountryId, x.TeamHome.CountryId, x.TeamAway.CountryId })).Distinct()
                                .Select(x => new CountryDto(x)).ToList();

                if (countries.Count > 0)
                {
                    _db.CountryRepository.AddIfNotExists_Countries(countries, out var countriesInserted);
                    result.CountriesInserted = countriesInserted;
                }

                #endregion

                #region leagues

                var leagues = fetch.Select(x => new LeagueDto(x.StageDto.LeagueId, x.StageDto.CountryId))
                              .Union(fetch.SelectMany(x => x.Games)
                                     .Select(x => new LeagueDto(x.LeagueId, x.CountryId)))
                              .GroupBy(x => x.Id)
                              .Select(x => x.First())
                              .ToList();

                if (leagues.Count > 0)
                {
                    _db.LeagueRepository.AddIfNotExists_Leagues(leagues, out var leaguesInserted);
                    result.LeaguesInserted = leaguesInserted;
                }

                #endregion

                #region seasons

                var seasons = fetch.Select(x =>
                                           new SeasonDto(x.StageDto.SeasonId, x.StageDto.CountryId, x.StageDto.LeagueId))
                              .Union(fetch.SelectMany(x => x.Games)
                                     .Select(x => new SeasonDto(x.SeasonId, x.CountryId, x.LeagueId)))
                              .GroupBy(x => x.Id).Select(x => x.First()).ToList();

                if (seasons.Count > 0)
                {
                    _db.SeasonRepository.AddIfNotExists_Seasons(seasons, out var seasonsInserted);
                    result.SeasonsInserted = seasonsInserted;
                }

                #endregion

                #region stages

                var stages = fetch.Select(x => x.StageDto).ToList();

                if (stages.Count > 0)
                {
                    _db.StageRepository.AddOrUpdate_Stages(stages, out var stagesInserted, out var stagesUpdated);
                    result.StagesInserted = stagesInserted;
                    result.StagesUpdated  = stagesUpdated;
                }

                #endregion

                #region Teams

                var teams = fetch
                            .SelectMany(x => x.Teams)
                            .ToList();

                if (teams.Count > 0)
                {
                    _db.TeamRepository.AddOrUpdate_Teams(teams, out var teamsInserted, out var teamsUpdated);
                    result.TeamsInserted = teamsInserted;
                    result.TeamsUpdated  = teamsUpdated;
                }

                #endregion

                #region Games

                var games = fetch
                            .SelectMany(s => s.Games)
                            .ToList();

                if (games.Count > 0)
                {
                    _db.GameRepository.AddOrUpdate_Games(games, out var gamesInserted, out var gamesUpdated);
                    result.GamesInserted = gamesInserted;
                    result.GamesUpdated  = gamesUpdated;
                }

                #endregion
            }
        }
コード例 #2
0
ファイル: DayStatsRunner.cs プロジェクト: geddar2010/new
 public DayStatsRunner(Result total = null) : base(total)
 {
     _total = total ?? new Result(DateArgs.Create(DateTime.Now), RunnerType.DayStats);
 }