Пример #1
0
        public string Execute(Command engineCommand)
        {
            this.command = engineCommand;

            switch (this.command.Name)
            {
                case "RegisterStationaryAirConditioner":
                    this.ValidateParametersCount(4);
                    this.commandMessage = this.RegisterStationaryAirConditioner(
                        this.command.Parameters[0],
                        this.command.Parameters[1],
                        this.command.Parameters[2],
                        int.Parse(this.command.Parameters[3]));
                    break;
                case "RegisterCarAirConditioner":
                    this.ValidateParametersCount(3);
                    this.commandMessage = this.RegisterCarAirConditioner(
                        this.command.Parameters[0],
                        this.command.Parameters[1],
                        int.Parse(this.command.Parameters[2]));
                    break;
                case "RegisterPlaneAirConditioner":
                    this.ValidateParametersCount(4);
                    this.commandMessage = this.RegisterPlaneAirConditioner(
                        this.command.Parameters[0],
                        this.command.Parameters[1],
                        int.Parse(this.command.Parameters[2]),
                        this.command.Parameters[3]);
                    break;
                case "TestAirConditioner":
                    this.ValidateParametersCount(2);
                    this.commandMessage = this.TestAirConditioner(
                        this.command.Parameters[0],
                        this.command.Parameters[1]);
                    break;
                case "FindAirConditioner":
                    this.ValidateParametersCount(2);
                    this.commandMessage = this.FindAirConditioner(
                        this.command.Parameters[0],
                        this.command.Parameters[1]);
                    break;
                case "FindReport":
                    this.ValidateParametersCount(2);
                    this.commandMessage = this.FindReport(this.command.Parameters[0], this.command.Parameters[1]);
                    break;
                case "Status":
                    this.ValidateParametersCount(0);
                    this.commandMessage = this.Status();
                    break;
                case "FindAllReportsByManufacturer":
                    this.ValidateParametersCount(1);
                    this.commandMessage = this.FindAllReportsByManufacturer(this.command.Parameters[0]);
                    break;
                default:
                    throw new ArgumentException(Constants.InvalidCommand);
            }

            return this.commandMessage;
        }
Пример #2
0
        public void Run()
        {
            while (true)
            {
                string line = this.userInterface.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                line = line.Trim();
                try
                {
                    this.command = new Command(line);
                    string commandMessage = this.ac.Execute(this.command);

                    this.userInterface.WriteLine(commandMessage);
                }
                catch (DuplicateEntryException ex)
                {
                    this.userInterface.WriteLine(ex.Message);
                }
                catch (NonExistantEntryException ex)
                {
                    this.userInterface.WriteLine(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    this.userInterface.WriteLine(ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    this.userInterface.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(this.userInterface.result);
        }