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);
        }
        internal static CanvasCommand CreateCommand(
            string[] parameters
            )
        {
            CanvasCommand command = null;

            // Validate Mandatory
            if (parameters.Length != 2)
            {
                throw new InvalidCommandParamsException("Expected 2 parameters but received " + parameters.Length + "\n" + GetHelp());
            }

            int width  = -1;
            int height = -1;

            try
            {
                width = Utils.FormatPositiveInt(parameters[0]);
            }
            catch (Exception ex)
            {
                throw new InvalidCommandParamsException("Invalid width: " + parameters[0] + ".\n" + GetHelp(), ex);
            }

            try
            {
                height = Utils.FormatPositiveInt(parameters[1]);
            }
            catch (Exception ex)
            {
                throw new InvalidCommandParamsException("Invalid height: " + parameters[1] + ". \n" + GetHelp(), ex);
            }

            command = new CanvasCommand(
                width,
                height
                );

            return(command);
        }