Exemple #1
0
        public static InstanceManager CreateWorkflowManager(Workflow workflow, IRepositoryHelper repoHelper)
        {
            Enforce.ArgumentNotNull(workflow, nameof(workflow));
            Enforce.ArgumentNotNull(repoHelper, nameof(repoHelper));

            var instance = new WorkflowInstance {
                WorkflowId = workflow.Id, CurrentStateId = workflow.StartState
            };
            var repo = repoHelper.GetWorkflowInstanceRepository(repoHelper.GetUnitOfWork());
            var id   = repo.Insert(instance);

            if (!string.IsNullOrWhiteSpace(id))
            {
                repoHelper.GetUnitOfWork().SaveChanges();
                var statePersistance = new InstanceStatePersistence(instance.Id, repoHelper);
                var stateMachine     = ConfigureStateMachine(workflow, statePersistance, repoHelper);
                return(new InstanceManager(instance, workflow, stateMachine, statePersistance, repoHelper));
            }
            return(null);
        }