Esempio n. 1
0
        /// <summary>Lets the given CmdTrigger trigger the given Command.</summary>
        /// <param name="trigger"></param>
        /// <param name="cmd"></param>
        /// <param name="silentFail">Will not reply if it failed due to target restrictions or privileges etc</param>
        /// <returns></returns>
        public virtual bool Execute(CmdTrigger <C> trigger, BaseCommand <C> cmd, bool silentFail)
        {
            if (cmd.Enabled)
            {
                Command <C> rootCmd = cmd.RootCmd;
                if (!rootCmd.MayTrigger(trigger, cmd, silentFail) || !this.TriggerValidator(trigger, cmd, silentFail))
                {
                    return(false);
                }
                trigger.cmd = cmd;
                try
                {
                    cmd.Process(trigger);
                    rootCmd.ExecutedNotify(trigger);
                }
                catch (Exception ex)
                {
                    rootCmd.FailNotify(trigger, ex);
                }

                return(true);
            }

            trigger.Reply("Command is disabled: " + (object)cmd);
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Lets the given CmdTrigger trigger the given Command.
        /// </summary>
        /// <param name="trigger"></param>
        /// <param name="cmd"></param>
        /// <param name="silentFail">Will not reply if it failed due to target restrictions or privileges etc</param>
        /// <returns></returns>
        public virtual bool Execute(CmdTrigger <C> trigger, BaseCommand <C> cmd, bool silentFail)
        {
            if (cmd.Enabled)
            {
                var rootCmd = cmd.RootCmd;
                if (!rootCmd.MayTrigger(trigger, cmd, silentFail))
                {
                    //trigger.Reply("Cannot trigger Command: " + rootCmd);
                }
                else if (TriggerValidator(trigger, cmd, silentFail))
                {
                    trigger.cmd = cmd;

                    try
                    {
                        cmd.Process(trigger);

                        // command callbacks
                        rootCmd.ExecutedNotify(trigger);

                        // TODO: Create a tree of expected responses?
                        //string[] expectedReplies = cmd.ExpectedServResponses;
                        //if (expectedReplies != null) {
                        //    trigger.expectsServResponse = true;

                        //    foreach (string reply in expectedReplies) {
                        //        AddWaitingTrigger(reply, trigger);
                        //    }
                        //}
                    }
                    catch (Exception e)
                    {
                        rootCmd.FailNotify(trigger, e);
                    }
                    return(true);
                }
                return(false);
            }
            trigger.Reply("Command is disabled: " + cmd);
            return(false);
        }