Example #1
0
 public void Execute(object parameter)
 {
     if (_showWaitCursor)
     {
         MouseEx.SetCursor(Cursors.Wait, () =>
         {
             Catch.ShowMessageBox(() =>
             {
                 if (parameter is T variable)
                 {
                     _method.Invoke(variable);
                 }
                 else
                 {
                     _method.Invoke(default(T));
                 }
             });
         });
     }
     else
     {
         Catch.ShowMessageBox(() =>
         {
             if (parameter is T variable)
             {
                 _method.Invoke(variable);
             }
             else
             {
                 _method.Invoke(default(T));
             }
         });
     }
 }
Example #2
0
 public void Execute(object parameter)
 {
     if (parameter is T variable)
     {
         _method.Invoke(variable);
     }
     else
     {
         _method.Invoke(default(T));
     }
 }
Example #3
0
 public void RunCommand()
 {
     if (!(_commandDelegate == null))
     {
         _commandDelegate.Invoke();
     }
 }
Example #4
0
 public void Selected()
 {
     if (CommandDelegate != null)
     {
         CommandDelegate.Invoke();
     }
 }
Example #5
0
        private void SortQueue()
        {
            if (CommandQueue.Count < 1)
            {
                return;
            }
            PlayerMessage pm = CommandQueue.Dequeue();

            if (CheckString != null)
            {
                CheckString.Invoke(pm);
            }
        }
        protected override void AddCommand(CommandDelegate <TSPlayer> command, string[] names)
        {
            CommandDelegate commandDelegate = async(CommandArgs args) =>
            {
                try
                {
                    int firstSpace = args.Message.IndexOf(' ');
                    // Get the command text without the command name
                    string rawCommandArguments = firstSpace == -1 ? "" : args.Message.Substring(firstSpace + 1);
                    await command.Invoke(args.Player, rawCommandArguments);
                }
                // TShock's command system does its own exception handling, so we have to catch error messages here.
                catch (CommandParsingException e)
                {
                    args.Player.SendErrorMessage(e.Message);
                }
                catch (CommandExecutionException e)
                {
                    args.Player.SendErrorMessage(e.Message);
                }
                catch (Exception e)
                {
                    TShock.Log.Error(e.ToString());
                    args.Player.SendErrorMessage(Context.TextOptions.CommandThrewException);
                }
            };

            var helpText    = command.GetCustomAttribute <HelpText>();
            var permissions = command.GetCustomAttribute <CommandPermissions>();
            var allowServer = command.GetCustomAttribute <AllowServer>();
            var doLog       = command.GetCustomAttribute <DoLog>();

            var tshockCommand = new TShockAPI.Command(permissions != null ? permissions.Permissions.ToList() : new List <string>(), commandDelegate, names)
            {
                HelpText    = $"{(helpText != null ? helpText.Documentation : "")} Syntax: {command.SyntaxDocumentation(TSPlayer.Server)}",
                AllowServer = allowServer != null ? allowServer.Allow : true,
                DoLog       = doLog != null ? doLog.Log : true
            };

            Commands.ChatCommands.Add(tshockCommand);
        }
Example #7
0
            public void SingleCommandHandler(CommandArgs args)
            {
                try
                {
                    string commandName = args.Message.Split(' ')[0];
                    var    cmd         = Commands.ChatCommands.FirstOrDefault(s => s.Names.Contains(commandName));

                    if (cmd == null)
                    {
                        throw new CommandException($"Invalid command! Try {RShockAPI.Config.CommandPrefix}{commandName} help for more info.");
                    }

                    commandDelegate.Invoke(
                        new CommandArgs(args.Message, args.Parameters)
                        );
                }
                catch (CommandException ex)
                {
                    Utils.ShowErrorMessage(ex.Message);
                }
            }
Example #8
0
        /// <summary>
        /// Translates the given command to its concrete type and invokes its execution.
        /// </summary>
        /// <param name="command">Command to be executed.</param>
        /// <param name="cancellationToken">Cancellation token.</param>

        public async Task <TResult> Execute(ICommand <TResult> command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (!(command is TCommand concrete))
            {
                throw new ArgumentException($"Expected command of type {typeof( TCommand )}; Received {command.GetType()}", nameof(command));
            }

            cancellationToken.ThrowIfCancellationRequested();

            var handle = new CommandDelegate <TCommand, TResult>(handler.Handle);

            if (decorators.Any())
            {
                handle = decorators
                         .Reverse()
                         .Aggregate(handle, (continuation, decorator) => (cmd, token) => decorator.Execute(cmd, token, continuation));
            }

            return(await handle.Invoke(concrete, cancellationToken));
        }
Example #9
0
 public async Task <object> Execute(TestCommand command, CancellationToken cancellationToken, CommandDelegate <TestCommand, object> continuation)
 {
     callback.Invoke(command);
     return(await continuation.Invoke(command, cancellationToken));
 }
Example #10
0
 protected override async Task Decorate(TestCommand command, CancellationToken cancellationToken, CommandDelegate <TestCommand, Unit> continuation) =>
 await continuation.Invoke(command, cancellationToken);