internal static RectangleCommand CreateCommand( string[] parameters ) { // Validate Mandatory if (parameters.Length != 4) { throw new InvalidCommandParamsException("Expected 4 parameters but received " + parameters.Length); } try { RectangleCommand command = new RectangleCommand( Utils.FormatPositiveInt(parameters[0]), Utils.FormatPositiveInt(parameters[1]), Utils.FormatPositiveInt(parameters[2]), Utils.FormatPositiveInt(parameters[3]) ); return(command); } catch (Exception ex) { throw new InvalidCommandParamsException("Invalid parameter/s " + String.Join(" ", parameters) + ". \n" + GetHelp(), ex); } }
public static CommandEntity GetCommand( string commandLine ) { string cleanedString = System.Text.RegularExpressions.Regex.Replace(commandLine.Trim(), @"\s+", " "); string[] split = cleanedString.Split(' '); int paramcount = split.Length - 1; string[] parameters = new string[paramcount]; Array.Copy(split, 1, parameters, 0, paramcount); switch (split[0].ToUpper()) { case "Q": return(QuitCommand.CreateCommand(parameters)); case "C": return(CanvasCommand.CreateCommand(parameters)); case "L": return(LineCommand.CreateCommand(parameters)); case "R": return(RectangleCommand.CreateCommand(parameters)); case "B": return(BucketCommand.CreateCommand(parameters)); default: string helpMessage = HelpCommand.CreateCommand().Message; throw new InvalidCommandException("Unknown command \n" + helpMessage); } }
internal static HelpCommand CreateCommand() { StringBuilder sb = new StringBuilder(); sb.Append(CanvasCommand.GetHelp()); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(LineCommand.GetHelp()); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(RectangleCommand.GetHelp()); sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); sb.Append(QuitCommand.GetHelp()); HelpCommand command = new HelpCommand(sb.ToString()); return(command); }