Пример #1
0
        /// <summary>
        /// Get all of the cards. This call will take a while to finish.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        // TODO: Make this call more generic
        public static List <PokemonCard> All(Dictionary <string, string> query = null)
        {
            using (HttpClient client = QueryBuilderHelper.SetupClient())
            {
                HttpResponseMessage stringTask;
                List <Pokemon>      items      = new List <Pokemon>();
                List <PokemonCard>  mergedList = new List <PokemonCard>();
                bool fetchAll = QueryBuilderHelper.FetchAll(ref query);

                if (query != null)
                {
                    if (!query.ContainsKey(CardQueryTypes.Page))
                    {
                        query.Add(CardQueryTypes.Page, "1");
                    }
                    query.Add(CardQueryTypes.PageSize, "500");
                }
                else
                {
                    query = new Dictionary <string, string>()
                    {
                        { CardQueryTypes.Page, "1" },
                        { CardQueryTypes.PageSize, "500" }
                    };
                }

                for (int i = 0; i < int.Parse(query[CardQueryTypes.PageSize]); i++)
                {
                    string queryString = string.Empty;
                    stringTask = QueryBuilderHelper.BuildTaskString(query, ref queryString, client, ResourceTypes.Cards);
                    if (stringTask.IsSuccessStatusCode)
                    {
                        Pokemon item = QueryBuilderHelper.CreateObject <Pokemon>(stringTask);
                        query[CardQueryTypes.Page] = (int.Parse(query[CardQueryTypes.Page]) + 1).ToString();
                        items.Add(item);

                        if (!fetchAll)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Create the list returned as a single list instead of
                // a list of lists
                foreach (Pokemon pokemon in items)
                {
                    mergedList.AddRange(pokemon.Cards);
                }

                return(mergedList);
            }
        }
Пример #2
0
        public static async Task <List <SetData> > All(Dictionary <string, string> query = null)
        {
            using (var client = QueryBuilderHelper.SetupClient())
            {
                var items      = new List <Set>();
                var mergedList = new List <SetData>();
                var fetchAll   = QueryBuilderHelper.FetchAll(ref query);

                if (query != null)
                {
                    if (!query.ContainsKey(CardQueryTypes.Page))
                    {
                        query.Add(CardQueryTypes.Page, "1");
                    }
                    query.Add(CardQueryTypes.PageSize, "500");
                }
                else
                {
                    query = new Dictionary <string, string>
                    {
                        { CardQueryTypes.Page, "1" },
                        { CardQueryTypes.PageSize, "100" }
                    };
                }

                var totalCount = int.Parse(query[CardQueryTypes.PageSize]);
                int amount;
                for (var i = 0; i < totalCount; i += amount)
                {
                    var queryString = string.Empty;
                    var stringTask  = await QueryBuilderHelper.BuildTaskString(query, queryString, client, ResourceTypes.Sets);

                    if (stringTask.IsSuccessStatusCode)
                    {
                        var info = HttpResponseToPagingInfo.MapFrom(stringTask.Headers);
                        totalCount = info.TotalCount;
                        amount     = info.Count;

                        var item = QueryBuilderHelper.CreateObject <Set>(stringTask);
                        query[CardQueryTypes.Page] = (int.Parse(query[CardQueryTypes.Page]) + 1).ToString();
                        items.Add(item);

                        if (!fetchAll)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Create the list returned as a single list instead of a list of lists
                foreach (var set in items)
                {
                    mergedList.AddRange(set.Cards);
                }

                return(mergedList);
            }
        }