BalloonsPop.Core.EngineCore.GetCommand C# (CSharp) Method

GetCommand() protected method

protected GetCommand ( string userCommand ) : ICommand
userCommand string
return ICommand
        protected virtual ICommand GetCommand(string userCommand)
        {
            ICommand cmd = null;

            bool isValidPopMove = this.validator.IsValidUserMove(userCommand)
                                    && !this.Context.Game.Field[userCommand[0].ToInt32(), userCommand[2].ToInt32()].IsPopped;

            try
            {
                if (isValidPopMove)
                {
                    this.context.UserRow = userCommand[IndexOfRowDigit].ToInt32();
                    this.context.UserCol = userCommand[IndexOfColumnDigit].ToInt32();
                    cmd = this.commandFactory.CreateCommand(PopCommandKey);
                }
                else if (this.CommandFactory.ContainsKey(userCommand.ToLower()))
                {
                    cmd = this.CommandFactory.CreateCommand(userCommand.ToLower());
                }
                else
                {
                    this.context.Message = WrongInputMessage;
                    cmd = this.commandFactory.CreateCommand(MessageCommandKey);
                }
            }
            catch (ArgumentException e)
            {
                var errorLog = string.Format(
                    "{0}{1}{2}{3}",
                                                 "The command factory failed to create the command.",
                                                 Environment.NewLine,
                                                 e.Message,
                                                 e.StackTrace);
                this.logger.Error(errorLog);

                throw e;
            }

            return cmd;
        }