Exemplo n.º 1
0
        static void Main(string[] args)
        {
            TflClientService tflClient = new TflClientService(_response);

            _factory   = new JObjectFactory();
            _response  = new ResponseFactory();
            _validator = new RequestValidatorService(_response, _factory);

            var services = new ServiceCollection();

            //JB. Register TflClientService (httpClient for Tfl)
            services.AddHttpClient <HttpClientFactoryService>();

            var serviceProvider = services.BuildServiceProvider();

            SetUpDi(services);
            SetUpLogging(services, serviceProvider);

            //JB. Begin execution of client and configuration of the App.
            Execute(tflClient, services).Wait();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the TflClientService and executes the application logic, making sure the correct parameters are passed.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="services"></param>
        /// <returns></returns>
        static async Task Execute(TflClientService service, ServiceCollection services)
        {
            Console.WriteLine("Hello, please type below the road you want to find information:");
            daRoad = Console.ReadLine();
            if (!String.IsNullOrEmpty(daRoad))
            {
                try
                {
                    Console.WriteLine(_validator.ValidateRequest(await service.InitializeClient(daRoad, services), daRoad));
                    Console.WriteLine((int)ExitCode.Success);
                    return;
                }
                catch (InvalidRoadException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine((int)ExitCode.InvalidRequest);
                    return;
                }
            }

            Console.WriteLine(new NullRoadIdException("").Message);
            Console.WriteLine((int)ExitCode.InvalidRequest);
            return;
        }