示例#1
0
        /// <summary>
        /// Upserts all entries into the cache.
        /// </summary>
        public async Task <IEnumerable <TResource> > UpsertAll()
        {
            var resourcesPage = await PokeApi.GetNamedPage <TResource>();

            var allResources = await GetAllResources();

            if (!allResources.Any() || allResources.ToList().Count != resourcesPage.Count)
            {
                const int pageSize = 20;

                var entryList = new List <TResource>();

                var pagesUsed = 0;
                NamedApiResourceList <TResource> page;
                do
                {
                    page = await PokeApi.GetNamedPage <TResource>(pageSize, pageSize *pagesUsed++);

                    var entries = await UpsertMany(page.Results);

                    entryList.AddRange(entries);
                } while (!string.IsNullOrEmpty(page.Next));

                return(entryList);
            }

            // if we have the right number of entries then we're probably good
            return(allResources);
        }
        /// <summary>
        /// Returns all Pokemon species up to a limit from an offset.
        /// </summary>
        public async Task <PokemonSpeciesEntry[]> GetPokemonSpecies(int limit, int offset)
        {
            var resources = await PokeApi.GetNamedPage <PokemonSpecies>(limit, offset);

            var species = await UpsertMany(resources);

            return(species.OrderBy(s => s.SpeciesId).ToArray());
        }