Exemplo n.º 1
0
        public async Task <IEnumerable <BlizzardPlayer> > GetSlimGuildMembersDataAsync(BlizzardRegion region, string guild, string realm)
        {
            var guildDataJson = await this.blizzardService.GetGuildMembersAsync(guild, realm, region);

            var members = GuildMemberParsing.GetSlimPlayersFromGuildPlayerList(guildDataJson).ToList();

            return(members.Select(x => new BlizzardPlayer()
            {
                GuildName = guild,
                PlayerName = x.Name,
                PlayerRealmName = x.RealmName,
                Class = x.Class,
                Level = x.Level
            }));
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <GuildMemberStats> > GetLargeGuildMembersDataAsync(BlizzardRegion region, string guild, string realm, IProgress <double> progress)
        {
            var guildDataJson = await this.blizzardService.GetGuildMembersAsync(guild, realm, region);

            var members = GuildMemberParsing.GetSlimPlayersFromGuildPlayerList(guildDataJson).ToList();

            foreach (var member in members)
            {
                member.RegionName = BlizzardService.GetRegionString(region);
                member.GuildName  = guild;
            }

            int totalCount = members.Count();

            int count = 0;

            var taskList = new List <Task <GuildMemberStats> >();

            foreach (var member in members)
            {
                taskList.Add(Task.Run(async() =>
                {
                    try
                    {
                        if (await this.PopulateMemberDataAsync(member, region))
                        {
                            return(member);
                        }

                        return(null);
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }
                    finally
                    {
                        progress.Report((double)count++ / totalCount);
                    }
                }));
            }

            await Task.WhenAll(taskList);

            return(taskList.Select(x => x.Result).Where(x => x != null));
        }