public void QueueExecution(IEnumerable<ExecutionRequestParameters> requestParameters) { ExecutionResponseParameters executionResponseParameter = (new ActivityExecutor(this._runtime)).Execute(requestParameters); if (this.ExecutionComplete != null) { ExecutionResponseEventArgs executionResponseEventArg = new ExecutionResponseEventArgs(executionResponseParameter); this.ExecutionComplete(this, executionResponseEventArg); } }
public void QueueExecution(IEnumerable<ExecutionRequestParameters> requestParameters) { var executor = new ActivityExecutor(); var response = executor.Execute(requestParameters); if (ExecutionComplete != null) { var args = new ExecutionResponseEventArgs(response); ExecutionComplete(this,args); } }
public void QueueExecution(IEnumerable <ExecutionRequestParameters> requestParameters) { var executor = new ActivityExecutor(); var response = executor.Execute(requestParameters); if (ExecutionComplete != null) { var args = new ExecutionResponseEventArgs(response); ExecutionComplete(this, args); } }
//通过注入的规则(IWorkflowBus),方法执行完成后调用本方法。 internal void BusExecutionComplete(object sender, ExecutionResponseEventArgs e) { var executionResponseParameters = e.Parameters; var processInstance = Builder.GetProcessInstance(executionResponseParameters.ProcessId); PersistenceProvider.FillSystemProcessParameters(processInstance); //TODO Сделать метод филл CurrentActivity if (executionResponseParameters.IsEmplty) { SetProcessNewStatus(processInstance, ProcessStatus.Idled); //var timerTransitions = // processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity).ToList(); //timerTransitions.ForEach(p=>_runtimeTimer.UpdateTimer(processInstance.ProcessId,p.Trigger.Timer)); return; } if (executionResponseParameters.IsError) { var executionErrorParameters = executionResponseParameters as ExecutionResponseParametersError; Logger.Log.Error(string.Format("Error Execution Complete Workflow Id={0}", processInstance.ProcessId), executionErrorParameters.Exception); if (string.IsNullOrEmpty(executionErrorParameters.ExecutedTransitionName)) { SetProcessNewStatus(processInstance, ProcessStatus.Idled); throw executionErrorParameters.Exception; } var transition = processInstance.ProcessScheme.FindTransition(executionErrorParameters.ExecutedTransitionName); var onErrorDefinition = transition.OnErrors.Where( oe => executionErrorParameters.Exception.GetType().Equals(oe.ExceptionType)). OrderBy(oe => oe.Priority).FirstOrDefault() ?? transition.OnErrors.Where( oe => oe.ExceptionType.IsAssignableFrom(executionErrorParameters.Exception.GetType())). OrderBy(oe => oe.Priority).FirstOrDefault(); if (onErrorDefinition == null) { SetProcessNewStatus(processInstance, ProcessStatus.Idled); throw executionErrorParameters.Exception; } if (onErrorDefinition.ActionType == OnErrorActionType.SetActivity) { var from = processInstance.CurrentActivity; var to = processInstance.ProcessScheme.FindActivity((onErrorDefinition as SetActivityOnErrorDefinition).NameRef); PersistenceProvider.UpdatePersistenceState(processInstance, TransitionDefinition.Create(from, to)); SetProcessNewStatus(processInstance, ProcessStatus.Idled); } throw executionErrorParameters.Exception; //return; } try { ActivityDefinition newCurrentActivity; if (string.IsNullOrEmpty(executionResponseParameters.ExecutedTransitionName)) { if (executionResponseParameters.ExecutedActivityName == processInstance.ProcessScheme.InitialActivity.Name) newCurrentActivity = processInstance.ProcessScheme.InitialActivity; else { var from = processInstance.CurrentActivity; var to = processInstance.ProcessScheme.FindActivity(executionResponseParameters.ExecutedActivityName); newCurrentActivity = to; PersistenceProvider.UpdatePersistenceState(processInstance,TransitionDefinition.Create(from,to)); } } else { var executedTransition = processInstance.ProcessScheme.FindTransition(executionResponseParameters.ExecutedTransitionName); newCurrentActivity = executedTransition.To; PersistenceProvider.UpdatePersistenceState(processInstance, executedTransition); } FillParameters(processInstance,(executionResponseParameters as ExecutionResponseParametersComplete)); PersistenceProvider.SavePersistenceParameters(processInstance); var autoTransitions = processInstance.ProcessScheme.GetAutoTransitionForActivity(newCurrentActivity).ToList(); if (autoTransitions.Count() < 1) { SetProcessNewStatus(processInstance, newCurrentActivity.IsFinal ? ProcessStatus.Finalized : ProcessStatus.Idled); //var timerTransitions = //processInstance.ProcessScheme.GetTimerTransitionForActivity(newCurrentActivity).ToList(); //timerTransitions.ForEach(p => _runtimeTimer.SetTimer(processInstance.ProcessId, p.Trigger.Timer)); return; } PersistenceProvider.FillProcessParameters(processInstance); var newExecutionParameters = new List<ExecutionRequestParameters>(); newExecutionParameters.AddRange( autoTransitions.Select( at => ExecutionRequestParameters.Create(processInstance.ProcessId, processInstance.ProcessParameters, at))); Bus.QueueExecution(newExecutionParameters); } catch (ActivityNotFoundException) { SetProcessNewStatus(processInstance, ProcessStatus.Terminated); } //TODO Обработка ошибок catch (Exception ex) { Logger.Log.Error(string.Format("Error Execution Complete Workflow Id={0}", processInstance.ProcessId), ex); SetProcessNewStatus(processInstance, ProcessStatus.Idled); } }
internal void BusExecutionComplete(object sender, ExecutionResponseEventArgs e) { ActivityDefinition to; ActivityDefinition currentActivity; ExecutionResponseParameters parameters = e.Parameters; ProcessInstance processInstance = e.Parameters.ProcessInstance; this.PersistenceProvider.FillSystemProcessParameters(processInstance); if (parameters.IsEmplty) { this.SetProcessNewStatus(processInstance, ProcessStatus.Idled); if (this.TimerManager != null) { this.TimerManager.ClearAndRegisterTimers(processInstance); } return; } if (parameters.IsError) { ExecutionResponseParametersError executionResponseParametersError = parameters as ExecutionResponseParametersError; this.PersistenceProvider.FillPersistedProcessParameters(processInstance); ProcessStatus terminated = ProcessStatus.Terminated; if (processInstance.ProcessScheme.GetCommandTransitions(processInstance.CurrentActivity, ForkTransitionSearchType.NotFork).Union<TransitionDefinition>(processInstance.ProcessScheme.GetTimerTransitionForActivity(processInstance.CurrentActivity, ForkTransitionSearchType.NotFork)).Any<TransitionDefinition>()) { terminated = ProcessStatus.Error; } if (this.OnWorkflowError != null) { TransitionDefinition transitionDefinition = null; if (!string.IsNullOrEmpty(executionResponseParametersError.ExecutedTransitionName)) { transitionDefinition = processInstance.ProcessScheme.FindTransition(executionResponseParametersError.ExecutedTransitionName); } WorkflowErrorEventArgs workflowErrorEventArg = new WorkflowErrorEventArgs(processInstance, terminated, transitionDefinition, executionResponseParametersError.Exception); this.OnWorkflowError(this, workflowErrorEventArg); terminated = workflowErrorEventArg.ProcessStatus; } this.SetProcessNewStatus(processInstance, terminated); if (terminated == ProcessStatus.Error || terminated == ProcessStatus.Terminated) { throw executionResponseParametersError.Exception; } return; } try { if (!string.IsNullOrEmpty(parameters.ExecutedTransitionName)) { TransitionDefinition transitionDefinition1 = processInstance.ProcessScheme.FindTransition(parameters.ExecutedTransitionName); to = transitionDefinition1.To; this.PersistenceProvider.UpdatePersistenceState(processInstance, transitionDefinition1); } else { try { currentActivity = processInstance.CurrentActivity; } catch (ActivityNotFoundException activityNotFoundException) { currentActivity = ActivityDefinition.Create(processInstance.CurrentActivityName, processInstance.GetParameter(DefaultDefinitions.ParameterCurrentState.Name).Value.ToString(), false, false, false, false); } ActivityDefinition activityDefinition = processInstance.ProcessScheme.FindActivity(parameters.ExecutedActivityName); to = activityDefinition; this.PersistenceProvider.UpdatePersistenceState(processInstance, TransitionDefinition.Create(currentActivity, activityDefinition)); } this.PersistenceProvider.SavePersistenceParameters(processInstance); List<TransitionDefinition> list = processInstance.ProcessScheme.GetAutoTransitionForActivity(to, ForkTransitionSearchType.Fork).ToList<TransitionDefinition>(); if (list.Any<TransitionDefinition>()) { this.CreateSubprocesses(processInstance, list, null); } List<TransitionDefinition> transitionDefinitions = processInstance.ProcessScheme.GetAutoTransitionForActivity(to, ForkTransitionSearchType.NotFork).ToList<TransitionDefinition>(); this.PersistenceProvider.FillProcessParameters(processInstance); if (transitionDefinitions.Any<TransitionDefinition>()) { List<ExecutionRequestParameters> executionRequestParameters = new List<ExecutionRequestParameters>(); executionRequestParameters.AddRange( from at in transitionDefinitions select ExecutionRequestParameters.Create(processInstance, at)); this.Bus.QueueExecution(executionRequestParameters); } else { processInstance.CurrentActivityName = to.Name; processInstance.CurrentState = processInstance.ExecutedActivityState; this.SetIdledStatus(processInstance, to); this.CheckSubprocesses(processInstance); if (this.TimerManager != null) { this.TimerManager.ClearAndRegisterTimers(processInstance); } } } catch (ActivityNotFoundException activityNotFoundException1) { this.SetProcessNewStatus(processInstance, ProcessStatus.Terminated); } catch (Exception exception1) { Exception exception = exception1; this.SetProcessNewStatus(processInstance, ProcessStatus.Idled); throw new Exception(string.Format("Error Execution Complete Workflow Id={0}", processInstance.ProcessId), exception); } }