public Execution <TContext> Resume <TClosure>(TContext context, TClosure closure) { var execution = m_Persister.Load(context); var executor = new WorkflowExecutor <TContext>(execution, context, this, m_ActivityFactory, m_ActivityExecutor, closure); string node = execution.Log.Select(item => item.Node).LastOrDefault(); accept(executor, node); m_Persister.Save(context, execution); return(execution); }
public virtual Execution Resume <TClosure>( TContext context, Guid activityExecutionId, TClosure closure) { var execution = m_Persister.Load(context); var activityExecution = execution.ExecutingActivities.FirstOrDefault(a => a.Id == activityExecutionId); if (activityExecution == null) { execution.Error = $"Failed to resume. Provided activity execution id '{activityExecutionId}' not found"; execution.State = WorkflowState.Corrupted; } else { var executor = new ResumeWorkflowExecutor <TContext>( execution, context, this, m_ActivityFactory, m_ExecutionObserver, activityExecution, closure); try { string node = activityExecution.Node; Accept(executor, node); } catch (Exception e) { execution.Error = e.ToString(); execution.State = WorkflowState.Corrupted; } } m_Persister.Save(context, execution); return(execution); }
/// <summary> /// Persists the specified work flow. /// </summary> /// <param name="workFlow">The work flow.</param> public void Save(IStateMachineContext workFlow) { if (workFlow == null) { throw new ArgumentNullException("workFlow"); } bool isPersisted = workFlow.Id != Guid.Empty; if (isPersisted == false) { workFlow.Id = GuidCombGenerator.Generate(); } string domainContextType = null; object domainContextId = null; object domainContext = GetDomainContext(workFlow); string domainContextStatusProperty = string.Empty; if (workFlow.DomainContext is ReflectiveDomainContextWrapper) { domainContextStatusProperty = ((ReflectiveDomainContextWrapper)workFlow.DomainContext).StateProperty.Name; } if (domainContext != null && _domainContextRepository != null) { _domainContextRepository.Save(domainContext); domainContextType = _domainContextRepository.GetTypeDescription(domainContext); domainContextId = _domainContextRepository.GetId(domainContext); } IStateMachineState currentState = workFlow.CurrentState; IWorkflowEntity workflowEntity = isPersisted ? _workflowPersister.Load(workFlow.Id) : _workflowPersister.CreateEmptyWorkflowEntity(workFlow.Id); if (workflowEntity == null) { throw new Exception("The workflow persister returned a null object from the CreateEmptyWorkflowEntity call."); } workflowEntity.WorkflowId = workFlow.Id; workflowEntity.CurrentState = currentState != null ? currentState.StateName : string.Empty; workflowEntity.MachineConfiguration = Convert.ToString(workFlow.StateMachine.Tag); workflowEntity.DomainContextTypeDescription = domainContextType; workflowEntity.DomainContextId = domainContextId; workflowEntity.DomainContextStatusProperty = domainContextStatusProperty; if (isPersisted && workFlow.IsComplete) { _workflowPersister.Complete(workflowEntity); } else if (isPersisted) { _workflowPersister.Update(workflowEntity); } else { _workflowPersister.Save(workflowEntity); } }