Beispiel #1
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();
                }
            }
        }
Beispiel #2
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();
                    }
                }
            }
        }