public async IAsyncEnumerable <Match> GetMatches(int batchSize, ulong startAtMatch = 0)
        {
            var dota2Interaface = _interfaceFactory.CreateSteamWebInterface <DOTA2Match>(new HttpClient());

            List <MatchHistoryMatchModel> allMatches = new List <MatchHistoryMatchModel>();

            uint matchesCount = 0;

            do
            {
                MatchHistoryModel matches = (await dota2Interaface.GetMatchHistoryAsync(
                                                 gameMode: 1, // All pick
                                                 startAtMatchId: startAtMatch)).Data;
                allMatches.AddRange(matches.Matches);

                if (matches.ResultsRemaining <= 0)
                {
                    break;
                }

                matchesCount += matches.NumResults;
                startAtMatch  = matches.Matches.Min(m => m.MatchId);
            } while (matchesCount < batchSize);



            var dota2EconomyInteraface = _interfaceFactory.CreateSteamWebInterface <DOTA2Econ>(new HttpClient());
            var heroes = (await dota2EconomyInteraface.GetHeroesAsync()).Data;
            var items  = (await dota2EconomyInteraface.GetGameItemsAsync()).Data;

            foreach (var match in allMatches.Take(batchSize))
            {
                var matchDetails = (await dota2Interaface.GetMatchDetailsAsync(match.MatchId)).Data;
                if (matchDetails != null)
                {
                    yield return new Match()
                           {
                               StartDate            = matchDetails.StartTime,
                               ExternalMatchId      = match.MatchId,
                               Winner               = matchDetails.RadiantWin ? Side.Radiant : Side.Dire,
                               PlayerMatchHistories = matchDetails.Players.Select(p => new PlayerMatchHistory()
                        {
                            Kills   = (int)p.Kills,
                            Deaths  = (int)p.Assists,
                            Assists = (int)p.Assists,
                            Side    = (((int)p.PlayerSlot & 128) == 128) ? Side.Dire : Side.Radiant,
                            Hero    = p.HeroId != 0 ? new Hero()
                            {
                                ExternalId = p.HeroId,
                                Name       = heroes.FirstOrDefault(h => h.Id == p.HeroId)?.LocalizedName
                            } : null,
                            ItemPlayerMatchHistories = new List <uint> {
                                p.Item0, p.Item1, p.Item2, p.Item3, p.Item4, p.Item5
                            }
                            .Where(p => p != 0)
                            .Select(i => new ItemPlayerMatchHistory()
                            {
                                Item = new Item()
                                {
                                    ExternalId = i,
                                    Name       = items.FirstOrDefault(it => it.Id == i).LocalizedName,
                                }
                            }).ToList(),
                            Player = new Player()
                            {
                                PlayerId       = p.AccountId,
                                SteamAccountId = p.AccountId,
                            }
                        }).ToList()
                           }
                }
                ;
            }
        }
    }
Пример #2
0
 public MatchHistoryViewModel(ServerConnection connection, Navigator navigator, User user) : base(connection, navigator)
 {
     this.model = new MatchHistoryModel(this.connection, user);
     this.matchHistoryDataTable = GetMatchHistoryDataTable();
     this.userWinRatio          = GetUserWinRatio();
 }