コード例 #1
0
        protected virtual WorkflowStateManager <S> RunStateMachine(HttpRequestBase request,
                                                                   WorkflowStateManager <S> stateManager)
        {
            while (true)
            {
                var nextState = stateManager.GetNextState();

                if (IComparable.Equals(nextState, this.Workflow.State) != true)
                {
                    this.Workflow.State = nextState;
                    stateManager        = this.GetWorkflowStateManager();
                }
                else
                {
                    if (OnBeforeRequire != null)
                    {
                        OnBeforeRequire.Invoke(this.Workflow, stateManager);
                    }
                    stateManager.Require();
                    if (OnAfterRequire != null)
                    {
                        OnAfterRequire.Invoke(this.Workflow, stateManager);
                    }

                    if (stateManager.GetActionResult(request) != null)
                    {
                        break;
                    }
                    else
                    {
                        if (OnBeforeProcess != null)
                        {
                            OnBeforeProcess.Invoke(this.Workflow, stateManager);
                        }
                        stateManager.Process(request.Form, this.ContextInfo.DefaultModelBinder);
                        if (OnAfterProcess != null)
                        {
                            OnAfterProcess.Invoke(this.Workflow, stateManager);
                        }

                        if (OnBeforeEnsure != null)
                        {
                            OnBeforeEnsure.Invoke(this.Workflow, stateManager);
                        }
                        stateManager.Ensure();
                        if (OnAfterEnsure != null)
                        {
                            OnAfterEnsure.Invoke(this.Workflow, stateManager);
                        }
                    }
                }
            }

            return(stateManager);
        }
コード例 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////

        public virtual ActionResult Run(HttpRequestBase request, bool skipProcess = false)
        {
            var stateManager = this.GetWorkflowStateManager();

            if (request.IsPostRequest() && !skipProcess)
            {
                if (OnBeforeProcess != null)
                {
                    OnBeforeProcess.Invoke(this.Workflow, stateManager);
                }
                stateManager.Process(request.Form, this.ContextInfo.DefaultModelBinder);
                if (OnAfterProcess != null)
                {
                    OnAfterProcess.Invoke(this.Workflow, stateManager);
                }

                if (stateManager.ValidationErrors.Any())
                {
                    stateManager.ValidationErrors.ForEach(v =>
                                                          this.ContextInfo.AddValidationError(v)
                                                          );
                }
                else
                {
                    if (OnBeforeEnsure != null)
                    {
                        OnBeforeEnsure.Invoke(this.Workflow, stateManager);
                    }
                    stateManager.Ensure();
                    if (OnAfterEnsure != null)
                    {
                        OnAfterEnsure.Invoke(this.Workflow, stateManager);
                    }
                }
            }

            stateManager = this.RunStateMachine(request, stateManager);
            stateManager.AddViewData();

            return(stateManager.GetActionResult(request));
        }