/// <summary> /// Loads work flow with the specified id. /// </summary> /// <param name="workflowId">The work flow id.</param> /// <returns>The work flow.</returns> public IStateMachineContext Load(Guid workflowId) { IWorkflowEntity workflowEntity = _workflowPersister.Load(workflowId); if (workflowEntity == null) { throw new ArgumentNullException(string.Format("The workflow with id {0} can not be loaded", workflowId)); } IStateMachine stateMachine = _stateMachineService.CreateStateMachine(workflowEntity.MachineConfiguration); object domainContext = null; StateMachineContext machineContext; if (_domainContextRepository != null) { domainContext = _domainContextRepository.Load(workflowEntity.DomainContextTypeDescription, workflowEntity.DomainContextId); } // there is a domain context and we have a status property if (domainContext != null && string.IsNullOrEmpty(workflowEntity.DomainContextStatusProperty) == false) { machineContext = new StateMachineContext(stateMachine, new ReflectiveDomainContextWrapper(domainContext, workflowEntity. DomainContextStatusProperty), this); } else { machineContext = new StateMachineContext(stateMachine, domainContext, this); } _stateField.SetValue(machineContext, stateMachine.FindStateByName(workflowEntity.CurrentState)); machineContext.Id = workflowId; return(machineContext); }