public IDisposable BindExecuteCommand()
        {
            var targetObservable = _model.WhenAnyValue(m => m.IsServerTargetSelected)
                                   .Merge(_model.WhenAnyValue(m => m.IsDatabaseTargetSelected));

            var commandObservable = _model.WhenAnyValue(m => m.CommandText)
                                    .Select(string.IsNullOrWhiteSpace);

            var executableObservable = targetObservable.Merge(commandObservable)
                                       .SelectSeq(_ =>
            {
                if (_model.IsServerTargetSelected || _model.IsDatabaseTargetSelected)
                {
                    return(_commandParser.Parse(_model.CommandText)
                           .Select(batchInfo => batchInfo.CommandInfos.Length > 0 && batchInfo.IsValid));
                }

                return(Observable.Return(false));
            })
                                       .ObserveOn(RxApp.MainThreadScheduler);

            _model.ExecuteCommand =
                ReactiveCommand.CreateFromObservable <string, RedisResultInfo[]>(
                    Execute, executableObservable, RxApp.MainThreadScheduler);

            return(_model.ExecuteCommand
                   .SubscribeWithLog(results =>
            {
                _broadcastService.Broadcast(new ViewResultsIntent(results));
                _broadcastService.Broadcast(new ViewStructIntent(null));
            }));
        }
        public void DispatchCommand(IList <string> args)
        {
            if (args == null || args.Count == 0)
            {
                Console.WriteLine("Empty command");
                return;
            }

            DispatchCommand(_commandParser.Parse(args));
        }
示例#3
0
        public void Valid_Command_Returns_Parsed_CommandList()
        {
            var input  = "R1R2R3L1L2";
            var output = _sut.Parse(input);

            output.Should().BeEquivalentTo(new List <CommandDetail>()
            {
                new CommandDetail('R', 1),
                new CommandDetail('R', 2),
                new CommandDetail('R', 3),
                new CommandDetail('L', 1),
                new CommandDetail('L', 2)
            });
        }
示例#4
0
        /// <inheritdoc />
        public int DoInstruction(string instructions)
        {
            var command = commandParser.Parse(instructions);

            ExecuteCommand(command);
            return(office.CleanedPlaces);
        }
        public void Execute(string commandString)
        {
            var commandList = commandParser.Parse(commandString);

            commandInvoker.Assign(commandList);
            commandInvoker.InvokeAll();
        }
        public void Invoke(RequestContext context)
        {
            var command = _parser.Parse(context.InputCommand);

            command.Execute();
            context.Next();
        }
示例#7
0
        public void Execute(string missionCommands)
        {
            var commandList = _commandParser.Parse(missionCommands);

            _commandInvoker.Assign(commandList);
            _commandInvoker.InvokeAll();
        }
