示例#1
0
        public string Execute(string[] input)
        {
            try
            {
                switch (input[0])
                {
                case "CreateRider":
                    return(controller.CreateRider(input[1]));

                case "CreateMotorcycle":
                    return(controller.CreateMotorcycle(input[1], input[2], int.Parse(input[3])));

                case "AddMotorcycleToRider":
                    return(controller.AddMotorcycleToRider(input[1], input[2]));

                case "AddRiderToRace":
                    return(controller.AddRiderToRace(input[1], input[2]));

                case "CreateRace":
                    return(controller.CreateRace(input[1], int.Parse(input[2])));

                case "StartRace":
                    return(controller.StartRace(input[1]));
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
示例#2
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (true)
            {
                string[] inputTokens = input.Split();
                string   result      = string.Empty;

                try
                {
                    switch (inputTokens[0])
                    {
                    case "CreateRider":
                        result = championshipController.CreateRider(inputTokens[1]);
                        break;

                    case "CreateMotorcycle":
                        result = championshipController.CreateMotorcycle(inputTokens[1], inputTokens[2], int.Parse(inputTokens[3]));
                        break;

                    case "AddMotorcycleToRider":
                        result = championshipController.AddMotorcycleToRider(inputTokens[1], inputTokens[2]);
                        break;

                    case "AddRiderToRace":
                        result = championshipController.AddRiderToRace(inputTokens[1], inputTokens[2]);
                        break;

                    case "CreateRace":
                        result = championshipController.CreateRace(inputTokens[1], int.Parse(inputTokens[2]));
                        break;

                    case "StartRace":
                        result = championshipController.StartRace(inputTokens[1]);
                        break;

                    case "End":
                        championshipController.End();
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (!string.IsNullOrWhiteSpace(result))
                {
                    Console.WriteLine(result);
                }
                input = Console.ReadLine();
            }
        }
示例#3
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string[] tokens = Console.ReadLine()
                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                    if (tokens[0].ToLower() == "end")
                    {
                        Environment.Exit(0);
                    }

                    if (tokens[0] == "CreateRider")
                    {
                        writer.WriteLine(championshipController.CreateRider(tokens[1]));
                    }
                    else if (tokens[0] == "CreateMotorcycle")
                    {
                        writer.WriteLine(championshipController
                                         .CreateMotorcycle(tokens[1], tokens[2], int.Parse(tokens[3])));
                    }
                    else if (tokens[0] == "AddMotorcycleToRider")
                    {
                        writer.WriteLine(championshipController
                                         .AddMotorcycleToRider(tokens[1], tokens[2]));
                    }
                    else if (tokens[0] == "AddRiderToRace")
                    {
                        writer.WriteLine(championshipController
                                         .AddRiderToRace(tokens[1], tokens[2]));
                    }
                    else if (tokens[0] == "CreateRace")
                    {
                        writer.WriteLine(championshipController
                                         .CreateRace(tokens[1], int.Parse(tokens[2])));
                    }
                    else if (tokens[0] == "StartRace")
                    {
                        writer.WriteLine(championshipController.StartRace(tokens[1]));
                    }
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                    continue;
                }
            }
        }
示例#4
0
        public void Run()
        {
            string input = string.Empty;
            IChampionshipController championship = new ChampionshipController();

            while ((input = Console.ReadLine()) != "End")
            {
                string[] command = input.Split();
                try
                {
                    if (command[0] == "CreateRider")
                    {
                        Console.WriteLine(championship.CreateRider(command[1]));
                    }
                    else if (command[0] == "CreateMotorcycle")
                    {
                        Console.WriteLine(championship.CreateMotorcycle(command[1], command[2], int.Parse(command[3])));
                    }
                    else if (command[0] == "CreateRace")
                    {
                        Console.WriteLine(championship.CreateRace(command[1], int.Parse(command[2])));
                    }
                    else if (command[0] == "AddMotorcycleToRider")
                    {
                        Console.WriteLine(championship.AddMotorcycleToRider(command[1], command[2]));
                    }
                    else if (command[0] == "StartRace")
                    {
                        Console.WriteLine(championship.StartRace(command[1]));
                    }
                    else if (command[0] == "AddRiderToRace")
                    {
                        Console.WriteLine(championship.AddRiderToRace(command[1], command[2]));
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }
            }
        }
示例#5
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string[] input = reader.ReadLine().Split();

                    if (input[0] == "End")
                    {
                        break;
                    }

                    if (input[0] == "CreateRider")
                    {
                        writer.WriteLine(controller.CreateRider(input[1]));
                    }
                    else if (input[0] == "CreateMotorcycle")
                    {
                        writer.WriteLine(controller.CreateMotorcycle(input[1], input[2], int.Parse(input[3])));
                    }
                    else if (input[0] == "AddMotorcycleToRider")
                    {
                        writer.WriteLine(controller.AddMotorcycleToRider(input[1], input[2]));
                    }
                    else if (input[0] == "AddRiderToRace")
                    {
                        writer.WriteLine(controller.AddRiderToRace(input[1], input[2]));
                    }
                    else if (input[0] == "CreateRace")
                    {
                        writer.WriteLine(controller.CreateRace(input[1], int.Parse(input[2])));
                    }
                    else if (input[0] == "StartRace")
                    {
                        writer.WriteLine(controller.StartRace(input[1]));
                    }
                }
                catch (Exception e)
                {
                    writer.WriteLine(e.Message);
                }
            }
        }
