Ejemplo n.º 1
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
                {
                    instanceStatus.Status = ProcessStatus.Initialized.Id;
                    instanceStatus.Update(connection);
                }
            }
        }
Ejemplo n.º 2
0
        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();
                }

                var oldLock = instanceStatus.Lock;

                instanceStatus.Lock   = Guid.NewGuid();
                instanceStatus.Status = ProcessStatus.Running.Id;

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

                if (cnt != 1)
                {
                    throw new ImpossibleToSetStatusException();
                }
            }
        }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
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();
                    }
                }
            }
        }