Exemplo n.º 1
0
        public void SaveGlobalParameter <T>(string type, string name, T value)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                var parameter = WorkflowGlobalParameter.SelectByTypeAndName(connection, type, name).FirstOrDefault();

                if (parameter == null)
                {
                    parameter = new WorkflowGlobalParameter()
                    {
                        Id    = Guid.NewGuid(),
                        Type  = type,
                        Name  = name,
                        Value = JsonConvert.SerializeObject(value)
                    };

                    parameter.Insert(connection);
                }
                else
                {
                    parameter.Value = JsonConvert.SerializeObject(value);

                    parameter.Update(connection);
                }

                WorkflowProcessInstance.Commit(connection);
            }
        }
Exemplo n.º 2
0
 public bool IsProcessExists(Guid processId)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         return(WorkflowProcessInstance.SelectByKey(connection, processId) != null);
     }
 }
Exemplo n.º 3
0
 public void DeleteGlobalParameters(string type, string name = null)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         WorkflowGlobalParameter.DeleteByTypeAndName(connection, type, name);
         WorkflowProcessInstance.Commit(connection);
     }
 }
Exemplo n.º 4
0
 private WorkflowProcessInstance GetProcessInstance(Guid processId)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         var processInstance = WorkflowProcessInstance.SelectByKey(connection, processId);
         if (processInstance == null)
         {
             throw new ProcessNotFoundException();
         }
         return(processInstance);
     }
 }
Exemplo n.º 5
0
        public void DeleteProcess(Guid processId)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                WorkflowProcessInstance.Delete(connection, processId);
                WorkflowProcessInstanceStatus.Delete(connection, processId);
                WorkflowProcessInstancePersistence.DeleteByProcessId(connection, processId);
                WorkflowProcessTransitionHistory.DeleteByProcessId(connection, processId);
                WorkflowProcessTimer.DeleteByProcessId(connection, processId);

                WorkflowProcessInstance.Commit(connection);
            }
        }
Exemplo n.º 6
0
        public void BindProcessToNewScheme(ProcessInstance processInstance, bool resetIsDeterminingParametersChanged)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                var oldProcess = WorkflowProcessInstance.SelectByKey(connection, processInstance.ProcessId);
                if (oldProcess == null)
                {
                    throw new ProcessNotFoundException();
                }

                oldProcess.SchemeId = processInstance.SchemeId;
                if (resetIsDeterminingParametersChanged)
                {
                    oldProcess.IsDeterminingParametersChanged = false;
                }
                oldProcess.Update(connection);
                WorkflowProcessInstance.Commit(connection);
            }
        }
Exemplo n.º 7
0
        public SchemeDefinition <XElement> GetProcessSchemeByProcessId(Guid processId)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                var processInstance = WorkflowProcessInstance.SelectByKey(connection, 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);
            }
        }
Exemplo n.º 8
0
 public void InitializeProcess(ProcessInstance processInstance)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         var oldProcess = WorkflowProcessInstance.SelectByKey(connection, 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,
             RootProcessId   = processInstance.RootProcessId,
             ParentProcessId = processInstance.ParentProcessId
         };
         newProcess.Insert(connection);
         WorkflowProcessInstance.Commit(connection);
     }
 }
Exemplo n.º 9
0
        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;

            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                WorkflowProcessInstance inst = WorkflowProcessInstance.SelectByKey(connection, 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;
                        }
                    }

                    inst.ParentProcessId = processInstance.ParentProcessId;
                    inst.RootProcessId   = processInstance.RootProcessId;

                    inst.Update(connection);
                }

                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
                };
                history.Insert(connection);
                WorkflowProcessTransitionHistory.Commit(connection);
            }
        }