예제 #1
0
 public static FlowNodeInstanceResult ToDto(FlowNodeInstance flowNodeInstance)
 {
     return(new FlowNodeInstanceResult
     {
         Id = flowNodeInstance.EltId,
         ActivityState = flowNodeInstance.ActivityState == null ? null : Enum.GetName(typeof(ActivityStates), flowNodeInstance.ActivityState),
         FlowNodeId = flowNodeInstance.FlowNodeId,
         Metadata = flowNodeInstance.Metadata,
         State = Enum.GetName(typeof(FlowNodeStates), flowNodeInstance.State),
         ActivityStates = flowNodeInstance.ActivityStates.Select(_ => ActivityStateHistoryResult.ToDto(_)).ToList()
     });
 }
예제 #2
0
 public static FlowNodeInstanceModel ToModel(this FlowNodeInstance flowNodeInstance)
 {
     return(new FlowNodeInstanceModel
     {
         State = flowNodeInstance.State,
         Id = flowNodeInstance.Id,
         Metadata = flowNodeInstance.Metadata,
         ActivityState = flowNodeInstance.ActivityState,
         FlowNodeId = flowNodeInstance.FlowNodeId,
         ActivityStates = flowNodeInstance.ActivityStates.Select(_ => _.ToModel()).ToList()
     });
 }
예제 #3
0
        private void DealSingleFlowNodeFlowTo(FlowNodeInstance flowNodeInstance, MessageContainer messageContainer)
        {
            var trans = TransactionManager.BeginTransaction();
            try
            {
                //判断流程对象是否ActionCompleted
                if (!flowNodeInstance.TriggerActionCompletedRule())
                    return;
                var nextNode = flowNodeInstance.GetNextNodeTypeWhenActioned();
                flowNodeInstance.Finished();
                flowNodeInstance.FlowNodeInstanceTasks.ToList().ForEach(task =>
                {
                    if (task.RecordDescription.IsUpdated)
                    {
                        _flowNodeInstanceTaskRepository.Save(task);
                    }
                });
                _flowNodeInstanceRepository.Save(flowNodeInstance);
                //如果不存在下一个节点表示流程完成
                if (nextNode == null)
                {
                    Finished(flowNodeInstance.BelongsFlow);
                    trans.Commit();
                    return;
                }

                if (nextNode.IsServerNode)
                    DealServerNodeLoop(flowNodeInstance.BelongsFlow, nextNode, messageContainer);
                else
                    DealClientNode(flowNodeInstance.BelongsFlow, nextNode, messageContainer);

                trans.Commit();
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;
            }
        }
예제 #4
0
 private FlowNodeInstance DealServerNode(Flow flow, FlowNode targetFlowNode, MessageContainer messageContainer)
 {
     if (targetFlowNode == null)
         return null;
     //生成服务端节点实例
     var newFlowInstanceOfServer = new FlowNodeInstance();
     newFlowInstanceOfServer.BelongsFlow = flow;
     newFlowInstanceOfServer.BelongsFlowNode = targetFlowNode;
     newFlowInstanceOfServer.TimeOfFinished = DateTime.Now;
     newFlowInstanceOfServer.Execute();
     newFlowInstanceOfServer.InstanceStatus = InstanceStatus.Finished;
     _flowNodeInstanceRepository.Save(newFlowInstanceOfServer);
     return newFlowInstanceOfServer;
 }
예제 #5
0
 private FlowNodeInstance DealClientNode(Flow flow, FlowNode targetFlowNode, MessageContainer messageContainer)
 {
     //创建新节点实例
     var newFlowInstance = new FlowNodeInstance();
     newFlowInstance.BelongsFlow = flow;
     newFlowInstance.BelongsFlowNode = targetFlowNode;
     var newTasks = newFlowInstance.BuilderTasksAndReturnNewTasks();
     _flowNodeInstanceRepository.Save(newFlowInstance);
     newTasks.ToList().ForEach(task => _flowNodeInstanceTaskRepository.Save(task));
     return newFlowInstance;
 }
예제 #6
0
파일: Flow.cs 프로젝트: chenchunwei/NPC
 public virtual FlowNodeInstance Goto(string nodeName, Dictionary<string, string> args = null)
 {
     //HACK:这种跳转动作因为涉及到多个聚合根,所以不适合放在单独某个聚合根中,这里这样做是因为大家配置了双向关联,实现比较方便,但是这里违背了聚合的边界
     //会造成持久化上的一些困镜。除非抛弃持久化时聚合的边界
     var targetNode = FlowType.FlowNodes.First(o => o.Name.ToLower() == nodeName.ToLower());
     if (targetNode == null)
         throw new ArgumentException("要跳转的目标节点不存在");
     //合并流程变量
     WriteDataFields(args);
     //把当前执行的节点设置成忽略状态并创建新的流程实例
     FlowNodeInstances.ToList().ForEach(nodeInstance =>
     {
         if (!nodeInstance.TriggerActionCompletedRule())
         {
             nodeInstance.Ignore();
         }
     });
     var newInstance = new FlowNodeInstance();
     newInstance.BelongsFlow = this;
     newInstance.BelongsFlowNode = targetNode;
     newInstance.RecordDescription.CreateBy(null);
     newInstance.BuilderTasksAndReturnNewTasks();
     FlowNodeInstances.Add(newInstance);
     return newInstance;
 }
예제 #7
0
파일: Flow.cs 프로젝트: chenchunwei/NPC
 /// <summary>
 /// 执行流程,让流程继续流转
 /// </summary>
 public FlowNodeInstance ExecuteFlowTo()
 {
     //HACK:这个方法本来不应该存在的。因为这里需要流程节点实例,及节点任务来共同决定的,涉及到三个聚合根,不能在某一个聚合 中来完成
     //HACK:以及这里只考虑到单节点激活,不考虑并行节点等因素,后期需要改造支持并行节点以及自由节点多点触发的问题(国强提到过的多点触发,可以解决并行节点不能实现自由节点间排列组合的问题)
     //但自由组合带来的新问题是节点会可能没有约束的向着多个方法流动,无法控制流程的正常合并与结束
     var instancesInActioned = FlowNodeInstances.Single(o => o.InstanceStatus == InstanceStatus.ActionCompleted || o.BelongsFlowNode.IsServerNode && o.InstanceStatus != InstanceStatus.Finished);
     if (instancesInActioned.TriggerActionCompletedRule())
     {
         instancesInActioned.Finished();
         var next = instancesInActioned.GetNextNodeTypeWhenActioned();
         var newInstance = new FlowNodeInstance();
         newInstance.BelongsFlow = this;
         newInstance.BelongsFlowNode = next;
         newInstance.RecordDescription.CreateBy(null);
         FlowNodeInstances.Add(newInstance);
         if (next.IsServerNode)
         {
             //HACK:存在堆栈溢出的风险,当然机率非常小,除非流程中海量的服务节点
             return ExecuteFlowTo();
         }
         return newInstance;
     }
     return null;
 }