private async Task UpdateVoiceActorFromFavorited() { try { var db = App.liteDB.GetCollection <FavoritedVoiceActor>(); var voiceActors = _collection as IList <FavoritedVoiceActor>; double total = voiceActors.Count; for (int i = 0; i < voiceActors.Count; i++) { double result = (double)i / total; MessagingCenter.Send <ProgressPopupViewModel, double>(this, string.Empty, result); await App.DelayRequest(4); if (_cancelationToken != null && _cancelationToken.IsCancellationRequested) { _cancelationToken.Token.ThrowIfCancellationRequested(); } var voiceAc = db.FindById(voiceActors[i].VoiceActor.MalId); Person person = await App.Jikan.GetPerson(voiceAc.VoiceActor.MalId); person.RequestCached = true; await App.DelayRequest(4); PersonPictures characterPictures = await App.Jikan.GetPersonPictures(voiceAc.VoiceActor.MalId); characterPictures.RequestCached = true; voiceAc = new FavoritedVoiceActor(person, characterPictures.Pictures.ToList()); voiceAc.IsFavorited = true; db.Update(voiceAc.VoiceActor.MalId, voiceAc); } } catch (JikanRequestException ex) { ex.SaveExceptionData(); } catch (OperationCanceledException ex) { } catch (Exception ex) { ex.SaveExceptionData(); } }
public async Task LoadAsync(object param) { long id = (long)param; IsLoading = true; CanEnable = !IsLoading; try { var favoritedVoiceActor = App.liteDB.GetCollection <FavoritedVoiceActor>().FindById(id); if (favoritedVoiceActor == null) { await App.DelayRequest(); Person person = await App.Jikan.GetPerson(id); await App.DelayRequest(); PersonPictures personPictures = await App.Jikan.GetPersonPictures(id); favoritedVoiceActor = new FavoritedVoiceActor(person, personPictures.Pictures.ToList()); } PersonContext = favoritedVoiceActor; } catch (JikanRequestException ex) { ex.SaveExceptionData(); } catch (OperationCanceledException ex) { } catch (Exception ex) { ex.SaveExceptionData(); } finally { IsLoading = false; CanEnable = !IsLoading; } }