/// <summary> /// Start the process. /// </summary> /// <param name="request">Request sahre by all the steps</param> public void HandleRequest(ChainRequest request) { Exception stepException = null; string TraceMessge = ""; try { //Execute step logic request.CurrentStepIndex += 1; //Update process status TraceMessge = string.Format("[{2}] Start Step {0} at process instance {1} step # {3}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId, request.CurrentStepIndex.ToString()); UpdateProcessStatus(request, TraceMessge); //Execute Workflow's Step HandleExecute(request); //Update Process Status TraceMessge = string.Format("[{2}] Finish Step {0} at process instance {1}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId); Trace.TraceInformation(TraceMessge); } catch (Exception currentStepException) { stepException = currentStepException; //Manage Exception and Trigger Compensation manageException(request, currentStepException); } //Update table status after finish Step UpdateProcessStatus(request, ""); if (!request.BreakChain) { //If exception problem solved Or not Execption if (nextStep != null) { nextStep.HandleRequest(request); } else { // This is the Workflow last step end. FinishProccessStatus(request); } } else { //the exceptionwas not solved, break the chain //and rise the last error if (stepException == null) { TraceMessge = string.Format("[{2}] Step Error {0} at process instance {1}: {3}", GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId, "Not Exception Information"); stepException = new Exception(TraceMessge); } throw (stepException); } }
/// <summary> /// Start the process. /// </summary> /// <param name="request">Request sahre by all the steps</param> public void HandleRequest(ChainRequest request) { string TraceMessge = ""; try { // CheckResumeProcess(request); //Execute step logic TraceMessge = string.Format("[{2}] Start Step {0} at process instance {1}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId); Trace.TraceInformation(TraceMessge); this.HandleExecute(request); TraceMessge = string.Format("[{2}] Finish Step {0} at process instance {1}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId); Trace.TraceInformation(TraceMessge); } catch (Exception X) { TraceMessge = string.Format("[{2}] Step Error {0} at process instance {1}: {3}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId, X.Message); Trace.TraceError(TraceMessge); request.Exceptions.Add(new Exception(TraceMessge, X)); //Exception Raise from Step request.BreakChain = true; try { //Compensatory action.... this.HandleCompensation(request); } catch (Exception X2) { TraceMessge = string.Format("[{2}] Step Error at compensatory method {0} at process instance {1}: {3}", this.GetType().FullName, request.ProcessInstanceId, request.ProcessTypeId, X2.Message); Trace.TraceError(TraceMessge); request.Exceptions.Add(new Exception(TraceMessge, X)); throw (X2); } } //Update process status UpdateProcessStatus(request); if (!request.BreakChain) { //If exception problem solved if (nextStep != null) { nextStep.HandleRequest(request); } } else { //the exceptionwas not solved, break the chain //and rise the last error throw (request.Exceptions.Last()); } }