Пример #1
0
        public void SetWorkflowRunning(ProcessInstance processInstance)
        {
            using (OracleConnection connection = new OracleConnection(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.LOCKFLAG;

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

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

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

                WorkflowProcessInstanceStatus.Commit(connection);
            }
        }
Пример #2
0
        private void SetCustomStatus(Guid processId, ProcessStatus status, bool createIfnotDefined = false)
        {
            using (OracleConnection connection = new OracleConnection(ConnectionString))
            {
                var instanceStatus = WorkflowProcessInstanceStatus.SelectByKey(connection, processId);
                if (instanceStatus == null)
                {
                    if (!createIfnotDefined)
                    {
                        throw new StatusNotDefinedException();
                    }

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

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

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

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

                WorkflowProcessInstanceStatus.Commit(connection);
            }
        }