Exemplo n.º 1
0
 public async Task FillFriendListAsync(string token, GroupList<Friend, int> friendList)
 {
     //Кеша
     foreach (Friend friend in await TaskEx.Run(() => VkStorage.FriendCashe.Cashe.GetAllAsObject<Friend>()))
     {
         friendList.AddItem(friend);
     }
     foreach (Group<Friend, int> group in friendList)
         foreach (Friend friend in group)
             friend.Photo = await UpdatePhoto(friend.PhotoUri);
     //Сервис
     const int count = 25;
     const int topCount = 5;
     int offset = 0;
     //Топ
     List<Friend> topFriend = await VkService.GetFriendListAsync(token, topCount, 0, FriendOrderType.Rate);
     for (int i = 0; i < topFriend.Count; i++)
     {
         Friend serviceValue = topFriend[i];
         serviceValue.TopOrder = i + 1;
         Friend casheValue = friendList.FindEqualByKey(serviceValue);
         if (casheValue == null)
             friendList.AddItem(serviceValue);
         VkStorage.FriendCashe.SyncCasheWithServiceValue<Friend, int>(serviceValue, casheValue);
     }
     //Остальные
     while (true)
     {
         List<Friend> friends = await VkService.GetFriendListAsync(token, count, offset, FriendOrderType.FirstName);
         foreach (Friend serviceValue in friends.Where(friend => topFriend.All(f => f.UserId != friend.UserId)))
         {
             Friend casheValue = friendList.FindEqualByKey(serviceValue);
             if (casheValue == null)
                 friendList.AddItem(serviceValue);
             VkStorage.FriendCashe.SyncCasheWithServiceValue<Friend, int>(serviceValue, casheValue);
         }
         offset += count;
         if (friends.Count != count)
             break;
     }
     //Фото
     foreach (Group<Friend, int> group in friendList)
         foreach (Friend friend in group)
             friend.Photo = await UpdatePhoto(friend.PhotoUri);
     //Очистка кеша от старых значений
     ClearFriendCashe(friendList);
 }
Exemplo n.º 2
0
        public void GetContactsList(string token, GroupList<Contact, string> contactsList)
        {
            Contacts contacts = new Contacts();
            Contact tmpContact;
            contacts.SearchCompleted += (s, e) =>
                                                  {
                                                      foreach (Microsoft.Phone.UserData.Contact contact in e.Results)
                                                      {
                                                          using (var contactPhotoStream = contact.GetPicture())
                                                          {
                                                              tmpContact = new Contact
                                                                                       {
                                                                                           DisplayName = contact.DisplayName,
                                                                                           ContactPic = contactPhotoStream == null
                                                                                                  ? PictureDecoder.DecodeJpeg(Application.GetResourceStream(new Uri(@"/VkMessenger;component/Image/No_photo.png", UriKind.Relative)).Stream)
                                                                                                  : PictureDecoder.DecodeJpeg(contactPhotoStream)
                                                                                       };

                                                              tmpContact.FillPhoneNumbers(contact.PhoneNumbers.Select(cpn => Regex.Replace(cpn.PhoneNumber.StartsWith("8") ? "+7" + cpn.PhoneNumber.Substring(1) : cpn.PhoneNumber, @"[^+\d]", string.Empty)).ToList());
                                                              contactsList.AddItem(tmpContact);
                                                          }
                                                      }
                                                      LinkContacts(token, contactsList);
                                                  };
            contacts.SearchAsync(string.Empty, FilterKind.None, null);
        }