Esempio n. 1
0
        private static CommandRule GetTestCommandRule()
        {
            var commandRule = new CommandRule();

            commandRule.Command = new Command {
                Name = "SomeValidCommand", Description = "Some command description"
            };
            commandRule.Command.RequiredParameters.Add(new RequiredCommandParameter
            {
                Name         = "InputFile",
                Description  = "Input file description",
                ExampleValue = "c:\\temp\\input.txt"
            });
            commandRule.Command.RequiredParameters.Add(new RequiredCommandParameter
            {
                Name         = "OutputFile",
                Description  = "Output file description",
                ExampleValue = "c:\\temp\\output.txt"
            });
            commandRule.Command.OptionalParameters.Add(new OptionalCommandParameter("false")
            {
                Name         = "OverwriteOutput",
                Description  = "Owerwrite output file",
                ExampleValue = "true"
            });
            return(commandRule);
        }
Esempio n. 2
0
        public SocketRequestInfo(CommandRule routeRule, ICommandRuleProvider commandRuleProvider, byte[] requestBody)
        {
            Route = routeRule;
            CommandRuleProvider = commandRuleProvider;
            var key = CommandRuleProvider.GetCommandName(routeRule);

            Initialize(key, requestBody);
        }
        public static void GetCommandRuleMetodHasCommandWithTwoRequiredParameterAndOneOptionalParameterVerifyCommandRuleSucessUnitTest()
        {
            CommandRuleProvider target      = new CommandRuleProvider();
            string      expectedCommandName = "CommandWithTwoRequiredParameterAndOneOptionalParameter";
            CommandRule commandRule         = target.GetCommandRule(typeof(TestCommands0).GetMethodEx(expectedCommandName));

            Assert.AreEqual(expectedCommandName, commandRule.Command.Name);
            Assert.AreEqual(2, commandRule.Command.RequiredParameters.Count);
            Assert.AreEqual(1, commandRule.Command.OptionalParameters.Count);
            //Console.WriteLine(commandRule.Help());
        }
