public ProcessStatus GetInstanceStatus(Guid processId)
 {
     using (MySqlConnection connection = new MySqlConnection(ConnectionString))
     {
         var instance = WorkflowProcessInstanceStatus.SelectByKey(connection, processId);
         if (instance == null)
             return ProcessStatus.NotFound;
         var status = ProcessStatus.All.SingleOrDefault(ins => ins.Id == instance.Status);
         if (status == null)
             return ProcessStatus.Unknown;
         return status;
     }
 }
        public void SetWorkflowRunning(ProcessInstance processInstance)
        {
            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processInstance.ProcessId);
                if (instanceStatus == null)
                    throw new StatusNotDefinedException();

                if (instanceStatus.Status == ProcessStatus.Running.Id)
                    throw new ImpossibleToSetStatusException();

                instanceStatus.Lock = Guid.NewGuid();
                instanceStatus.Status = ProcessStatus.Running.Id;
                instanceStatus.Update(connection);
            }
        }
Exemple #3
0
        public void DeleteProcess(Guid processId)
        {
            using (var connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    WorkflowProcessInstance.Delete(connection, processId, transaction);
                    WorkflowProcessInstanceStatus.Delete(connection, processId, transaction);
                    WorkflowProcessInstancePersistence.DeleteByProcessId(connection, processId, transaction);
                    WorkflowProcessTransitionHistory.DeleteByProcessId(connection, processId, transaction);
                    WorkflowProcessTimer.DeleteByProcessId(connection, processId, null, transaction);
                    transaction.Commit();
                }
            }
        }
Exemple #4
0
        private void SetCustomStatus(Guid processId, ProcessStatus status, bool createIfnotDefined = false)
        {
            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processId);
                if (instanceStatus == null)
                {
                    if (!createIfnotDefined)
                    {
                        throw new StatusNotDefinedException();
                    }

                    instanceStatus = new WorkflowProcessInstanceStatus
                    {
                        Id     = processId,
                        Lock   = Guid.NewGuid(),
                        Status = ProcessStatus.Initialized.Id
                    };
                    instanceStatus.Insert(connection);
                }
                else
                {
                    var oldLock = instanceStatus.Lock;

                    instanceStatus.Status = status.Id;
                    instanceStatus.Lock   = Guid.NewGuid();

                    var cnt = WorkflowProcessInstanceStatus.ChangeStatus(connection, instanceStatus, oldLock);

                    if (cnt != 1)
                    {
                        throw new ImpossibleToSetStatusException();
                    }
                }
            }
        }