示例#6
0
        public void Run()
        {
            var championshipController = new ChampionshipController();

            while (true)
            {
                var input = ConsoleReader.ReadLine();

                if (input == "End")
                {
                    break;
                }

                var splitInput = input.Split();
                var command    = splitInput[0];

                try
                {
                    switch (command)
                    {
                    case "CreateRider":
                        var riderName = splitInput[1];
                        this.ConsoleWriter.WriteLine(championshipController.CreateRider(riderName));
                        break;

                    case "CreateMotorcycle":
                        var type       = splitInput[1];
                        var model      = splitInput[2];
                        var horsePower = int.Parse(splitInput[3]);
                        this.ConsoleWriter.WriteLine(championshipController.CreateMotorcycle(type, model, horsePower));
                        break;

                    case "AddMotorcycleToRider":
                        riderName = splitInput[1];
                        var motorcycleModel = splitInput[2];
                        this.ConsoleWriter.WriteLine(championshipController.AddMotorcycleToRider(riderName, motorcycleModel));
                        break;

                    case "AddRiderToRace":
                        var raceName = splitInput[1];
                        riderName = splitInput[2];
                        this.ConsoleWriter.WriteLine(championshipController.AddRiderToRace(raceName, riderName));
                        break;

                    case "CreateRace":
                        raceName = splitInput[1];
                        var laps = int.Parse(splitInput[2]);
                        this.ConsoleWriter.WriteLine(championshipController.CreateRace(raceName, laps));
                        break;

                    case "StartRace":
                        raceName = splitInput[1];
                        this.ConsoleWriter.WriteLine(championshipController.StartRace(raceName));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    this.ConsoleWriter.WriteLine(ex.Message);
                }
            }
        }
示例#7
0
        public void Run()
        {
            while (true)
            {
                var command = this.reader.ReadLine();
                if (command == "End")
                {
                    break;
                }

                try
                {
                    var commandResult = ProcessCommand(command);
                    this.writer.WriteLine(commandResult);
                }
                catch (ArgumentException e)
                {
                    writer.WriteLine(e.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    writer.WriteLine(ioe.Message);
                }
            }

            string ProcessCommand(string command)
            {
                var commandArgs = command.Split(' ');
                var commandName = commandArgs[0];
                var args        = commandArgs.Skip(1).ToArray();

                var output = string.Empty;

                switch (commandName)
                {
                case "CreateRider":
                {
                    var name = args[0];

                    output = chshcon.CreateRider(name);
                    break;
                }

                case "CreateMotorcycle":
                {
                    var type       = args[0];
                    var name       = args[1];
                    var horsePower = int.Parse(args[2]);
                    output = chshcon.CreateMotorcycle(type, name, horsePower);
                    break;
                }

                case "AddMotorcycleToRider":
                {
                    var riderName       = args[0];
                    var motorcycleModel = args[1];

                    output = chshcon.AddMotorcycleToRider(riderName, motorcycleModel);
                    break;
                }

                case "CreateRace":
                {
                    var raceName = args[0];
                    var laps     = int.Parse(args[1]);

                    output = chshcon.CreateRace(raceName, laps);
                    break;
                }

                case "AddRiderToRace":
                {
                    var raceName  = args[0];
                    var riderName = args[1];

                    output = chshcon.AddRiderToRace(raceName, riderName);
                    break;
                }

                case "StartRace":
                {
                    var raceName = args[0];

                    output = chshcon.StartRace(raceName);
                    break;
                }
                }

                return(output);
            }
        }
示例#8
0
        public void Run()
        {
            while (true)
            {
                string[] input = reader.ReadLine().Split();
                if (input[0] == "Exit")
                {
                    Environment.Exit(0);
                }
                //
                try
                {
                    //
                    string result = string.Empty;

                    if (input[0] == "CreateRider")
                    {
                        string name = input[1];


                        result = championshipController.CreateRider(name);
                    }
                    else if (input[0] == "CreateMotorcycle")
                    {
                        string type       = input[1];
                        string model      = input[2];
                        int    horsePower = int.Parse(input[3]);

                        result = championshipController.CreateMotorcycle(type, model, horsePower);
                    }
                    else if (input[0] == "AddMotorcycleToRider")
                    {
                        string riderName = input[1];
                        string motorName = input[2];

                        result = championshipController.AddMotorcycleToRider(riderName, motorName);
                    }
                    else if (input[0] == "AddRiderToRace")
                    {
                        string raceName  = input[1];
                        string riderName = input[2];


                        result = championshipController.AddRiderToRace(raceName, riderName);
                    }
                    else if (input[0] == "CreateRace")
                    {
                        string name = input[1];
                        int    laps = int.Parse(input[2]);


                        result = championshipController.CreateRace(name, laps);
                    }
                    else if (input[0] == "StartRace")
                    {
                        string name = input[1];

                        result = championshipController.StartRace(name);
                    }


                    writer.WriteLine(result);
                    //
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.Message);
                }
                //
            }
        }
示例#9
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string[] input = Console.ReadLine()
                                     .Split();

                    string command = input[0];

                    if (command == "End")
                    {
                        break;
                    }

                    string result = string.Empty;
                    switch (command)
                    {
                    case "CreateRider":
                        string name = input[1];
                        result = controller.CreateRider(name);
                        break;

                    case "CreateMotorcycle":
                        string motorcycleType  = input[1];
                        string motorcycleModel = input[2];
                        int    motorcycleHp    = int.Parse(input[3]);
                        result = controller.CreateMotorcycle(motorcycleType, motorcycleModel, motorcycleHp);
                        break;

                    case "AddMotorcycleToRider":
                        string riderName      = input[1];
                        string motorcycleName = input[2];
                        result = controller.AddMotorcycleToRider(riderName, motorcycleName);
                        break;

                    case "AddRiderToRace":
                        string raceName = input[1];
                        riderName = input[2];
                        result    = controller.AddRiderToRace(raceName, riderName);
                        break;

                    case "CreateRace":
                        raceName = input[1];
                        int laps = int.Parse(input[2]);
                        result = controller.CreateRace(raceName, laps);
                        break;

                    case "StartRace":
                        raceName = input[1];
                        result   = controller.StartRace(raceName);
                        break;

                    default:
                        break;
                    }

                    Console.WriteLine(result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message}");
                }
            }
        }
