Beispiel #1
0
        static void Main(string[] args)
        {
            ServiceProvider serviceProvider = Setup();

            if (args.Length != 1)
            {
                throw new Exception("A solução deve receber somente um parametro, com o caminho para o arquivo de input");
            }

            String pathFile = args[0];

            IValidationBusiness  validationBusiness = serviceProvider.GetService <IValidationBusiness>();
            ITravelPathBusiness  travelPathBusiness = serviceProvider.GetService <ITravelPathBusiness>();
            IAirportBusiness     airportBusiness    = serviceProvider.GetService <IAirportBusiness>();
            IReadDestinationFile fileReader         = serviceProvider.GetService <IReadDestinationFile>();

            airportBusiness.Initialize(pathFile, fileReader);

            while (true)
            {
                Console.WriteLine("Por favor, entre a rota no formato AAA-BBB:");
                String strLine = Console.ReadLine();
                validationBusiness.ValidateInput(strLine, airportBusiness.GetAirportList());
                TravelPath path = travelPathBusiness.FindBestPath(strLine, airportBusiness.GetAirportList());
                Console.WriteLine(travelPathBusiness.GenerateOutput(path));
            }
        }
Beispiel #2
0
        public TravelPath FindBestPath(string origin, string destination, IEnumerable <Airport> lstAirport)
        {
            validation.ValidateInput(origin, destination, lstAirport);
            var result = ((List <Airport>)lstAirport).Find(t => t.name == origin).FindAllPaths(destination, null);

            if (result.Count() == 0)
            {
                throw new Exception("Não foi possível encontrar um caminho");
            }
            else
            {
                return(result.OrderBy(p => p.calculateCost()).First());
            }
        }