Beispiel #1
0
 public void InitializeProcess(ProcessInstance processInstance)
 {
     using (var session = Store.OpenSession())
     {
         var oldProcess = session.Load <WorkflowProcessInstance>(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
         };
         session.Store(newProcess);
         session.SaveChanges();
     }
 }
Beispiel #2
0
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            WorkflowProcessInstance processInstance = new WorkflowProcessInstance();

            using (var session = Store.OpenSession())
            {
                processInstance = session.Load <WorkflowProcessInstance>(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);
        }
Beispiel #3
0
        public void UpdatePersistenceState(ProcessInstance processInstance, TransitionDefinition transition)
        {
            var paramIdentityId    = processInstance.GetParameter(DefaultDefinitions.ParameterIdentityId.Name);
            var paramImpIdentityId = processInstance.GetParameter(DefaultDefinitions.ParameterImpersonatedIdentityId.Name);

            string identityId    = paramIdentityId == null ? string.Empty : (string)paramIdentityId.Value;
            string impIdentityId = paramImpIdentityId == null ? identityId : (string)paramImpIdentityId.Value;

            using (var session = Store.OpenSession())
            {
                WorkflowProcessInstance inst = session.Load <WorkflowProcessInstance>(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;
                        }
                    }
                }

                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
                };

                session.Store(history);
                session.SaveChanges();
            }
        }