Пример #1
0
 /// <summary>
 /// Execute this <c>MacroCommand</c>'s <i>SubCommands</i>.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///         The <i>SubCommands</i> will be called in First In/First Out (FIFO)
 ///         order.
 ///     </para>
 /// </remarks>
 /// <param name="notification">the <c>INotification</c> object to be passsed to each <i>SubCommand</i>.</param>
 public virtual void Execute(INotification notification)
 {
     while (Subcommands.Count > 0)
     {
         var commandClassRef = Subcommands[0];
         var commandInstance = commandClassRef();
         commandInstance.Execute(notification);
         Subcommands.RemoveAt(0);
     }
 }
Пример #2
0
        /// <summary>
        /// Calling, while user send messae with prefix and aliase this Executor.
        /// </summary>
        /// <returns>Response to user</returns>
        public virtual Message?Execute()
        {
            if (Subcommands.Length == 0)
            {
                throw new JubiException($"{GetType().Name} class does not override Execute() method");
            }

            var dict = Subcommands.ToDictionary(
                k => k.Alias,
                v => v);

            if (Args.Length < 1 || !dict.ContainsKey(Get <string>(0)))
            {
                throw new SyntaxErrorException(this, $"<{string.Join("/", dict.Keys)}>");
            }

            var executor = dict[Get <string>(0)];

            executor.User   = User;
            executor.Parent = this;

            var args = new List <object>(Args);

            args.RemoveAt(0);

            executor.Args = args.ToArray();

            foreach (var middleware in executor.Middlewares)
            {
                if (!middleware(executor))
                {
                    return(null);
                }
            }
            if (!executor.PreProcessData())
            {
                return(null);
            }

            return(executor.Execute());
        }
Пример #3
0
 /// <summary>
 /// Add a <c>SubCommand</c>.
 /// </summary>
 /// <remarks>
 ///     <para>
 ///         The <i>SubCommands</i> will be called in First In/First Out (FIFO)
 ///         order.
 ///     </para>
 /// </remarks>
 /// <param name="commandClassRef">a reference to the <c>FuncDelegate</c> of the <c>ICommand</c>.</param>
 protected void AddSubCommand(Func <ICommand> commandClassRef)
 {
     Subcommands.Add(commandClassRef);
 }
Пример #4
0
 public bool TryGetChild(string name, out CommandNode node)
 {
     return(Subcommands.TryGetValue(name, out node));
 }
Пример #5
0
 public StringArgs StrArgs;  //Отвечает за строки - "str"
 public ArgsController()
 {
     SubCmds  = new Subcommands(this);
     NumbArgs = new NumberArgs(this);
     StrArgs  = new StringArgs(this);
 }