Exemplo n.º 1
0
        public static async Task <StarWarsEntityList <Starship> > GetStarships(string stops, double inputDist)
        {
            var api = new StarWarsAPIClient();

            // Get first page of all starships available
            StarWarsEntityList <Starship> _lstStarships = await api.GetAllStarship("1");

            // Get the number of pages
            int totalPages = Convert.ToInt32(Math.Ceiling(((double)_lstStarships.count / _lstStarships.results.Count())));

            // While loop to filter through all pages of data returned (data returns results in groups of 10)
            for (int pageNum = 1; pageNum < totalPages + 1; pageNum++)
            {
                if (pageNum != 1) // Skip recalling page 1. Only needs recallinging for changing to pages that follow
                {
                    _lstStarships = await api.GetAllStarship(pageNum.ToString());
                }


                foreach (Starship s in _lstStarships.results)
                {
                    stops = CalculateStops(s.consumables, s.MGLT, inputDist);

                    Console.WriteLine(string.Format("{0}: {1}", s.name, stops));
                }
            }

            return(_lstStarships);
        }
Exemplo n.º 2
0
        public List <Starship> GetAllFromApi()
        {
            var api = new StarWarsAPIClient();

            var starships = new List <Starship>();

            int pageNo = 0;

            while (true)
            {
                var page = api.GetAllStarship((++pageNo).ToString());

                starships.AddRange(page.Result.results.Select(x => mapper.GetStarship(x)));

                if (!page.Result.isNext)
                {
                    break;
                }
            }

            return(starships);
        }
Exemplo n.º 3
0
        public async Task <List <Starship> > GetAll()
        {
            var api = new StarWarsAPIClient();

            var starships = new List <Starship>();

            int pageNo = 0;

            while (true)
            {
                var page = await api.GetAllStarship((++pageNo).ToString());

                starships.AddRange(page.results.Select(x => model.GetStarship(x)));

                if (!page.isNext)
                {
                    break;
                }
            }

            return(starships);
        }