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);
            }
        }
Exemple #2
0
        internal static QuitCommand CreateCommand(
            string[] parameters
            )
        {
            // Validate Mandatory
            if (parameters.Length > 0)
            {
                throw new InvalidCommandParamsException("Received unexpected parameters. No parameters expected.");
            }

            QuitCommand command = new QuitCommand();


            return(command);
        }
        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);
        }