示例#10
0
        public void Run()
        {
            while (true)
            {
                string[] input = Console.ReadLine().Split();
                if (input[0] == "End")
                {
                    break;
                }

                StringBuilder result = new StringBuilder();

                string command = input[0];

                try
                {
                    switch (command)
                    {
                    case "CreateRider":
                    {
                        string name = input[1];

                        result.AppendLine(controller.CreateRider(name));
                    }
                    break;

                    case "CreateMotorcycle":
                    {
                        string type       = input[1];
                        string model      = input[2];
                        int    horsePower = int.Parse(input[3]);

                        result.AppendLine(controller.CreateMotorcycle(type, model, horsePower));
                    }
                    break;

                    case "AddMotorcycleToRider":
                    {
                        string riderName = input[1];
                        string motoName  = input[2];

                        result.AppendLine(controller.AddMotorcycleToRider(riderName, motoName));
                    }
                    break;

                    case "AddRiderToRace":
                    {
                        string raceName  = input[1];
                        string riderName = input[2];

                        result.AppendLine(controller.AddRiderToRace(raceName, riderName));
                    }
                    break;

                    case "CreateRace":
                    {
                        string name = input[1];
                        int    laps = int.Parse(input[2]);

                        result.AppendLine(controller.CreateRace(name, laps));
                    }
                    break;

                    case "StartRace":
                    {
                        string name = input[1];

                        result.AppendLine(controller.StartRace(name));
                    }
                    break;

                    default: break;
                    }
                }
                catch (Exception e)
                {
                    result.AppendLine(e.Message);
                }

                Console.WriteLine(result.ToString().TrimEnd());
            }
        }
