コード例 #1
0
        /// <summary>
        /// Returns strong typed page of data.
        /// </summary>
        /// <param name="pageIndex">Page number.</param>
        /// <param name="pageSize">Size of page.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Strong typed page of data.</returns>
        public async Task <IEnumerable <T> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_isFirstCall)
            {
                var result = await _paginatedArray.FirstAsync();

                return(ProcessResult(result));
            }
            else
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }

                if (_paginatedArray.HasNext && (pageIndex < _maxPages))
                {
                    var result = await _paginatedArray.NextAsync();

                    return(ProcessResult(result));
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #2
0
ファイル: UserLikes.xaml.cs プロジェクト: villagra/winsdkfb
        private async void AddLikes(
            IReadOnlyList <object> pages
            )
        {
            int count = 0;

            foreach (object page in pages)
            {
                Items.Add((MyFBPage)page);
                if (count == 0)
                {
                    count++;
                    PageGetter pg = new PageGetter();
                    pg.GetPageWithId(((MyFBPage)page).Id);
                }
            }

            if (_likes.HasNext)
            {
                FBResult result = await _likes.NextAsync();

                if (result.Succeeded)
                {
                    IReadOnlyList <object> nextPages =
                        (IReadOnlyList <object>)result.Object;
                    AddLikes(nextPages);
                }
            }
            else
            {
                DoneGetUserLikes();
            }
        }
コード例 #3
0
        /// <summary>
        /// Helper method to process pages of results from underlying service instance.
        /// </summary>
        /// <typeparam name="T">Strong type of model.</typeparam>
        /// <param name="results">List of results to process.</param>
        /// <param name="maxRecords">Total upper limit of records to process.</param>
        /// <param name="processedResults">Stores the processed results constrained by maxRecords.</param>
        /// <returns>Task to support await of async call.</returns>
        private async Task ProcessResultsAsync <T>(IReadOnlyList <object> results, int maxRecords, List <T> processedResults)
        {
            foreach (T result in results)
            {
                if (processedResults.Count < maxRecords)
                {
                    processedResults.Add(result);
                }
            }

            if (paginatedArray.HasNext && processedResults.Count < maxRecords)
            {
                var nextResult = await paginatedArray.NextAsync();

                if (nextResult.Succeeded)
                {
                    IReadOnlyList <object> nextResults = (IReadOnlyList <object>)nextResult.Object;
                    await ProcessResultsAsync <T>(nextResults, maxRecords, processedResults);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Helper method to process pages of results from underlying service instance.
        /// </summary>
        /// <param name="results">List of results to process.</param>
        /// <param name="maxRecords">Total upper limit of records to process.</param>
        /// <returns>Task to support await of async call.</returns>
        private async Task ProcessResultsAsync(IReadOnlyList <object> results, int maxRecords)
        {
            foreach (FacebookPost result in results)
            {
                if (queryResults.Count < maxRecords)
                {
                    queryResults.Add(result);
                }
            }

            if (paginatedArray.HasNext && queryResults.Count < maxRecords)
            {
                var nextResult = await paginatedArray.NextAsync();

                if (nextResult.Succeeded)
                {
                    IReadOnlyList <object> nextResults = (IReadOnlyList <object>)nextResult.Object;
                    await ProcessResultsAsync(nextResults, maxRecords);
                }
            }
        }
コード例 #5
0
        internal static async Task PopulateUserPages()
        {
            Pages.Clear();
            String graphPath = "me/accounts";

            FBPaginatedArray fbPages = new FBPaginatedArray(graphPath, null, FBPage.Factory);
            FBResult         result  = null;

            do
            {
                if (result == null)
                {
                    result = await fbPages.FirstAsync();
                }
                else
                {
                    result = await fbPages.NextAsync();
                }
                if (result.Succeeded)
                {
                    IReadOnlyList <object> pages = (IReadOnlyList <object>)result.Object;
                    foreach (var p in pages)
                    {
                        FBPage page = (FBPage)p;
                        if (page != null)
                        {
                            Pages.Add(page);
                        }
                    }
                }
                else
                {
                    FBErrorHandler.HandleError(result);
                }
            } while (fbPages.HasNext);
        }