コード例 #1
0
        public async Task <IEnumerable <Starship> > LoadStarships(StarWarsApiService service)
        {
            var returnListStarships = new List <Starship>();
            var returnFromService   = await service.GetStarships();

            while (returnFromService != null)
            {
                returnListStarships.AddRange(returnFromService.Results);

                if (!string.IsNullOrEmpty(returnFromService.Next))
                {
                    returnFromService = await service.GetStarships(returnFromService.Next);
                }
                else
                {
                    returnFromService = null;
                }
            }

            return(returnListStarships);
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            try
            {
                var httpClient              = new HttpClient();
                var service                 = new StarWarsApiService(httpClient);
                var consoleVirtual          = new ConsoleVirtual();
                var useCaseStarshipResupply = new StarshipResupplyRequired();

                var inputedDistanceMGLT = useCaseStarshipResupply.ReceiveInputedValue(consoleVirtual);

                Console.WriteLine("Please wait, loading...");

                var listOfStarships = await useCaseStarshipResupply.LoadStarships(service);

                useCaseStarshipResupply.CalculateResupplyRequired(listOfStarships, inputedDistanceMGLT, consoleVirtual);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }