/// <summary> /// Executes an action and validates the State of the model /// </summary> /// <remarks>Raises OnExecuteAction event</remarks> /// <param name="action">Name of action to execute</param> /// <param name="state">Expected end State object</param> /// <param name="inParams">Input Action Parameter object</param> /// <param name="outParams">Output Action Parameter object</param> /// <returns>false if errors occurred</returns> /// <example> /// <code>myModel.ExecuteAction("Open", endState, inAParams, outAParams);</code> /// </example> public virtual bool ExecuteAction(string action, State state, State inParams, State outParams) { bool actionResult = true; //check whether the action exists if (!_actionHandlers.Contains(action)) { throw new Exception("This model does not contain an action called " + action); } //Save the outParams in case they are needed for comparison later State expOutputParams = outParams; //Invoke the Action Handlers ActionHandler aHandler = (ActionHandler)_actionHandlers[action]; foreach (ActionHandler handler in aHandler.GetInvocationList()) { actionResult = handler(state, inParams, outParams); } //not sure what purpose this serves (should remove if not nessasary) if (OnExecuteAction != null) { OnExecuteAction(this, new ExecuteActionEventArgs(action, state, inParams, outParams)); } //Validate the expected state against the current state if the action succeds if (actionResult && state != null) { return(ValidateState(state)); } return(actionResult); }