Esempio 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);
 }