Ejemplo n.º 1
0
        /// <summary>
        /// Main method that processes the request
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <KneatView> Process(GetStarShipRequest request)
        {
            dataResult = new KneatView();

            var response = await _swapiService.GetStarShipAsync();

            Calculate(response, request.Distance);

            while (!string.IsNullOrEmpty(response.Next))
            {
                response = await _swapiService.GetStarShipAsync(response.Next);

                Calculate(response, request.Distance);
            }

            return(dataResult);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var serviceProvider = Launch();

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Type the distance and press ENTER (ESC to cancel)");

                var t = ReadLineWithCancel();

                if (t == null)
                {
                    Environment.Exit(0);
                }

                Console.WriteLine(Environment.NewLine);
                Console.WriteLine("Processing...");

                var service = serviceProvider.GetService <IKneatService>();

                long.TryParse(t, out var dist);

                var request = new GetStarShipRequest {
                    Distance = dist
                };

                var result = service.Process(request).Result;

                Console.WriteLine(Environment.NewLine);

                Console.WriteLine($" ===== Total starships: {result.Items.Count} ====== (Sorted by name)");
                foreach (var item in result.Items.OrderBy(x => x.Name))
                {
                    Console.WriteLine($"Name: {item.Name} - NumberStops: {item.NumberStops}");
                }

                if (!result.Success)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(result.ErrorMessage);
                }

                Console.WriteLine(Environment.NewLine);
            }
        }