Example #1
0
        public async Task ExecuteAsync()
        {
            var heroes = await GetHeroes();

            var guides = await GetGuides(heroes);

            var masterTiers = await repository.GetHeroTiersAsync("master", applicationHostLifetime.ApplicationStopping);

            var generalTiers = await repository.GetHeroTiersAsync("general", applicationHostLifetime.ApplicationStopping);

            var aramTiers = await repository.GetHeroTiersAsync("aram", applicationHostLifetime.ApplicationStopping);

            var maps = guides.SelectMany(guide => guide.MapPreference.AllMaps).Distinct();

            SaveGuides(new Output.Data(
                           guides.Select(CreateOutpuHero).ToList(),
                           maps.Select(Output.Map.FromModel).ToList()));
            await DownloadImagesAsync(guides, "heroes");
            await DownloadImagesAsync(maps, "maps");

            Output.Hero CreateOutpuHero(HeroGuide guide)
            => new Output.Hero(
                guide.Id,
                guide.Name,
                guide.Role,
                guide.GuideUri,
                Output.HeroMapPreference.FromModel(guide.MapPreference),
                Output.HeroSynergiesAndCounter.FromModel(guide.SynergiesAndCounter),
                ExtractTierRecommendation(guide.Id, generalTiers),
                ExtractTierRecommendation(guide.Id, masterTiers),
                ExtractTierRecommendation(guide.Id, aramTiers));

            Dictionary <string, Output.TierRecommendation> ExtractTierRecommendation(string heroId, IReadOnlyList <Tier> tiers)
            {
                var recommendations = from tier in tiers
                                      from hero in tier.Heroes
                                      where hero.Id == heroId
                                      select(tier, hero);

                return(recommendations.ToDictionary(
                           recommendation => recommendation.hero.Condition ?? "default",
                           recommendation => new Output.TierRecommendation(
                               recommendation.tier.Name,
                               recommendation.hero.BanRecommended)));
            }
        }