Пример #1
0
        public void AddModel()
        {
            commandLine.Write("Add new aircraft model.");
            commandLine.Write("Enter Make:");
            string make = commandLine.Read();

            commandLine.Write("Enter Model:");
            string        model         = commandLine.Read();
            int           speed         = commandLine.ReadInt("Enter Model speed in km/h. (Average speed is 828 km/h):");
            int           numberOfSeats = commandLine.ReadInt("Enter Number of seats:");
            AircraftModel aircraftModel = new AircraftModel(make, model, speed, numberOfSeats);

            store.AddModel(aircraftModel);
            commandLine.Write($"Successfully added model: {aircraftModel}");
        }
Пример #2
0
        public void Run()
        {
            RegisterCommands();
            cli.DisplayApplicationName();
            while (true)
            {
                commandLine.Write("Available sections: model, airplane, airport, flight, exit");
                commandLine.Write("What do you want to do next:");
                string help = commandLine.Read();

                if (help.ToLower() == "exit")
                {
                    Exit();
                }
                else
                {
                    if (cli.ReturnCommand(help.ToLower()))
                    {
                        cli.HandleCommand(help.ToLower());
                    }
                    else
                    {
                        cli.DisplayHelp(help);
                        cli.HandleCommand();
                    }
                }
            }
        }
Пример #3
0
        public void AddAirplane()
        {
            commandLine.Write("Add new airplane.");

            if (aircraftModelManager.ModelsCount().Equals(0))
            {
                commandLine.Write("Add at least one aircraft model.");
                return;
            }

            Airplane airplane = new Airplane(GetAircraftModel());

            airplane.MaintenanceTime = TimeSpan.FromMinutes(120);
            commandLine.Write("Enter airport of origin.");
            airplane.AirportCode = commandLine.Read().ToUpper();
            airplaneStore.AddAirplane(airplane);
            commandLine.Write($"Successfully added airplane: {airplane}");
        }
Пример #4
0
        private DateTime ReadDate()
        {
            DateTime dateValue;
            string   dateString;

            do
            {
                commandLine.Write("Format: DD/MM/YYYY HH:MM:");
                dateString = commandLine.Read();
            }while (!DateTime.TryParseExact(dateString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue));

            return(dateValue);
        }
Пример #5
0
        public void HandleCommand()
        {
            string commandName = commandLine.Read();
            Action handler;

            if (handlers.TryGetValue(commandName, out handler))
            {
                handler();
            }
            else
            {
                DisplayInvalidCommandMessage(commandName);
            }
        }
Пример #6
0
        public static int ReadInt(this ICommandLine commandLine, string message, bool allowEmpty = false)
        {
            int    value = 0;
            string input;

            do
            {
                commandLine.Write(message);
                input = commandLine.Read();

                if (allowEmpty && string.IsNullOrWhiteSpace(input))
                {
                    break;
                }
            }while (!int.TryParse(input, out value) || value == 0);

            return(value);
        }
Пример #7
0
        public void AddAirport()
        {
            commandLine.Write("Add new Airport.");
            commandLine.Write("Enter City:");
            string city = commandLine.Read();

            while (AnalyzeString(city) == null)
            {
                city = commandLine.Read();
            }

            commandLine.Write("Enter Country:");
            string country = commandLine.Read();

            while (AnalyzeString(country) == null)
            {
                country = commandLine.Read();
            }

            commandLine.Write("Enter Name:");
            string name = ReadAirportName();

            while (AnalyzeString(name) == null)
            {
                name = commandLine.Read();
            }

            commandLine.Write("Enter Code:");
            string code = ReadAirportCode();

            while (AnalyzeString(code) == null)
            {
                code = commandLine.Read();
            }

            int freeGates = commandLine.ReadInt("Enter number of free gates:");

            Airport airport = new Airport(code, name, city, country, freeGates);

            airportStore.AddAirport(airport);
            commandLine.Write($"Successfully added airport: {airport}");
        }