public virtual bool Execute(ICommand command) { lock (this) { try { InExecute = true; ActiveCommand = command; if (CommandExecuting != null) { var e = new CommandExecutingEventArgs(command); CommandExecuting(this, e); if (e.Cancel) { if (CommandExecutionCancelled != null) CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); return false; } } if (!BeforeExecute(command)) { if (CommandExecutionCancelled != null) CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); return false; } if (!DoExecute(command)) { if (CommandExecutionCancelled != null) CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); return false; } if (!AfterExecute(command)) { if (CommandExecutionCancelled != null) CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); return false; } if (CommandExecuted != null) CommandExecuted(this, new CommandExecutedEventArgs(command)); return true; } catch (Exception) { if (CommandExecutionCancelled != null) CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); throw; } finally { InExecute = false; ActiveCommand = null; } } }
public virtual bool Execute(ICommand command) { lock (this) { try { InExecute = true; ActiveCommand = command; if (CommandExecuting != null) { var e = new CommandExecutingEventArgs(command); CommandExecuting(this, e); if (e.Cancel) { if (CommandExecutionCancelled != null) { CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); } return(false); } } if (!BeforeExecute(command)) { if (CommandExecutionCancelled != null) { CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); } return(false); } if (!DoExecute(command)) { if (CommandExecutionCancelled != null) { CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); } return(false); } if (!AfterExecute(command)) { if (CommandExecutionCancelled != null) { CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); } return(false); } if (CommandExecuted != null) { CommandExecuted(this, new CommandExecutedEventArgs(command)); } return(true); } catch (Exception) { if (CommandExecutionCancelled != null) { CommandExecutionCancelled(this, new CommandExecutedEventArgs(command)); } throw; } finally { InExecute = false; ActiveCommand = null; } } }