public void InitializeProcess(ProcessInstance processInstance) { var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); var oldProcess = dbcoll.FindOneById(processInstance.ProcessId); if (oldProcess != null) { throw new ProcessAlredyExistsException(); } var newProcess = new WorkflowProcessInstance { Id = processInstance.ProcessId, SchemeId = processInstance.SchemeId, ActivityName = processInstance.ProcessScheme.InitialActivity.Name, StateName = processInstance.ProcessScheme.InitialActivity.State }; dbcoll.Insert(newProcess); }
public void InitializeProcess(ProcessInstance processInstance) { var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); var oldProcess = dbcoll.Find(x => x.Id == processInstance.ProcessId).FirstOrDefault(); if (oldProcess != null) { throw new ProcessAlreadyExistsException(processInstance.ProcessId); } var newProcess = new WorkflowProcessInstance { Id = processInstance.ProcessId, SchemeId = processInstance.SchemeId, ActivityName = processInstance.ProcessScheme.InitialActivity.Name, StateName = processInstance.ProcessScheme.InitialActivity.State, RootProcessId = processInstance.RootProcessId, ParentProcessId = processInstance.ParentProcessId, Persistence = new List <WorkflowProcessInstancePersistence>() }; dbcoll.InsertOne(newProcess); }
public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId) { WorkflowProcessInstance processInstance = new WorkflowProcessInstance(); var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); { processInstance = dbcoll.FindOneById(processId); } if (processInstance == null) { throw new ProcessNotFoundException(); } if (!processInstance.SchemeId.HasValue) { throw new SchemeNotFoundException(); } var schemeDefinition = GetProcessSchemeBySchemeId(processInstance.SchemeId.Value); schemeDefinition.IsDeterminingParametersChanged = processInstance.IsDeterminingParametersChanged; return(schemeDefinition); }
public void UpdatePersistenceState(ProcessInstance processInstance, TransitionDefinition transition) { var paramIdentityId = processInstance.GetParameter(DefaultDefinitions.ParameterIdentityId.Name); var paramImpIdentityId = processInstance.GetParameter(DefaultDefinitions.ParameterImpersonatedIdentityId.Name); var identityId = paramIdentityId == null ? string.Empty : (string)paramIdentityId.Value; var impIdentityId = paramImpIdentityId == null ? identityId : (string)paramImpIdentityId.Value; var dbcoll = Store.GetCollection <WorkflowProcessInstance>(MongoDBConstants.WorkflowProcessInstanceCollectionName); WorkflowProcessInstance inst = dbcoll.FindOneById(processInstance.ProcessId); if (inst != null) { if (!string.IsNullOrEmpty(transition.To.State)) { inst.StateName = transition.To.State; } inst.ActivityName = transition.To.Name; inst.PreviousActivity = transition.From.Name; if (!string.IsNullOrEmpty(transition.From.State)) { inst.PreviousState = transition.From.State; } if (transition.Classifier == TransitionClassifier.Direct) { inst.PreviousActivityForDirect = transition.From.Name; if (!string.IsNullOrEmpty(transition.From.State)) { inst.PreviousStateForDirect = transition.From.State; } } else if (transition.Classifier == TransitionClassifier.Reverse) { inst.PreviousActivityForReverse = transition.From.Name; if (!string.IsNullOrEmpty(transition.From.State)) { inst.PreviousStateForReverse = transition.From.State; } } dbcoll.Save(inst); } var history = new WorkflowProcessTransitionHistory() { ActorIdentityId = impIdentityId, ExecutorIdentityId = identityId, Id = Guid.NewGuid(), IsFinalised = false, ProcessId = processInstance.ProcessId, FromActivityName = transition.From.Name, FromStateName = transition.From.State, ToActivityName = transition.To.Name, ToStateName = transition.To.State, TransitionClassifier = transition.Classifier.ToString(), TransitionTime = _runtime.RuntimeDateTimeNow, TriggerName = string.IsNullOrEmpty(processInstance.ExecutedTimer) ? processInstance.CurrentCommand : processInstance.ExecutedTimer }; var dbcollTransition = Store.GetCollection <WorkflowProcessTransitionHistory>(MongoDBConstants.WorkflowProcessTransitionHistoryCollectionName); dbcollTransition.Insert(history); }