示例#1
0
        protected virtual void InvokeExecuting(CommandExecutingEventArgs args)
        {
            var handler = Executing;

            if (handler != null)
            {
                handler(this, args);
            }
        }
示例#2
0
        public void Execute()
        {
            this.LogDebugFormat("Executing command {0} (type {1})...", this, GetType());

            if (!Enabled)
            {
                throw new CommandExecutingException("Cannot execute disabled command");
            }

            if (Buzy)
            {
                throw new InvalidOperationException("Cannot execute buzy command");
            }

            try
            {
                Buzy = true;

                InvokeBeforeExecute();

                var args = new CommandExecutingEventArgs(Context);

                InvokeExecuting(args);

                if (args.Cancel)
                {
                    this.LogWarnFormat("Command {0} cancelled by user code", this);
                    return;
                }

                OnExecute();

                InvokeAfterExecute(new CommandExecutedEventArgs(Context));
            }
            finally
            {
                Buzy = false;
            }
        }