Example #1
0
 public void CreateFlowWithAssignId(Guid flowId, string flowName, User originator, string title, Dictionary<string, string> args = null, string comment = null)
 {
     var trans = TransactionManager.BeginTransaction();
     try
     {
         var flow = new Flow();
         flow.FlowStatus = FlowStatus.Instance;
         var flowType = _flowTypeRepository.GetByTypeName(flowName);
         if (flowType == null)
             throw new Exception(string.Format("{0}的流程类型不存在", flowName));
         flow.FlowType = flowType;
         flow.Id = flowId;
         flow.Title = title;
         args = args ?? new Dictionary<string, string>();
         args.ToList().ForEach(o => flow.FlowDataFields.Add(new FlowDataField { Name = o.Key, Value = o.Value }));
         flow.RecordDescription.CreateBy(originator);
         flow.UserOfFlowAdmin = originator;
         var history = new FlowHistory()
         {
             Comment = comment,
             Action = "提交流程",
             Stage = "发起流程"
         };
         history.RecordDescription.CreateBy(originator);
         flow.FlowHistories.Add(history);
         _flowRepository.Save(flow);
         trans.Commit();
     }
     catch (Exception)
     {
         trans.Rollback();
         throw;
     }
 }
Example #2
0
 private void Finished(Flow flow)
 {
     flow.Finished();
     _flowRepository.Save(flow);
 }
Example #3
0
 private void DealSingleFlowNode(Flow flow, MessageContainer messageContainer)
 {
     if (!flow.IsCompleted())
         return;
     flow.Finished();
     _flowRepository.Save(flow);
 }
Example #4
0
 private void DealServerNodeLoop(Flow flow, FlowNode targetFlowNode, MessageContainer messageContainer)
 {
     var nodes = new Stack<FlowNodeInstance>();
     var node = DealServerNode(flow, targetFlowNode, messageContainer);
     if (node == null)
     {
         Finished(flow);
         return;
     }
     nodes.Push(node);
     while (nodes.Any())
     {
         //这里循环处理,主要是为了使服务器节点无延迟的即时处理,因为服务器节点仅依赖流程变量与客户无关
         //而客户节点肯定是依赖于客户的操作来处理
         var tempFlowNodeInstance = nodes.Pop();
         if (!tempFlowNodeInstance.BelongsFlowNode.IsServerNode)
         {
             DealClientNode(flow, tempFlowNodeInstance.GetNextNodeTypeWhenActioned(), messageContainer);
             return;
         }
         var returnNodeInstanace = DealServerNode(flow, tempFlowNodeInstance.GetNextNodeTypeWhenActioned(), messageContainer);
         //服务端与客户端的区别,服务端的处理完之后就已经Finished了,所以直接接着处理下一个节点,
         //如果是客户端则需要生成客户端任务,服务端则继续执行服务端的处理
         if (returnNodeInstanace == null)
         {
             Finished(flow);
             return;
         }
         nodes.Push(returnNodeInstanace);
     }
 }
Example #5
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;
 }
Example #6
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;
 }
Example #7
0
        private void CreateSingleFlowNodeInstance(Flow flow, MessageContainer messageContainer)
        {
            var trans = TransactionManager.BeginTransaction();
            try
            {
                var flowNode = flow.FlowType.GetFirstNode();
                if (flowNode == null)
                    throw new ApplicationException("流程不存在任务节点,流程 id=" + flow.Id);
                if (flowNode.IsServerNode)
                    DealServerNodeLoop(flow, flowNode, messageContainer);
                else
                    DealClientNode(flow, flowNode, messageContainer);

                flow.FlowStatus = FlowStatus.Start;
                flow.RecordDescription.DateOfLastestModify = DateTime.Now;
                _flowRepository.Save(flow);
                trans.Commit();
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;
            }
        }