public void Run() { while (true) { string input = this.userInterface.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { break; } input = input.Trim(); try { var command = new Command(input); var commandResult = this.controller.ExecuteComand(command); this.userInterface.WriteLine(commandResult); } catch (Exception ex) { this.userInterface.WriteLine(ex.Message); } } this.userInterface.Flush(); }
public static void ValidateParametersCount(Command command, int count) { if (command.Parameters.Length != count) { throw new InvalidOperationException(Constants.InvalidCommand); } }
public string ExecuteComand(Command command) { string result = string.Empty; try { switch (command.Name) { case "RegisterStationaryAirConditioner": Validators.ValidateParametersCount(command, 4); result = this.RegisterStationaryAirConditioner( command.Parameters[0], command.Parameters[1], command.Parameters[2], int.Parse(command.Parameters[3])); break; case "RegisterCarAirConditioner": Validators.ValidateParametersCount(command, 3); result = this.RegisterCarAirConditioner( command.Parameters[0], command.Parameters[1], int.Parse(command.Parameters[2])); break; case "RegisterPlaneAirConditioner": Validators.ValidateParametersCount(command, 4); result = this.RegisterPlaneAirConditioner( command.Parameters[0], command.Parameters[1], int.Parse(command.Parameters[2]), command.Parameters[3]); break; case "TestAirConditioner": Validators.ValidateParametersCount(command, 2); result = this.TestAirConditioner( command.Parameters[0], command.Parameters[1]); break; case "FindAirConditioner": Validators.ValidateParametersCount(command, 2); result = this.FindAirConditioner( command.Parameters[0], command.Parameters[1]); break; case "FindReport": Validators.ValidateParametersCount(command, 2); result = this.FindReport( command.Parameters[0], command.Parameters[1]); break; case "FindAllReportsByManufacturer": Validators.ValidateParametersCount(command, 1); result = this.FindAllReportsByManufacturer(command.Parameters[0]); break; case "Status": Validators.ValidateParametersCount(command, 0); result = this.Status(); break; default: throw new InvalidOperationException(Constants.InvalidCommand); } } catch (FormatException ex) { throw new InvalidOperationException(Constants.InvalidCommand, ex.InnerException); } return result; }