Exemplo n.º 1
0
        private async static Task <MarketplaceList> ParsePage(MarketplaceQuery query)
        {
            MarketplaceList items        = new MarketplaceList();
            string          responseBody = await Client.GetStringAsync(query.Uri);

            MarketplaceQueryResponse response = JsonSerializer.Deserialize <MarketplaceQueryResponse>(responseBody);

            Console.WriteLine("Returned {0} items", response.results.Count);
            response.AddToMarketplaceList(items);
            return(items);
        }
Exemplo n.º 2
0
        public async static Task <MarketplaceList> ParseTolist(MarketplaceQuery query)
        {
            MarketplaceList items = new MarketplaceList();

            query.AddParam("start", 0);
            query.AddParam("count", 100);

            string responseBody = await Client.GetStringAsync(query.Uri);

            MarketplaceQueryResponse response = JsonSerializer.Deserialize <MarketplaceQueryResponse>(responseBody);

            Console.Write("Query 1 sent. ");
            Console.WriteLine("Returned {0} items", response.results.Count);
            response.AddToMarketplaceList(items);



            int count = response.total_count;

            if (count > 100)
            {
                try
                {
                    for (int pos = 100; pos <= count; pos += 100)
                    {
                        Console.WriteLine("({0}/{1})", pos, count);
                        Thread.Sleep(Delay);

                        query.AddParam("start", pos);

                        Console.Write("Query {0} sent. ", pos / 100 + 1);
                        items.AddRange(await ParsePage(query));
                    }
                }
                catch (HttpRequestException e)
                {
                    Console.WriteLine("\nException Caught!");
                    Console.WriteLine("Message :{0}", e.Message);
                    Console.WriteLine("Saving {0} items", items.Count);
                }
            }

            return(items);
        }