예제 #1
0
        private List <CommandBase> SearchCommandAndAlias(InputRequest inputRequest)
        {
            var commands = Commands.Where(k => k.CommandName.ToLowerInvariant() == inputRequest.CommandName)
                           .ToList();

            if (commands.Count == 0 && inputRequest.CommandName.Length > MandatoryCommandSufix.Length)
            {
                var aliasName = inputRequest.CommandName.Substring(0, inputRequest.CommandName.Length - MandatoryCommandSufix.Length);
                var isAlias   = StoredDataService.ExistsAlias(aliasName);
                if (isAlias)
                {
                    var commandName = StoredDataService.GetAliasedCommand(aliasName);
                    commands = Commands.Where(k => k.GetInvocationCommandName() == commandName)
                               .ToList();
                }
            }

            return(commands);
        }
예제 #2
0
        public override void Execute(List <CommandParameter> parameters)
        {
            var commandName = GetStringParameterValue(parameters, CommandNameParameter.Name);
            var aliasName   = GetStringParameterValue(parameters, CommandAliasParameter.Name);

            var commandAliased = RegisteredCommands
                                 .FirstOrDefault(k => k.GetInvocationCommandName() == commandName);

            if (commandAliased == null)
            {
                throw new CommandNotFoundException(commandName);
            }

            if (StoredDataService.ExistsAlias(aliasName))
            {
                throw new AliasRepeatedException(aliasName);
            }

            StoredDataService.AddAlias(commandName, aliasName);

            Log($"Alias stored!");
        }