示例#8
0
        public void Start()
        {
            Console.WriteLine("Welcom to Canvas Game!");
            printHelpInfo();
            Console.WriteLine("==================================");
            Console.WriteLine("Let's create a canvas first!");
            Console.WriteLine("Enter Command: ");
            var input = Console.ReadLine();

            while (input != "Q" && input != "q")
            {
                try
                {
                    var command = _parser.Parse(input);
                    command.Execute(_canvas);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                Console.WriteLine("Enter Command: ");
                input = Console.ReadLine();
            }
        }
示例#9
0
        public void Execute(string commandString)
        {
            var commandToExecute = commandParser.Parse(commandString);

            commandInvoker.MakeMovement(commandToExecute);
            commandInvoker.ExecuteCommands();
        }
示例#10
0
        public void Run()
        {
            while (true)
            {
                string input  = reader.ReadLine();
                var    tokens = input.Split();

                if (tokens[0] == "Exit")
                {
                    writer.WriteLine(commandParser.Parse(tokens));

                    break;
                }
                writer.WriteLine(commandParser.Parse(tokens));
            }
        }
示例#11
0
        /// <summary>
        /// Initialize command line args parser
        /// </summary>
        /// <param name="args"></param>
        private static bool SetupCLI(string[] args)
        {
            ICommandParser cli = null;

            try
            {
                cli = CLI.Parser().Title("xsltator").Version("1.0.0").HelpText("Utility for applying an xslt to an xml");
                var xslt = cli.Parameter <string>("xslt").Required(true).HelpText("Xslt file path");
                var xml  = cli.Parameter <string>("xml").Required(true).HelpText("Xml file path");
                var html = cli.Parameter <string>("html").Required(false).HelpText("Optional output html file path");

                cli.Parse(args);

                xsltPath = xslt.Value;
                xmlPath  = xml.Value;

                htmlPath = html.IsSet ? html.Value : Path.ChangeExtension(xmlPath, "html");
            }
            catch (Exception exception)
            {
                using (CLI.WithColors(ConsoleColor.White, ConsoleColor.Red))
                {
                    Console.WriteLine($"\nError while reading command line:\t{exception.Message}\n");
                    using (CLI.WithForeground(ConsoleColor.Black))
                    {
                        Console.WriteLine("Press any...");
                        Console.ReadKey();
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#12
0
        async public Task ExecuteAsync <TRoot, TGlobalOptions>(TRoot rootCommand, TGlobalOptions globalOptions)
        {
            var verbAtt = new VerbAttribute
            {
                IsRoot   = true,
                Instance = rootCommand
            };

            var globalOptionsWrapper = _impl.GetGlobalOptions(globalOptions);

            _attributeDecorator.Decorate(verbAtt, typeof(TGlobalOptions));

            var commandParts = _parser.Parse().GetEnumerator();

            try
            {
                await _impl.ExecuteInternalAsync(verbAtt, commandParts, globalOptionsWrapper);
            }
            catch (BadCommandException bce)
            {
                Console.WriteLine(bce.BadCommand);

                if (bce.Command != null)
                {
                    _commandHelper.WriteCommandHelp(bce.Command, _options, globalOptionsWrapper);
                }
                else
                {
                    _commandHelper.WriteVerbHelp(bce.Verb, _options, globalOptionsWrapper);
                }
            }
        }
示例#13
0
        public IEnumerable <string> ToAssembly(string line)
        {
            var command = commandParser.Parse(line);

            var translator = translatorProvider.GetTranslatorForCommand(command);

            return(translator.ToAssembly(command));
        }
        public void Handle(string line)
        {
            var(type, args) = _parser.Parse(line, SimpleHandler.LineSeparator);
            _validator.Validate(type, args, this.CurrentSheet);
            var command = CommandFactory.Create(type, args, this.CurrentSheet);

            this.CurrentSheet = command.Execute();
        }
        public void EnterCommand(string commandText)
        {
            var wallData = _commandParser.Parse(commandText);

            if (wallData != null)
            {
                _displayResultService.Show(wallData);
            }
        }
示例#16
0
        /// <summary>
        /// Execute the commands
        /// </summary>
        public void ExecuteCommands()
        {
            List <ICommand> commands = m_commandParser.Parse(commandInput);

            foreach (ICommand command in commands)
            {
                command.Execute(this);
            }
        }
示例#17
0
        public async Task RunAsync(string[] input)
        {
            parser.Parse(input);
            Dictionary <string, string> arguments = parser.Arguments;
            string groupName  = parser.GroupName;
            string actionName = parser.ActionName;

            Command command = router.GetCommand(groupName, actionName);
            await command.ExecuteAsync(arguments);
        }
        public string[] ProcessCommand(string commandLine)
        {
            var parsedCommand   = _commandParser.Parse(commandLine);
            var commandFactory  = _applicationFactoriesProvider.GetCommandFactory(_environmentVariables.AppName);
            var requiredCommand = commandFactory.GetCommand(parsedCommand.Name);

            BaseCommand.SetGlobalVariables(_environmentVariables);
            var commandResult = requiredCommand.Execute(parsedCommand.Args, parsedCommand.NamedParameters);

            return(commandResult.Messages.ToArray());
        }
示例#19
0
        private void ParseCommand(string request, ref int start)
        {
            //var pos = request.IndexOf("\r", start);
            //if (pos == -1)
            //{
            //    _state = CommandParseState.WaitForCommand;

            //    return;
            //}

            //var commandLine = request.Substring(start, pos-start);
            //start = pos + 1;

            //var commandInfo = _commandTypeHelper.GetCommandInfo(commandLine);
            //if (commandInfo == null) return;

            //_command = _commandRegistry.GetCommand(commandInfo.CommandName);
            //_state = CommandParseState.WaitForCommand;
            //_command = _commandParser.Parse(request, ref start);
            //if (_command == null)
            //{
            //    //_state = CommandParseState.Idle;
            //    return;
            //}

            //_state = CommandParseState.Command;

            //var handData = _command.HandleCommand(commandInfo);

            //if(handData)
            //    _state = CommandParseState.Data;
            //else
            //    FinishCommand();

            try
            {
                ICommandHandler command;
                if (_commandParser.Parse(request, ref start, out command))
                {
                    FinishCommand();
                }
                else
                {
                    _command = command;
                }
            }
            catch (Exception ex)
            {
                TraceUtil.Error("Parse command error", ex);
                FinishCommand();
            }
        }
示例#20
0
        public Task StartAsync()
        {
            ICommand command;

            command = _parser.Parse(Console.ReadLine());
            command.ExecuteOn(_arena);

            foreach (var robot in _robots)
            {
                command = _parser.Parse(Console.ReadLine());
                command.ExecuteOn(robot);
                command = _parser.Parse(Console.ReadLine());
                command.ExecuteOn(robot);
            }

            foreach (var robot in _robots)
            {
                Console.WriteLine($"{robot.Latitude} {robot.Longitude} {robot.Direction.ToString()[0]}");
            }

            return(Task.CompletedTask);
        }
示例#21
0
 public void ParseCommand(string playerid, string command)
 {
     try {
         var player = GetPlayer(playerid);
         if (ShutedGroups.All(g => g != DeskId))
         {
             _currentParser.Parse(this, player, command);
         }
         _standardParser.Parse(this, player, command);
     } catch (Exception e) {
         AddMessage($"抱歉 我们在处理你的命令时发生了错误{e}");
     }
 }
示例#22
0
        public void Run()
        {
            while (true)
            {
                string[] tokens = reader.ReadLine().Split(' ', System.StringSplitOptions.RemoveEmptyEntries);

                string result = commandParser.Parse(tokens.ToList());
                writer.WriteLine(result);
                if (tokens[0] == "Exit")
                {
                    break;
                }
            }
        }
示例#23
0
        public void Run()
        {
            while (isRunning)
            {
                IList <string> commands = reader.ReadLine().Split().ToList();
                string         result   = commandParser.Parse(commands);

                if (commands[0] == "Exit")
                {
                    isRunning = false;
                }

                writer.WriteLine(result);
            }
        }
        public void Parse_WithNullOrEmptyLine_ShouldThrowValidationException(string line)
        {
            // Arrange

            // Act
            Func <(CommandType type, string[] args)> action = () => _sut.Parse(line, LineSeparator);

            // Assert
            action.Should().ThrowExactly <ValidationException>();
        }
示例#25
0
        public void Run()
        {
            this.isRunning = true;

            while (isRunning)
            {
                List <string> arguments = reader.ReadLine().Split().ToList();

                if (arguments[0] == "Exit")
                {
                    isRunning = false;
                }

                string result = commandParser.Parse(arguments);
                writer.WriteLine(result);
            }
        }
示例#26
0
        private static void run(ICommandParser parser, CancellationToken cancelToken)
        {
            var drawer = new Drawer();

            while (cancelToken.IsCancellationRequested == false)
            {
                Console.Write("enter command: ");
                var line = Console.ReadLine();
                var cmd  = parser.Parse(line);

                drawer.Paint(cmd);

                if (cancelToken.IsCancellationRequested == false)
                {
                    Print(drawer.Canvas);
                }
            }
        }
示例#27
0
        public async void ExecuteCommand(Player player, string message)
        {
            message = _cleaner.Clean(message);
            var(command, remainingMessage) = _commandParser.Parse(message);
            var usedParameters = _argumentsParser.ParseUserArguments(remainingMessage);
            var userInputData  = new UserInputData(command, message, usedParameters);

            if (!TryGetCommandData(player, userInputData, out var commandData))
            {
                return;
            }
            if (!TryGetPossibleMethods(player, userInputData, usedParameters, commandData, out var possibleMethods))
            {
                return;
            }

            await _methodExecuter.TryExecuteSuitable(player, userInputData, commandData, possibleMethods);
        }
示例#28
0
        private void OnCommandFileChanged(object sender, FileSystemEventArgs e)
        {
            _fileSystemWatcher.EnableRaisingEvents = false;

            OpenFileWithRetries(e.FullPath, reader =>
            {
                string line = reader.ReadLine();
                var command = _commandParser.Parse(line);

                if (command == null)
                {
                    _logger.Warn($"The command has not been recognized: '{line}'");
                }

                Publish(command);
            });

            _fileSystemWatcher.EnableRaisingEvents = true;
        }
示例#29
0
 public void Run()
 {
     while (true)
     {
         string[] input = reader.ReadLine().Split();
         try
         {
             writer.WriteLine(commandParser.Parse(input));
             if (input[0] == "Exit")
             {
                 break;
             }
         }
         catch (ArgumentException ae)
         {
             writer.WriteLine(ae.Message);
         }
     }
 }
示例#30
0
        private ICommand GetCommand(Activity activity)
        {
            var text        = GetTextWithoutRecipientMention(activity).Trim();
            var parseResult = commandParser.Parse(text);

            if (parseResult.IsCommand)
            {
                return(commandFactory.Create(parseResult.CommandInfo, new AuditInfo()
                {
                    Source = "MsBotFramework",
                    SubSource = activity.Conversation.Id,
                    InvokedBy = activity.From.Id,
                    InvokedByName = activity.From.Name,
                    SubSubSource = activity.Id,
                    Date = activity.Timestamp
                }));
            }

            return(null);
        }