Beispiel #1
0
        protected override object OnExecute(CommandContext context)
        {
            if (context.Expression.Arguments.Length == 0)
            {
                throw new CommandException(Properties.Resources.Text_Command_MissingArguments);
            }

            //从环境中查找秘密提供程序
            var secretor = SecretCommand.FindSecretor(context.CommandNode);

            if (secretor == null)
            {
                throw new CommandException("Missing required secretor for the command.");
            }

            if (secretor.Verify(context.Expression.Options.GetValue <string>(KEY_NAME_OPTION), context.Expression.Arguments[0], out var extra))
            {
                if (extra != null && extra.Length > 0)
                {
                    context.Output.WriteLine(extra);
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        protected override object OnExecute(CommandContext context)
        {
            //从环境中查找秘密提供程序
            var secretor = SecretCommand.FindSecretor(context.CommandNode);

            if (secretor == null)
            {
                throw new CommandException("Missing required secretor for the command.");
            }

            var name    = context.Expression.Options.GetValue <string>(KEY_NAME_OPTION);
            var pattern = context.Expression.Options.GetValue <string>(KEY_PATTERN_OPTION);

            switch (context.Expression.Arguments.Length)
            {
            case 0:
                return(secretor.Generate(name, pattern, null));

            case 1:
                return(secretor.Generate(name, pattern, context.Expression.Arguments[0]));
            }

            //定义返回验证码的数组
            var results = new string[context.Expression.Arguments.Length];

            for (int i = 0; i < context.Expression.Arguments.Length; i++)
            {
                results[i] = secretor.Generate(name, pattern, context.Expression.Arguments[i]);
            }

            return(results);
        }