Esempio n. 4
0
    TryMatchRule(CommandRule rule, IEnumerable <Token> tokens, CommandResult commandResult, DirectiveCollection directives)
    {
        var entryItems = ImmutableArray.CreateBuilder <KeyValuePair <string, string> >();

        entryItems.Add(new KeyValuePair <string, string>("verb", rule.CommandName));

        // Filter out option tokens as we query the command result for them when processing a rule.
        var tokenQueue = new Queue <Token>(tokens.Where(x => x.Type != TokenType.Option));

        Token NextToken()
        {
            return(tokenQueue.TryDequeue(out var firstToken) ? firstToken : default);
Esempio n. 5
0
        TryMatchRule(CommandRule rule, IEnumerable <Token> tokens, CommandResult commandResult, IDirectiveCollection directives)
        {
            var entryItems = ImmutableArray.CreateBuilder <KeyValuePair <string, string> >();

            entryItems.Add(new KeyValuePair <string, string>("verb", rule.CommandName));

            // Filter out option tokens as we query the command result for them when processing a rule.
            var tokenQueue = new Queue <Token>(tokens.Where(x => x.Type != TokenType.Option));

            Token NextToken()
            {
                return(tokenQueue.TryDequeue(out var firstToken) ? firstToken : null);
            }

            var currentToken = NextToken();

            // We have a valid rule so far.
            var passed = true;

            _directiveProcessor?.Invoke(commandResult, directives, entryItems);

            foreach (var item in rule.Items)
            {
                // Stop checking items since our rule already failed.
                if (!passed)
                {
                    break;
                }

                switch (item)
                {
                case OptionItem optItem:
                {
                    var optionValue = commandResult.Children.OfType <OptionResult>().FirstOrDefault(o => o.Option.HasAlias(optItem.Option))?.GetValueOrDefault()?.ToString();
                    if (optionValue is not null && optItem.Values.Contains(optionValue))
                    {
                        entryItems.Add(new KeyValuePair <string, string>(optItem.EntryKey, optionValue));
                    }
Esempio n. 6
0
        public void Setup()
        {
            Syntax      = new CommandSyntax();
            Parser      = new CommandParser(Syntax);
            Validator   = new CommandValidator(Parser, new MockLocalizer());
            MockMethods = new MockCommand();
            Generator   = new CandidatesGenerator(Syntax);

            Switch      = new ArgumentRule("switch", MockMethods.Switch);
            Click       = new ArgumentRule("click", MockMethods.Click);
            RightClick  = new ArgumentRule("rightclick", MockMethods.RightClick);
            DoubleClick = new ArgumentRule("doubleclick", MockMethods.DoubleClick);

            ArgApplication   = new ArgumentRule("application", MockMethods.Application, ArgsFactory(Switch));
            ArgWindow        = new ArgumentRule("window", MockMethods.Window, ArgsFactory(Click, RightClick, DoubleClick));
            ArgTaskbar       = new ArgumentRule("taskbar", MockMethods.Taskbar, ArgsFactory(Click, RightClick));
            ArgDividedscreen = new ArgumentRule("windowdividedscreen", MockMethods.WindowDividedScreen, ArgsFactory(Click, DoubleClick));

            ArgText           = new ArgumentRule("Text", MockMethods.Text);
            ArgCommand        = new ArgumentRule("Command", MockMethods.Command);
            ArgInItemsControl = new ArgumentRule("TextInItemsControl", MockMethods.TextInItemsControl);

            OptButton   = new ArgumentRule("Button", MockMethods.Button);
            OptCheckBox = new ArgumentRule("CheckBox", MockMethods.CheckBox);

            OptGenerator = new ArgumentRule("-hintGenerator", MockMethods.HintGenerator);
            OptTarget    = new ArgumentRule("-searchTarget", MockMethods.SearchTarget, null, ArgsFactory(OptButton, OptCheckBox));

            Hah            = new CommandRule("hah", MockMethods.HitaHint, ArgsFactory(ArgWindow, ArgApplication, ArgTaskbar, ArgDividedscreen), ArgsFactory(OptGenerator, OptTarget));
            SearchByText   = new CommandRule("/", MockMethods.SearchByText, ArgsFactory(ArgText, ArgCommand, ArgInItemsControl), ArgsFactory(OptTarget));
            Hah2           = new CommandRule("hah2", MockMethods.HitaHint2, ArgsFactory(ArgWindow, ArgDividedscreen));
            MouseEmulation = new CommandRule("me", MockMethods.MouseEmulation);

            Syntax.Add(Hah);
            Syntax.Add(SearchByText);
            Syntax.Add(Hah2);
            Syntax.Add(MouseEmulation);
        }
Esempio n. 7
0
        TryMatchRule(CommandRule rule, IEnumerable <Token> tokens, CommandResult commandResult)
        {
            var entryItems = ImmutableArray.CreateBuilder <KeyValuePair <string, string> >();

            entryItems.Add(new KeyValuePair <string, string>("verb", rule.CommandName));

            // Filter out option tokens as we query the command result for them when processing a rule.
            var tokenQueue = new Queue <Token>(tokens.Where(x => x.Type != TokenType.Option));

            Token NextToken()
            {
                if (tokenQueue.TryDequeue(out var firstToken))
                {
                    return(firstToken);
                }
                else
                {
                    return(null);
                }
            }

            var currentToken = NextToken();

            // We have a valid rule so far.
            var passed = true;

            foreach (var item in rule.Items)
            {
                // Stop checking items since our rule already failed.
                if (!passed)
                {
                    break;
                }

                switch (item)
                {
                case OptionItem optItem:
                {
                    var optionValue = commandResult.OptionResult(optItem.Option)?.Tokens?.FirstOrDefault()?.Value;
                    if (optionValue != null && optItem.Values.Contains(optionValue))
                    {
                        entryItems.Add(new KeyValuePair <string, string>(optItem.EntryKey, optionValue));
                    }
                    else
                    {
                        passed = false;
                    }
                    break;
                }

                case ArgumentItem argItem:
                {
                    if (argItem.TokenType == currentToken?.Type &&
                        argItem.Value == currentToken?.Value)
                    {
                        entryItems.Add(new KeyValuePair <string, string>(argItem.EntryKey, argItem.Value));
                        currentToken = NextToken();
                    }
                    else if (argItem.IsOptional)
                    {
                        currentToken = NextToken();
                    }
                    else
                    {
                        passed = false;
                    }
                    break;
                }

                case IgnoreItem ignoreItem:
                {
                    if (ignoreItem.TokenType == currentToken?.Type)
                    {
                        currentToken = NextToken();
                    }
                    else if (ignoreItem.IsOptional)
                    {
                        currentToken = NextToken();
                    }
                    else
                    {
                        passed = false;
                    }
                    break;
                }

                default:
                    passed = false;
                    break;
                }
            }

            if (passed)
            {
                return(entryItems.ToImmutable());
            }
            else
            {
                return(null);
            }
        }
 public void ShowHelp(List <CommandRule> commandRules, CommandRule helpForCommandRule, IApplicationInfo applicationInfo)
 {
     throw new CustomTestHelpProviderException();
 }