Esempio n. 1
0
        internal static async Task <List <T> > Depage(Paging <T> page, LoadingStatus status = null)
        {
            var loadedItems = page.Items;
            var passedPage  = page;

            status?.SetAvailable(page.Total);
            status?.SetLoaded(loadedItems.Count);

            // then iterate over all the next pages
            while (page.HasNextPage())
            {
                page = await API.S.GetNextPageAsync(page);

                loadedItems.AddRange(page.Items);
                status?.SetLoaded(loadedItems.Count);
            }

            // Handle previous pages if supplied page parameter was not the first page
            while (passedPage.HasPreviousPage())
            {
                passedPage = await API.S.GetPreviousPageAsync(passedPage);

                loadedItems.AddRange(passedPage.Items);
                status?.SetLoaded(loadedItems.Count);
            }

            return(loadedItems);
        }
Esempio n. 2
0
        /// <summary>
        /// Splits a list before creating a request, as it will cut off after a certain amount of IDs
        /// </summary>
        /// <param name="cacher">The function to request recursively</param>
        /// <param name="ids">List of IDs in string form</param>
        /// <param name="limit">The limit corresponding to this request</param>
        /// <returns>true on success, false on error</returns>
        private static async Task <bool> SplitRequestIDs(Func <List <string>, LoadingStatus, Task <bool> > cacher, List <string> ids, int limit, LoadingStatus status = null)
        {
            bool success = true;

            for (int i = 0; i <= ids.Count; i += limit)
            {
                // if we're at the end of the list, only request up to count, as otherwise we hit an OutOfBounds exception
                if (i + limit > ids.Count)
                {
                    // change the success variable only if it returned false
                    if (!await cacher(ids.GetRange(i, ids.Count - i), status))
                    {
                        success = false;
                    }
                }
                else
                {
                    if (!await cacher(ids.GetRange(i, limit), status))
                    {
                        success = false;
                    }
                }
                status?.SetLoaded(i);
            }

            return(success);
        }