/// <summary> /// Executes the command with the given parameter. This means calling /// <see cref="CommandBase.CommandOperation"/>, /// pushing the command on the "Undo" stack and clearing the "Redo" stack. /// </summary> public override sealed void Execute() { if (Controller.CreatedMacro != null) { Controller.CreatedMacro.Commands.Add(this); return; } CommandNumber = getNextCommandNumber(); // call notifying method Controller.OnExecutingCommand(this, false, null); // check mandatory arguments #if DEBUG FieldsChecker.CheckMandatoryArguments(this); #endif if (!CommandCantExecuteDialog.CheckCanExecute(this)) { return; } if (Undoable) { UndoStack.Push(this); // all redo Commands are from now invalid RedoStack.Invalidate(); } // call the actual executive method CommandOperation(); Debug.WriteLine(string.Format("Command {0} executed.", this)); #if DEBUG FieldsChecker.CheckCommandResults(this); #endif // call successful notification method Controller.OnExecutedCommand(this, false, null); }
/// <summary> /// Returns true if all partial Commands can execute. /// </summary> /// <returns>Returns true if all partial Commands can execute.</returns> public override bool CanExecute() { int count = CheckFirstOnlyInCanExecute ? 1 : Commands.Count; for (int i = 0; i < count; i++) { #if DEBUG FieldsChecker.CheckMandatoryArguments(Commands[i]); #endif if (!(Commands[i].CanExecute())) { ErrorDescription = Commands[i].ErrorDescription; return(false); } } return(true); }
/// <summary> /// Performs CommandOperation of all of the partial Commands. /// </summary> internal override void CommandOperation() { for (int i = 0; i < Commands.Count; i++) { Controller.OnExecutingCommand(Commands[i], true, this); #if DEBUG FieldsChecker.CheckMandatoryArguments(Commands[i]); #endif if (!CommandCantExecuteDialog.CheckCanExecute(Commands[i])) { return; } Commands[i].CommandOperation(); #if DEBUG FieldsChecker.CheckCommandResults(this); #endif Controller.OnExecutedCommand(Commands[i], true, this); } CommandsExecuted(); }
/// <summary> /// Executes the command with the given parameter. This means calling /// <see cref="CommandBase.CommandOperation"/>, /// pushing the command on the "Undo" stack and clearing the "Redo" stack. /// </summary> public override void Execute() { if (Controller.CreatedMacro != null) { Controller.CreatedMacro.Commands.Add(this); return; } CommandNumber = getNextCommandNumber(); // call notifying method Controller.InvokeExecutingCommand(this, false, null, false, false); // check mandatory arguments #if DEBUG FieldsChecker.CheckMandatoryArguments(this); #endif if (this is MacroCommand) { (this as MacroCommand).GenerateSubCommands(); } if (!CanExecute()) { throw new ExolutioCommandException(CommandErrors.COMMAND_CANT_EXECUTE, this); } if (Undoable) { UndoStack.Push(this); // all redo Commands are from now invalid RedoStack.Invalidate(); } // call the actual executive method CommandOperation(); Executed = true; #if DEBUG FieldsChecker.CheckCommandResults(this); #endif // call successful notification method Controller.InvokeExecutedCommand(this, false, null, false, false); }
/// <summary> /// Performs CommandOperation of all of the partial Commands if it can be done /// </summary> internal override void CommandOperation() { //GenerateSubCommands(); List <CommandBase> list = new List <CommandBase>(Commands); #if DEBUG int counter = 0; #endif foreach (CommandBase t in list) { Controller.InvokeExecutingCommand(t, true, this, false, false); #if DEBUG FieldsChecker.CheckMandatoryArguments(t); #endif if (t.CanExecute()) { //PREPROPAGATION START if (t is AtomicCommand) { AtomicCommand command = t as AtomicCommand; if (command.Propagate) { PropagationMacroCommand m = command.PrePropagation(); if (m != null) { if (m.Report == null) { m.Report = new CommandReport("Pre-propagation"); } m.GenerateSubCommands(); if (m.CanExecute()) { m.CommandOperation(); Commands.Insert(Commands.IndexOf(t), m); } else { throw new ExolutioCommandException(CommandErrors.COMMAND_CANT_EXECUTE_PROPAGATION, m); } } } } //PREPROPAGATION END if (t is MacroCommand) { (t as MacroCommand).GenerateSubCommands(); if (!t.CanExecute()) { throw new ExolutioCommandException(CommandErrors.COMMAND_CANT_EXECUTE_UNEXPECTED, t); } } t.CommandOperation(); //POSTPROPAGATION START if (t is AtomicCommand) { AtomicCommand command = t as AtomicCommand; if (command.Propagate) { PropagationMacroCommand m = command.PostPropagation(); if (m != null) { if (m.Report == null) { m.Report = new CommandReport("Post-propagation"); } m.GenerateSubCommands(); if (m.CanExecute()) { m.CommandOperation(); Commands.Insert(Commands.IndexOf(t) + 1, m); } else { throw new ExolutioCommandException(CommandErrors.COMMAND_CANT_EXECUTE_PROPAGATION, m); } } } } //POSTPROPAGATION END } else { throw new ExolutioCommandException(t.ErrorDescription ?? CommandErrors.COMMAND_CANT_EXECUTE_UNEXPECTED, t); } #if DEBUG FieldsChecker.CheckCommandResults(this); counter++; #endif Controller.InvokeExecutedCommand(t, true, this, false, false); } CommandsExecuted(); }