private async Task PopulateDataAsync() { HasActiveTask = true; var termsPost = new PostTerms { PagingSkip = 0, PagingTake = 128 }; var feed = default(PostFeed); try { var feeds = await _client.FetchPostFeedsAsync(_userID, CancellationToken.None); feed = feeds.FirstOrDefault(x => x.Title == "READING_LIST"); if (feed == null) { EntriesPublic.Clear(); } else { var postsFeed = await _client.FetchPostsAsync(_userID, feed.ID, termsPost, CancellationToken.None); if (postsFeed != null) { // BUG: pip-services-net EntriesPublic.Clear(); foreach (var x in postsFeed.Values) EntriesPublic.Add(new PostEntryViewModel(NavigationService, x, _userID)); } } var postsJournal = await _client.FetchPostsAsync(_userID, termsPost, CancellationToken.None); EntriesJournal.Clear(); if (postsJournal != null) { // BUG: pip-services-net foreach (var x in postsJournal.Values) EntriesJournal.Add(new PostEntryViewModel(NavigationService, x, _userID)); } } catch (OperationCanceledException) { } HasActiveTask = false; try { if (feed != null) { var termsConnection = new ConnectionTerms(); var connections = await _client.FetchConnectionsAsync(_userID, termsConnection, CancellationToken.None); EntriesReading.Clear(); foreach (var partyID in feed.PartyIDs) { var connection = connections.FirstOrDefault(x => x.ToPartyID == partyID); if (connection != null) EntriesReading.Add(new ConnectionEntryViewModel(_client, _userID, connection, true)); } } } catch (OperationCanceledException) { } }
public async Task<PagingSegment<Post>> FetchPostsAsync(string partyID, PostTerms terms, CancellationToken terminator) { if (partyID == null) throw new ArgumentNullException(nameof(partyID)); if (terms == null) throw new ArgumentNullException(nameof(terms)); VerifyServerAddress(); var parameters = new Dictionary<string, string>(StringComparer.Ordinal) { ["paging"] = "1" }; if (terms.PagingSkip != default(ulong)) parameters.Add("skip", terms.PagingSkip.ToString(CultureInfo.InvariantCulture)); if (terms.PagingTake != default(ulong)) parameters.Add("take", terms.PagingTake.ToString(CultureInfo.InvariantCulture)); if (terms.SearchText != default(string)) parameters.Add("search", terms.SearchText); var uri = RestUriBuilder.Create(FormattableString.Invariant($"{_server}/api/parties/{partyID}/posts"), parameters); using (var response = await _client.GetAsync(uri, terminator).ConfigureAwait(false)) { await VerifyResponseAsync(response); return await response.Content.ReadAsJsonObjectAsync<PagingSegment<Post>>().ConfigureAwait(false); } }