Exemple #1
0
        public async Task RunCommand(string methodName, object[] prm)
        {
            if (!reportingAction)
            {
                try
                {
                    reportingAction = true;
                    if (!RunnableCommands.TryGetValue(methodName, out var command))
                    {
                        throw new ArgumentException("Wrong command: " + methodName);
                    }

                    if (command.Async)
                    {
                        await(Task) command.Method.Invoke(this, prm);
                    }
                    else
                    {
                        command.Method.Invoke(this, prm);
                    }
                }
                finally
                {
                    reportingAction = false;
                }
            }
        }
        public void Run(IEnumerable <string> tokens)
        {
            // TODO: validate full command's string format
            var command         = tokens.First();
            var arguments       = tokens.Skip(1);
            var runnableCommand = RunnableCommands.FirstOrDefault(cmd => cmd.DefinedCommand.Name.Equals(command));

            if (runnableCommand == null)
            {
                throw new InvalidOperationException("Command does not exist.");
            }

            runnableCommand.Run(arguments, this);
        }