Esempio n. 1
0
        protected async Task <ProcessTaskEntity> CreateTaskAsync(ProcessInstanceEntity processInstance, FlowNodeEntity node)
        {
            if (!ProcessItemCheck.IsTask(node.ItemType))
            {
                throw new FlowNodeException(node.FlowNodeId, "Task");
            }

            //Create New Task
            ProcessTaskEntity task = new ProcessTaskEntity()
            {
                ProcessInstanceId = processInstance.Id,
                FlowNodeId        = node.Id,
                TaskId            = node.FlowNodeId,
                TaskType          = node.ItemType,
                Assignee          = null,           //TODO Set to default Assignee
                CreatedBy         = GetUserId(),
                TenantId          = TenantId
            };

            processTaskStore.Create(task);
            await SaveChangesAsync();

            return(task);

            //TODO Add to history
            //AddHistory(proc.Name, pi.ProcessInstanceName, t.ProcessTaskName, string.Format("User: {0} Created Task '{1}'", user, proc.Name), user);
        }
Esempio n. 2
0
        public async Task <ProcessTaskEntity> CreateTaskAsync(int processInstanceId, int nodeId, string nodeName, ProcessItemType ItemType)
        {
            if (!ProcessItemCheck.IsTask(ItemType))
            {
                throw new FlowNodeException(nodeName, "Task");
            }
            ProcessTaskEntity task = new ProcessTaskEntity()
            {
                ProcessInstanceId = processInstanceId,
                FlowNodeId        = nodeId,
                TaskId            = nodeName,
                TaskType          = ItemType,
                CreatedBy         = GetUserId()
            };

            TaskStore.Create(task);
            await SaveChangesAsync();

            return(task);

            //TODO Add to history
            //AddHistory(proc.Name, pi.ProcessInstanceName, t.ProcessTaskName, string.Format("User: {0} Created Task '{1}'", user, proc.Name), user);
        }
Esempio n. 3
0
        protected async Task <bool> ProcessFlowAsync(ProcessInstanceEntity processInstance, FlowNodeEntity flowNode)
        {
            bool result = false;

            if (ProcessItemCheck.IsSubProcess(flowNode.ItemType))
            {
                await StartProcessInstanceAsync(flowNode.FlowNodeId, processInstance.BusinessKey, processInstance.Id);
            }
            else if (ProcessItemCheck.IsTask(flowNode.ItemType))
            {
                await CreateTaskAsync(processInstance, flowNode);

                return(true);
            }
            else if (ProcessItemCheck.IsGateway(flowNode.ItemType))
            {
                if (ProcessItemCheck.IsExclusiveGateway(flowNode.ItemType))
                {
                    FlowNodeEntity    nextNode = null;
                    ExpressionContext context  = new ExpressionContext();
                    AddVariableCondition(context, await GetAllVariableAsync(processInstance.Id));

                    // Exclusive gateway is a diversion point of a business process flow.
                    // For a given instance of the process, there is only one of the paths can be taken.
                    // If two possible paths will only execute one but not both.
                    foreach (var sequence in await GetNextSequenceFlowAsync(flowNode.Id))
                    {
                        // Set default node
                        nextNode = await GetFlowAsync(sequence.SourceId);

                        if (!string.IsNullOrWhiteSpace(sequence.ConditionExpression) && EvaluateCondition(context, sequence.ConditionExpression))                // parse condition expression
                        {
                            break;
                        }
                    }
                    if (nextNode == null)
                    {
                        throw new ArgumentException("Next flow from flowNodeId: {0} is not found");
                    }
                    //Save Process Flow
                    await SaveProcessFlowAsync(processInstance.Id, flowNode.Id, nextNode.Id);

                    //Flow next process
                    await ProcessFlowAsync(processInstance, nextNode);
                }
                else if (ProcessItemCheck.IsInclusiveGateway(flowNode.ItemType))
                {
                    FlowNodeEntity    nextNode = null;
                    ExpressionContext context  = new ExpressionContext();
                    AddVariableCondition(context, await GetAllVariableAsync(processInstance.Id));

                    // Inclusive gateway is also a division point of the business process.
                    // Unlike the exclusive gateway, inclusive gateway may trigger more than 1 out-going paths.
                    // Since inclusive gateway may trigger more than 1 out-going paths, the condition checking process will have a little bit different then the exclusive gateway.
                    foreach (var sequence in await GetNextSequenceFlowAsync(flowNode.Id))
                    {
                        if (string.IsNullOrWhiteSpace(sequence.ConditionExpression) || EvaluateCondition(context, sequence.ConditionExpression))
                        {
                            //Get Node
                            nextNode = await GetFlowAsync(sequence.SourceId);

                            //Save Process Flow
                            await SaveProcessFlowAsync(processInstance.Id, flowNode.Id, nextNode.Id);

                            //Flow next process
                            await ProcessFlowAsync(processInstance, nextNode);
                        }
                    }
                }
                else
                {
                    // Process To Next Flow
                    foreach (var nextFlow in await GetNextFlowAsync(flowNode.Id))
                    {
                        await ProcessFlowAsync(processInstance, nextFlow);
                    }
                    return(true);
                }

                // process only if previous node is done
                if (await IsPrevNodeDoneAsync(flowNode, processInstance.Id))
                {
                    // Process To Next Flow
                    await ProcessToNextFlowAsync(processInstance, flowNode);

                    return(true);
                }
            }
            else if (ProcessItemCheck.IsEndEvent(flowNode.ItemType))
            {
                //await CancelAllPendingTaskAsync(processInstanceId);
                //await CancelAllSubProcessAsync(processInstanceId);
                //ProcessInstance update = await ProcessInstanceStore.FindByIdAsync(processInstanceId);
                //if (update.ParentProcessInstanceId.HasValue)
                //{
                //    update.Status = ProcessInstanceStatus.Completed;
                //    await ProcessInstanceStore.UpdateAsync(update);
                //    var proc = await ProcessStore.FindByIdAsync(update.ProcessId);
                //    var parent = await ProcessInstanceStore.FindByIdAsync(update.ParentProcessInstanceId.Value);
                //    // Process To Next Parent Flow
                //    await ProcessToNextFlow(parent.ProcessInstanceId, proc.FlowNodeId, ProcessItemType.SubProcess);
                //}
            }
            else
            {
                throw new NotSupportedException(string.Format("node '{0}' is not support yet", flowNode.ItemType.ToString()));
            }
            return(result);
        }