private async Task AddProfiles(VKResponseList<Comment> responce) { var user_id_query = from item in responce.response select item.uid; IEnumerable<Profiles.IVKProfile> newprofiles = await VKApi.Profiles.UserManager.GetShortInfo(user_id_query); this.profiles.UnionWith(newprofiles); }
public async Task GetFriendList() { if (FriendList == null) this.FriendList = new List<Profile>(); VKResponseList<Profile> profileslist = null; if (this.id > 0) profileslist = await provider.Call<VKResponseList<Profile>>("friends.get" , new Dictionary<string, string>() { {"uid",id.ToString()} ,{ "fields","uid,first_name,last_name,photo,photo_medium,photo_big,online" } ,{ "order", "hints"} }); else { VKResponse<UserCount> idlist = await provider.Call<VKResponse<UserCount>>("groups.getMembers" , new Dictionary<string, string>() { {"gid",Math.Abs(id).ToString()} }); if (idlist == null || idlist.response.count == 0) return; List<List<int>> queries = new List<List<int>>(); int firstCounter = 0; int secondCounter = 0; foreach (var item in idlist.response.users) { if (firstCounter == 0) { queries.Add(new List<int>()); } queries[secondCounter].Add(item); firstCounter++; if (firstCounter == 200) { firstCounter = 0; secondCounter++; } } profileslist = new VKResponseList<Profile>(); foreach (var query in queries) { StringBuilder idListBuilder = new StringBuilder(); foreach (var item in query) { idListBuilder.Append(item.ToString()); idListBuilder.Append(','); } idListBuilder.Remove(idListBuilder.Length - 1, 1); var responce = await provider.Call<VKResponseList<Profile>>("users.get" , new Dictionary<string, string>() { {"uids",idListBuilder.ToString()} ,{"fields","photo,photo_medium,photo_big"} }); profileslist.response.AddRange(responce.response); } StringBuilder idstringbuilder = new StringBuilder(); if (idlist.response.users.Count < 300) { foreach (var item in idlist.response.users) { idstringbuilder.Append(item.ToString()); idstringbuilder.Append(','); } idstringbuilder.Remove(idstringbuilder.Length - 1, 1); profileslist = await provider.Call<VKResponseList<Profile>>("users.get" , new Dictionary<string, string>() { {"uids",idstringbuilder.ToString()} ,{"fields","photo,photo_medium,photo_big"} }); } } if (profileslist == null) return; if (FriendList.Count == 0) FriendList = profileslist.response; else foreach (var friend in profileslist.response) { int itempos = FriendList.IndexOf(friend); if (itempos < 0) FriendList.Add(friend); else FriendList[itempos] = friend; } }