public async Task <bool> LoadTrophies(string username) { Offset = Offset + MaxCount; IsLoading = true; var trophyManager = new TrophyManager(); TrophyEntity trophyList = await trophyManager.GetTrophyList(username, Offset, UserAccountEntity); if (trophyList == null) { //HasMoreItems = false; return(false); } foreach (TrophyEntity.TrophyTitle trophy in trophyList.TrophyTitles) { Add(trophy); } if (trophyList.TrophyTitles.Any()) { HasMoreItems = true; MaxCount += 64; } else { HasMoreItems = false; } IsLoading = false; return(true); }
private async Task <bool> GetTrophyList() { var trophyManager = new TrophyManager(); TrophyCollection = new InfiniteScrollingCollection { UserAccountEntity = App.UserAccountEntity, TrophyList = new ObservableCollection <TrophyEntity.TrophyTitle>(), Offset = 64 }; var items = await trophyManager.GetTrophyList(App.SelectedUser.OnlineId, 0, App.UserAccountEntity); if (items == null) { return(false); } foreach (TrophyEntity.TrophyTitle item in items.TrophyTitles) { TrophyCollection.TrophyList.Add(item); } if (!items.TrophyTitles.Any()) { NoTrophyTextBlock.Visibility = Visibility.Visible; TrophyHeaderGrid.Visibility = Visibility.Collapsed; } TrophyList.ItemRealized += trophyList_ItemRealized; TrophyList.DataContext = TrophyCollection; ComparedUserNameBlock.Text = App.UserAccountEntity.GetUserEntity().OnlineId.Equals(App.SelectedUser.OnlineId) ? string.Empty : App.SelectedUser.OnlineId; FromUserNameBlock.Text = App.UserAccountEntity.GetUserEntity().OnlineId; return(true); }
public async Task <bool> LoadTrophies(string username) { Offset = Offset + MaxCount; IsLoading = true; await Shell.Instance.ViewModel.UpdateTokens(); var trophyManager = new TrophyManager(); var trophyResultList = await trophyManager.GetTrophyList(username, CompareUsername, Offset, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, trophyResultList); var result = await ResultChecker.CheckSuccess(trophyResultList, false); if (!result) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return(false); } var trophyList = JsonConvert.DeserializeObject <TrophyDetailResponse>(trophyResultList.ResultJson); if (trophyList == null) { //HasMoreItems = false; IsEmpty = true; IsLoading = false; return(false); } foreach (var trophy in trophyList.TrophyTitles) { Add(trophy); } if (trophyList.TrophyTitles.Any()) { HasMoreItems = true; MaxCount += 64; } else { if (Count <= 0) { IsEmpty = true; } HasMoreItems = false; } IsLoading = false; return(true); }
public async Task <IEnumerable <TrophyEntry> > GetTrophies(Account account, DateTime lastUpdatedStamp) { var results = new List <TrophyEntry>(); var trophies = await _trophyManager.GetTrophyList(account.PSNName, 0, _userAccountEntity); int flag = 0; while (flag < 10) { if (trophies != null && trophies.TrophyTitles != null && trophies.TrophyTitles.Any()) { foreach (var trophy in trophies.TrophyTitles.Where(tt => tt.ComparedUser != null && (DateTime.Parse(tt.ComparedUser.LastUpdateDate).ToUniversalTime() > lastUpdatedStamp))) { int f = 0; while (f < 10) { var details = await _trophyDetailManager.GetTrophyDetailList(trophy.NpCommunicationId, account.PSNName, true, _userAccountEntity); if (details != null && details.Trophies != null && details.Trophies.Any()) { foreach (var detail in details.Trophies.Where(t => t.ComparedUser.Earned && DateTime.Parse(t.ComparedUser.EarnedDate).ToUniversalTime() > account.LastPolledTrophy)) { results.Add(new TrophyEntry(account, detail, DateTime.Parse(detail.ComparedUser.EarnedDate).ToUniversalTime(), trophy.TrophyTitleName, trophy.NpCommunicationId)); } f = 10; } else { f++; Console.WriteLine("{0} Can't fetch details", DateTime.Now); Thread.Sleep(5000); } } } flag = 10; } else { flag++; Console.WriteLine("{0} Can't fetch achievments for user {1}", DateTime.Now, account.PSNName); Thread.Sleep(5000); } } return(results.OrderBy(r => r.TimeStamp)); }