public void Run() { string[] inputInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); while (inputInfo[0] != "End") { try { string command = inputInfo[0]; if (command == "CreateRider") { string name = inputInfo[1]; championshipContraller.CreateRider(name); } if (command == "CreateMotorcycle") { string type = inputInfo[1]; string model = inputInfo[2]; int horsePower = int.Parse(inputInfo[3]); championshipContraller.CreateMotorcycle(type, model, horsePower); } if (command == "AddMotorcycleToRider") { string name = inputInfo[1]; string model = inputInfo[2]; championshipContraller.AddMotorcycleToRider(name, model); } if (command == "StartRace") { string raceName = inputInfo[1]; championshipContraller.StartRace(raceName); } if (command == "AddRiderToRace") { string raceName = inputInfo[1]; string riderName = inputInfo[2]; championshipContraller.AddRiderToRace(raceName, riderName); } if (command == "CreateRace") { string name = inputInfo[1]; int laps = int.Parse(inputInfo[2]); championshipContraller.CreateRace(name, laps); } } catch (Exception ex) { Console.WriteLine(ex.Message); } inputInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); } }
public void Run() { while (true) { var input = reader.ReadLine(); if (input == "End") { Environment.Exit(0); } var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); try { if (args[0] == "CreateRider") { writer.WriteLine(controller.CreateRider(args[1])); } else if (args[0] == "CreateMotorcycle") { writer.WriteLine(controller.CreateMotorcycle(args[1], args[2], int.Parse(args[3]))); } else if (args[0] == "AddMotorcycleToRider") { writer.WriteLine(controller.AddMotorcycleToRider(args[1], args[2])); } else if (args[0] == "AddRiderToRace") { writer.WriteLine(controller.AddRiderToRace(args[1], args[2])); } else if (args[0] == "CreateRace") { writer.WriteLine(controller.CreateRace(args[1], int.Parse(args[2]))); } else if (args[0] == "StartRace") { writer.WriteLine(controller.StartRace(args[1])); } } catch (Exception ex) { writer.WriteLine(ex.Message); //writer.WriteLine(ex.ToString()); } } }
public void Run() { while (true) { string command = consoleReader.ReadLine(); string output = string.Empty; if (command == "End") { break; } string[] info = command.Split(" ", StringSplitOptions.RemoveEmptyEntries); string method = info[0]; try { if (method == "CreateRider") { string riderName = info[1]; output = controller.CreateRider(riderName); } else if (method == "CreateMotorcycle") { string motorcycleType = info[1]; string model = info[2]; int horsepower = int.Parse(info[3]); output = controller.CreateMotorcycle(motorcycleType, model, horsepower); } else if (method == "AddMotorcycleToRider") { string name = info[1]; string motorcycleName = info[2]; output = controller.AddMotorcycleToRider(name, motorcycleName); } else if (method == "AddRiderToRace") { string raceName = info[1]; string riderName = info[2]; output = controller.AddRiderToRace(raceName, riderName); } else if (method == "CreateRace") { string name = info[1]; int laps = int.Parse(info[2]); output = controller.CreateRace(name, laps); } else if (method == "StartRace") { string raceName = info[1]; output = controller.StartRace(raceName); } consoleWriter.WriteLine(output); } catch (Exception ex) { this.consoleWriter.WriteLine(ex.Message); } } }
public void Run() { string input; while ((input = reader.ReadLine()) != "End") { string[] splitInput = input.Split(" "); try { switch (splitInput[0]) { case "CreateRider": { string name = splitInput[1]; writer.WriteLine(champController.CreateRider(name)); } break; case "CreateMotorcycle": { string type = splitInput[1]; string model = splitInput[2]; int horsePower = int.Parse(splitInput[3]); writer.WriteLine(champController.CreateMotorcycle(type, model, horsePower)); } break; case "AddMotorcycleToRider": { string name = splitInput[1]; string motorName = splitInput[2]; writer.WriteLine(champController.AddMotorcycleToRider(name, motorName)); } break; case "AddRiderToRace": { string raceName = splitInput[1]; string riderName = splitInput[2]; writer.WriteLine(champController.AddRiderToRace(raceName, riderName)); } break; case "CreateRace": { string name = splitInput[1]; int laps = int.Parse(splitInput[2]); writer.WriteLine(champController.CreateRace(name, laps)); } break; case "StartRace": { string name = splitInput[1]; writer.WriteLine(champController.StartRace(name)); } break; } } catch (Exception ex) { if (ex is TargetInvocationException) { Console.WriteLine(ex.InnerException.Message); } else { Console.WriteLine(ex.Message); } continue; } } }
public void Run() { while (true) { string[] inputInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string command = inputInfo[0]; if (command == "End") { break; } else if (command == "CreateRider") { string name = inputInfo[1]; Console.WriteLine(championshipController.CreateRider(name)); } else if (command == "CreateMotorcycle") { string type = inputInfo[1]; string model = inputInfo[2]; int horsepower = int.Parse(inputInfo[3]); Console.WriteLine(championshipController.CreateMotorcycle(type, model, horsepower)); } else if (command == "AddMotorcycleToRider") { string riderName = inputInfo[1]; string motorcycleName = inputInfo[2]; Console.WriteLine(championshipController.AddMotorcycleToRider(riderName, motorcycleName)); } else if (command == "AddRiderToRace") { string raceName = inputInfo[1]; string riderName = inputInfo[2]; Console.WriteLine(championshipController.AddRiderToRace(raceName, riderName)); } else if (command == "CreateRace") { string name = inputInfo[1]; int laps = int.Parse(inputInfo[2]); Console.WriteLine(championshipController.CreateRace(name, laps)); } else if (command == "StartRace") { string name = inputInfo[1]; Console.WriteLine(championshipController.StartRace(name)); } } }
public void Run() { StringBuilder sb = new StringBuilder(); string input = consoleReader.ReadLine(); while (input != "End") { string[] arr = input.Split(); string typeOfCommand = arr[0]; try { switch (typeOfCommand) { case "CreateRider": string name = arr[1]; sb.AppendLine(this.championshipController.CreateRider(name)); break; case "CreateMotorcycle": string motorcycleType = arr[1]; string model = arr[2]; string horsepower = arr[3]; sb.AppendLine(championshipController.CreateMotorcycle(motorcycleType, model, int.Parse(horsepower))); break; case "AddMotorcycleToRider": string riderName = arr[1]; string motorcycleName = arr[2]; sb.AppendLine(championshipController.AddMotorcycleToRider(riderName, motorcycleName)); break; case "AddRiderToRace": string raceName = arr[1]; string currentRiderName = arr[2]; sb.AppendLine(championshipController.AddRiderToRace(raceName, currentRiderName)); break; case "CreateRace": string currentName = arr[1]; string laps = arr[2]; sb.AppendLine(championshipController.CreateRace(currentName, int.Parse(laps))); break; case "StartRace": string currentRaceName = arr[1]; sb.AppendLine(championshipController.StartRace(currentRaceName)); break; } } catch (Exception ex) { sb.AppendLine(ex.Message); } input = consoleReader.ReadLine(); } consoleWriter.WriteLine(sb.ToString().TrimEnd()); }
public void Run() { while (true) { string[] input = reader.ReadLine().Split(); if (input[0] == "End") { Environment.Exit(0); } try { string result = string.Empty; if (input[0] == "CreateRider") { string riderName = input[1]; result = controller.CreateRider(riderName); } else if (input[0] == "CreateMotorcycle") { string type = input[1]; string model = input[2]; int horsePower = int.Parse(input[3]); result = controller.CreateMotorcycle(type, model, horsePower); } else if (input[0] == "AddMotorcycleToRider") { string riderName = input[1]; string motorcycleModel = input[2]; result = controller.AddMotorcycleToRider(riderName, motorcycleModel); } else if (input[0] == "AddRiderToRace") { string raceName = input[1]; string riderName = input[2]; result = controller.AddRiderToRace(raceName, riderName); } else if (input[0] == "CreateRace") { string name = input[1]; int laps = int.Parse(input[2]); result = controller.CreateRace(name, laps); } else if (input[0] == "StartRace") { string raceName = input[1]; result = controller.StartRace(raceName); } writer.WriteLine(result); } catch (Exception ex) { writer.WriteLine(ex.Message); } } }