private static Command CreateCommand(string command, int numberOfCommand) { string[] wordsArr = command.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); string name = wordsArr[0].ToLower(); List <string> args = new List <string>(); for (int i = 1; i < wordsArr.Length; ++i) { args.Add(wordsArr[i]); } switch (name) { case "echo": { Command result = new Echo(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0); if (result.IsCorrectArgs()) { return(result); } break; } case "cat": { Command result = new Cat(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0); if (result.IsCorrectArgs()) { return(result); } break; } case "pwd": { Command result = new Pwd(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0); if (result.IsCorrectArgs()) { return(result); } break; } case "wc": { Command result = new Wc(args, Path.GetTempPath() + "\\tmpResult" + numberOfCommand + ".txt", numberOfCommand == 0); if (result.IsCorrectArgs()) { return(result); } break; } case "exit": { Command result = new Exit(args); if (result.IsCorrectArgs()) { return(result); } break; } } throw new CommandException("Incorrect command name"); }