示例#11
0
        public void Run()
        {
            ChampionshipController controler = new ChampionshipController();

            string command = Console.ReadLine();

            while (command != "End")
            {
                try
                {
                    var commandPasser = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    if (commandPasser[0] == "CreateRider")
                    {
                        string nameRider = commandPasser[1];
                        string result    = controler.CreateRider(nameRider);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (commandPasser[0] == "CreateMotorcycle")
                    {
                        // Speed Honda 60
                        string type       = commandPasser[1];
                        string model      = commandPasser[2];
                        int    horsePower = int.Parse(commandPasser[3]);
                        string result     = controler.CreateMotorcycle(type, model, horsePower);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (commandPasser[0] == "CreateRace")
                    {
                        //Loket 2
                        string nameRace = commandPasser[1];
                        int    laps     = int.Parse(commandPasser[2]);
                        string result   = controler.CreateRace(nameRace, laps);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (commandPasser[0] == "AddMotorcycleToRider")
                    {
                        string riderName = commandPasser[1];
                        string motorName = commandPasser[2];
                        string result    = controler.AddMotorcycleToRider(riderName, motorName);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (commandPasser[0] == "StartRace")
                    {
                        string nameRase = commandPasser[1];
                        string result   = controler.StartRace(nameRase);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (commandPasser[0] == "AddRiderToRace")
                    {
                        string nameRase  = commandPasser[1];
                        string nameRider = commandPasser[2];
                        string result    = controler.AddRiderToRace(nameRase, nameRider);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result);
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ForegroundColor = ConsoleColor.White;
                }

                command = Console.ReadLine();
            }
        }
示例#12
0
        public void Run()
        {
            ConsoleReader          consoleReader = new ConsoleReader();
            ConsoleWriter          consoleWriter = new ConsoleWriter();
            ChampionshipController championship  = new ChampionshipController();

            var input = consoleReader.ReadLine();

            string riderName = string.Empty;
            string raceName  = string.Empty;

            while (input != "End")
            {
                var inputArgs = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                try
                {
                    switch (inputArgs[0])
                    {
                    case "CreateRider":

                        riderName = inputArgs[1];
                        consoleWriter.WriteLine(championship.CreateRider(riderName));
                        break;

                    case "CreateMotorcycle":

                        string motorcycleType = inputArgs[1];
                        string model          = inputArgs[2];
                        int    horsepower     = int.Parse(inputArgs[3]);

                        consoleWriter.WriteLine(championship.CreateMotorcycle(motorcycleType, model, horsepower));
                        break;

                    case "AddMotorcycleToRider":

                        riderName = inputArgs[1];
                        string motorcycle = inputArgs[2];

                        consoleWriter.WriteLine(championship.AddMotorcycleToRider(riderName, motorcycle));
                        break;

                    case "AddRiderToRace":

                        raceName  = inputArgs[1];
                        riderName = inputArgs[2];

                        consoleWriter.WriteLine(championship.AddRiderToRace(raceName, riderName));
                        break;

                    case "CreateRace":

                        raceName = inputArgs[1];
                        int laps = int.Parse(inputArgs[2]);

                        consoleWriter.WriteLine(championship.CreateRace(raceName, laps));
                        break;

                    case "StartRace":

                        raceName = inputArgs[1];
                        consoleWriter.WriteLine(championship.StartRace(raceName));
                        break;

                    default:
                        break;
                    }
                }
                catch (ArgumentNullException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                input = consoleReader.ReadLine();
            }
        }
示例#13
0
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (input == "End")
                {
                    break;
                }

                string[] inputArgs = input.Split();

                string command = inputArgs[0];

                try
                {
                    if (command == "CreateRider")
                    {
                        string name = inputArgs[1];
                        Console.WriteLine(controller.CreateRider(name));
                    }
                    else if (command == "CreateMotorcycle")
                    {
                        string type       = inputArgs[1];
                        string model      = inputArgs[2];
                        int    horsePower = int.Parse(inputArgs[3]);

                        Console.WriteLine(controller.CreateMotorcycle(type, model, horsePower));
                    }
                    else if (command == "AddMotorcycleToRider")
                    {
                        string riderName      = inputArgs[1];
                        string motorcycleName = inputArgs[2];

                        Console.WriteLine(controller.AddMotorcycleToRider(riderName, motorcycleName));
                    }
                    else if (command == "AddRiderToRace")
                    {
                        string raceName  = inputArgs[1];
                        string riderName = inputArgs[2];

                        Console.WriteLine(controller.AddRiderToRace(raceName, riderName));
                    }
                    else if (command == "CreateRace")
                    {
                        string name = inputArgs[1];
                        int    laps = int.Parse(inputArgs[2]);

                        Console.WriteLine(controller.CreateRace(name, laps));
                    }
                    else if (command == "StartRace")
                    {
                        string raceName = inputArgs[1];

                        Console.WriteLine(controller.StartRace(raceName));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }