Ejemplo n.º 1
0
        public static void FinishSubRouting <T>(TransInfoDto transDto)
        {
            var sqlDbContext   = transDto.Context as MainWorkflowUnitOfWork;
            var newActivities  = new HashSet <Guid>();
            var nextActivities = XmlHelper.GetAllNextActivities(transDto.TemplateXml, transDto.InstanceNodeId);

            nextActivities.ToList().ForEach(p =>
            {
                newActivities.Add(Guid.Parse(p.Element(ActivityConst.ID).Value));
            });
            // 回到父流程节点
            var finisheds = TransRoutingHelper.InstanceFinished(newActivities, transDto.TaskId, transDto.InstanceId, sqlDbContext);

            // 新生成的节点
            foreach (var item in finisheds)
            {
                // 首先获取模板上面的ID
                var parentNode = sqlDbContext.NSNodeInfos.First(p => p.TaskId == transDto.TaskId && p.InstanceId == transDto.InstanceId && p.Id == transDto.ParentId);

                if (parentNode != null)
                {
                    var      instnace  = sqlDbContext.NsInstanceInfos.First(p => p.Id == transDto.InstanceId);
                    XElement parentDoc = XElement.Parse(sqlDbContext.NSTemplateInfos.First(p => p.Id == instnace.TemplateId).TemplateText);
                    // 获取节点名称
                    var nodeInfos = from c in parentDoc.Elements("DesignerItems").Elements("DesignerItem")
                                    where c.Element("ID").Value == parentNode.NodeId.ToString()
                                    select c;

                    foreach (var nodeInfo in nodeInfos)
                    {
                        TransRouting.Routing(parentDoc, nodeInfo, parentNode, sqlDbContext, newActivities);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public virtual void EndBuiness(TransInfoDto transInfoDto)
 {
     if (Ending != null)
     {
         Ending(this, new WFArgs(transInfoDto));
     }
 }
Ejemplo n.º 3
0
 public virtual void StartBuiness(TransInfoDto transInfoDto)
 {
     if (Starting != null)
     {
         Starting(this, new WFArgs(transInfoDto));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 结束流程
        /// </summary>
        /// <param name="dto">要用到的Dto</param>
        public void EndInstance(TransInfoDto dto)
        {
            // 结束当前流程
            var instance = dto.Persistence.FinishInstance(dto.InstanceId);

            // 查找是否需要回归到父流程
            if (instance.ParentNodeId.HasValue)
            {
                var backToParent = dto.Persistence.FinishRouting(dto.TaskId, instance.ParentNodeId.Value, ActivityConst.GROUPNAME_INSTANCE);
                // 如果不回归到主流程上
                if (backToParent == null)
                {
                    // 结束当前任务
                    dto.Persistence.FinishTask(dto.TaskId);
                }
                else
                {
                    // 回归到上一个点
                    var copyInfo = dto.GetCopyInfo();
                    copyInfo.InstanceId     = backToParent.InstanceId;
                    copyInfo.ActivityType   = ActivityTypeEnum.SubRouting;
                    copyInfo.InstanceNodeId = backToParent.Id;
                    EndRouing(copyInfo);
                }
            }
            else
            {
                // 结束任务
                dto.Persistence.FinishTask(dto.TaskId);
            }
        }
Ejemplo n.º 5
0
 public void End(TransInfoDto transInfoDto)
 {
     try
     {
         EndBuiness(transInfoDto);
     }
     catch (Exception ex)
     {
         throw new WFRoutingException(this.ToString() + "在结束节点时候出现异常:" + ex.ToString());
     }
 }
Ejemplo n.º 6
0
 public void Start(TransInfoDto transInfoDto)
 {
     try
     {
         StartBuiness(transInfoDto);
     }
     catch (Exception ex)
     {
         throw new WFRoutingException(this.ToString() + "在创建节点时候出现异常:" + ex.ToString());
     }
 }
Ejemplo n.º 7
0
 public virtual void TransactBuiness(TransInfoDto transInfoDto)
 {
     try
     {
         if (Transacting != null)
         {
             Transacting(this, new WFArgs(transInfoDto));
         }
     }
     catch (Exception ex)
     {
         throw new WFRoutingException(this.ToString() + "在执行的时候出现异常:" + ex.ToString());
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 路由工厂
 /// </summary>
 /// <param name="newActivities">新的集合</param>
 /// <param name="dto">传输的实体</param>
 public void RoutingFactory(List <XElement> newActivities, TransInfoDto dto)
 {
     if (newActivities != null && newActivities.Count > 0)
     {
         newActivities.ToList().ForEach(p =>
         {
             var copyDto            = dto.GetCopyInfo();
             copyDto.InstanceNodeId = p.ParseById();
             copyDto.Activity       = p;
             copyDto.GroupName      = p.ParseByGroupName();
             copyDto.ActivityType   = EnumHelper.GetEnumByString <ActivityTypeEnum>(XmlHelper.GetSafeValue(p, ActivityConst.TYPE));
             RoutingFactory(copyDto);
         });
     }
     else if (newActivities != null && newActivities.Count() == 0)
     {
         EndInstance(dto);
     }
 }
Ejemplo n.º 9
0
        public override void EndBuiness(TransInfoDto transInfoDto)
        {
            // 启动新流程,记录到流程的ID,任务ID等信息
            IPersistence p = transInfoDto.Persistence;
            // 结束当前点状态
            NSNodeInfo     nsNodeInfo = p.GetActivityByID(transInfoDto.InstanceNodeId);
            NSInstanceInfo nsInstance = p.GetInsanceInfo(nsNodeInfo.InstanceId);
            NSTemplateInfo nsTemplate = p.GetTemplateInfo(nsInstance.TemplateId);

            p.FinishActivity(nsNodeInfo);
            //TODO: 产生新的节点,如果在回归之后继续执行逻辑,则要有全局的传递,以后在进行添加
            var nextActivities = XmlHelper.GetAllNextActivities(nsTemplate.TemplateText, nsNodeInfo.NodeId);

            if (nextActivities != null)
            {
                new RoutingHost().RoutingFactory(nextActivities.ToList(), transInfoDto);
            }
            base.EndBuiness(transInfoDto);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 结束节点
        /// </summary>
        /// <param name="dto"></param>
        public void EndRouing(TransInfoDto dto)
        {
            IBookmark bookmarkInfo = BookmarkFactory.GetBookmark(dto.ActivityType);

            // 结束并发
            if (dto.SubmitType == SubmitTypeEnum._SP)
            {
                XElement parallelStart = null;
                // 获取对应的并发等待节点
                var doc = XElement.Parse(dto.TemplateXml);
                XmlHelper.GetFirstParalle(doc, dto.InstanceNodeId, ref parallelStart);

                if (parallelStart == null)
                {
                    throw new Exception("没有找到并发起始节点");
                }

                if (XmlHelper.HasValue(parallelStart, "GroupName"))
                {
                    HashSet <Guid>           parallelNodes = new HashSet <Guid>();
                    Dictionary <string, int> parallelCount = new Dictionary <string, int>();
                    var copyInfo = dto.GetCopyInfo();
                    copyInfo.InstanceNodeId = Guid.Parse(XmlHelper.GetSafeValue(parallelStart, ActivityConst.ID));
                    parallelCount.Add(copyInfo.TaskId + XmlHelper.GetSafeValue(parallelStart, "GroupName"), 1);
                    XmlHelper.TraversingGraphParallel(doc, parallelStart.ParseById(), null);
                    StopAll(parallelStart.Element("GroupName").Value, copyInfo, parallelNodes, ref parallelCount);
                    dto.Persistence.FinishActivityByNodeIds(copyInfo.InstanceId, parallelNodes.ToList(), RunStateConst.STOP);
                }

                return;
            }

            bookmarkInfo.Ending += (s, r) =>
            {
                var args = r as WFArgs;
                if (args.Parameter.NextActivities != null)
                {
                    RoutingFactory(args.Parameter.NextActivities, dto);
                }
            };
            bookmarkInfo.End(dto);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 路由工厂
        /// </summary>
        /// <param name="dto"></param>
        public void RoutingFactory(TransInfoDto dto)
        {
            IBookmark bookmarkInfo = BookmarkFactory.GetBookmark(dto.ActivityType);

            bookmarkInfo.Start(dto);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 停止所有
        /// </summary>
        /// <param name="groupName">分组名称</param>
        /// <param name="dto">传输Dto</param>
        /// <param name="parallelNodes">并发内部节点</param>
        /// <param name="parallelCount">并发数量(并发内并发)</param>
        private void StopAll(string groupName, TransInfoDto dto, HashSet <Guid> parallelNodes, ref Dictionary <string, int> parallelCount)
        {
            var template = XElement.Parse(dto.TemplateXml);

            // 查找父节点中的第一个节点
            var custs = from c in template.Elements("Connections").First().Elements("Connection")
                        where c.Element("SourceID").Value == dto.InstanceNodeId.ToString()
                        select c.Element("SinkID").Value;

            // 获取节点名称
            var nodeInfoLinks = from c in template.Elements("DesignerItems").Elements("DesignerItem")
                                where custs.Contains(c.Element("ID").Value)
                                select c;

            foreach (var item in nodeInfoLinks)
            {
                var copyInfo = dto.GetCopyInfo();
                copyInfo.SubmitType     = SubmitTypeEnum._SB;
                copyInfo.InstanceNodeId = item.ParseById();
                if (item.ParseByActivityType() == "Process")
                {
                    var activiy = JsonHelper.JsonToT <StandBookmark>(item.ParseByDetails());
                    if (activiy.IsParallel == true)
                    {
                        if (!parallelCount.Keys.Contains(copyInfo.TaskId + groupName))
                        {
                            parallelCount.Add(copyInfo.TaskId + groupName, nodeInfoLinks.Count());
                        }
                    }

                    parallelNodes.Add(copyInfo.InstanceNodeId);
                    StopAll(groupName, copyInfo, parallelNodes, ref parallelCount);
                }
                else
                {
                    if (item.ParseByActivityType() == "Parallel" && item.ParseByGroupName() == groupName)
                    {
                        copyInfo.GroupName = groupName;
                        parallelCount[copyInfo.TaskId + groupName] = parallelCount[copyInfo.TaskId + groupName] - 1;
                        if (parallelCount[copyInfo.TaskId + groupName] == 0)
                        {
                            parallelCount.Remove(copyInfo.TaskId + groupName);
                            copyInfo.Persistence.FinishParallel(copyInfo.TaskId, copyInfo.InstanceId, groupName);
                            var nextActivities = XmlHelper.GetAllNextActivities(copyInfo.TemplateXml, Guid.Parse(XmlHelper.GetSafeValue(item, ActivityConst.ID)));
                            if (nextActivities != null && nextActivities.Count() > 0)
                            {
                                RoutingFactory(nextActivities.ToList(), copyInfo);
                            }
                        }
                    }
                    else
                    {
                        parallelCount[copyInfo.TaskId + item.ParseByGroupName()] = parallelCount[copyInfo.TaskId + item.ParseByGroupName()] - 1;
                        if (parallelCount[copyInfo.TaskId + groupName] == 0)
                        {
                            StopAll(groupName, copyInfo, parallelNodes, ref parallelCount);
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public override void StartBuiness(TransInfoDto transInfo)
        {
            // 启动新流程,记录到流程的ID,任务ID等信息
            IPersistence       p             = transInfo.Persistence;
            SubRoutingBookmark submitRouting = JsonHelper.JsonToT <SubRoutingBookmark>(XmlHelper.GetSafeValue(transInfo.Activity, ActivityConst.DETAILS));

            this.TemplateName = submitRouting.TemplateName;
            this.TemplateId   = submitRouting.TemplateId;
            this.Name         = submitRouting.Name;

            // 生成回归点
            NSNodeInfo nsNodeInfo = new NSNodeInfo();

            nsNodeInfo.Id         = Guid.NewGuid();
            nsNodeInfo.TaskId     = transInfo.TaskId;
            nsNodeInfo.InstanceId = transInfo.InstanceId;
            nsNodeInfo.NodeName   = this.Name;
            nsNodeInfo.ParentId   = transInfo.ParentId;
            nsNodeInfo.RunState   = EnumExt.RunStateConst.RUNNING;
            nsNodeInfo.CreateTime = DateTime.Now;
            nsNodeInfo.NodeId     = Guid.Parse(XmlHelper.GetSafeValue(transInfo.Activity, ActivityConst.ID));
            p.CreateActivity(nsNodeInfo);

            // 生成路由信息
            NSRoutingInfo nsRoutingInfo = new NSRoutingInfo();

            nsRoutingInfo.Id           = Guid.NewGuid();
            nsRoutingInfo.InstanceId   = transInfo.InstanceId;
            nsRoutingInfo.ParentId     = nsNodeInfo.Id;
            nsRoutingInfo.TaskId       = transInfo.TaskId;
            nsRoutingInfo.GroupName    = ActivityConst.GROUPNAME_INSTANCE;
            nsRoutingInfo.GroupCounter = 1;
            p.CreateRoutingInfo(nsRoutingInfo);

            // 流程实例信息
            NSInstanceInfo insanceInfo = new NSInstanceInfo();

            insanceInfo.InstanceName = submitRouting.TemplateName;
            insanceInfo.RunState     = EnumExt.RunStateConst.RUNNING;
            insanceInfo.StartTime    = DateTime.Now;
            insanceInfo.TemplateId   = this.TemplateId;
            insanceInfo.Id           = Guid.NewGuid();
            insanceInfo.TaskId       = transInfo.TaskId;
            insanceInfo.TemplateName = this.TemplateName;
            insanceInfo.ParentNodeId = nsNodeInfo.Id;
            p.CreateInstance(insanceInfo);

            TransInfoDto copyInfo = transInfo.GetCopyInfo();

            copyInfo.InstanceId = insanceInfo.Id;

            copyInfo.TemplateXml = p.GetTemplateInfo(insanceInfo.TemplateId).TemplateText;
            // 生成子流程的第一个节点
            var startActivities = XmlHelper.GetTemplateFirstActivity(XElement.Parse(copyInfo.TemplateXml));

            if (startActivities != null)
            {
                new RoutingHost().RoutingFactory(startActivities.ToList(), copyInfo);
            }
            base.StartBuiness(transInfo);
        }
Ejemplo n.º 14
0
//        public string SubmitWorkflow(SubmitInfo_DTO submitInfo)
//        {
//            if (submitInfo == null)
//                return "提交信息不能为空!";

//            if (!string.IsNullOrEmpty(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult)))
//                return _iSubmitValidation.ValidateMsg(submitInfo.SubmitResult);

//            if (!Locker.Add(submitInfo.NodeId))
//                return "请不要重复提交!";

//            // 读取模板
//            TemplateRepository tr = new TemplateRepository(Context);
//            InstanceInfoRepository iir = new InstanceInfoRepository(Context);
//            NodeInfoRepository nir = new NodeInfoRepository(Context);
//            HashSet<Guid> newActivities = new HashSet<Guid>();
//            var node = nir.Get(submitInfo.NodeId);

//            if (node != null)
//            {
//                node.SubmitResult = submitInfo.SubmitResult;
//                var instance = iir.Get(node.InstanceId);
//                if (instance != null)
//                {
//                    var templateInfo = tr.Get(instance.TemplateId);

//                    // 解析
//                    XElement doc = XElement.Parse(templateInfo.TemplateText);

//                    // 结束并发
//                    if (submitInfo.SubmitResult.StartsWith(SubmitTypeEnum._SP.ToString()))
//                    {

//                        // 停止并发
//                        TransRouting.StopParallel(doc, instance.TaskId, node, Context, node.NodeId);
//                    }
//                    // 驳回
//                    else if (submitInfo.SubmitResult.StartsWith(SubmitTypeEnum._BK.ToString()))
//                    {
//                        // 找到要驳回的点的名称
//                        string backNodeName = submitInfo.SubmitResult.Substring(4);

//                        // 在模板上找到的对应的点
//                        XElement templateXml = XElement.Parse(templateInfo.TemplateText);
//                        var nodeInfos = from c in templateXml.Elements("DesignerItems").Elements("DesignerItem")
//                                        where c.Element("Name").Value == backNodeName
//                                        select c;
//                        if (nodeInfos.Count() == 0)
//                            throw new Exception("驳回的点不存在!");
//                        // 结束该点下的所有点

//#warning 上一节点,下一个节点
//                        HashSet<Guid> stopAllNodes = new HashSet<Guid>();
//                        HashSet<Guid> hasAlreadyFinds = new HashSet<Guid>();
//                        TransRouting.FindAllNext(templateXml, nodeInfos.First(), node.TaskId, node.InstanceId, Context, stopAllNodes, hasAlreadyFinds);
//                        stopAllNodes.Add(node.NodeId);
//                        var stopNodeInfos = Context.NSNodeInfos.Where(p => p.InstanceId == node.InstanceId && p.RunState == RUNNING && stopAllNodes.Contains(p.NodeId));
//                        foreach (var nodeInfo in stopNodeInfos)
//                        {
//                            nodeInfo.RunState = RunStateEnum.end.ToString();
//                        }
//                        TransRouting.Routing(doc, nodeInfos.First(), node, Context, newActivities);
//                    }
//                    else
//                    {
//                        ///  查找驳回点并生成新的节点
//                        var custsExc = from c in doc.Elements("Connections").First().Elements("Connection")
//                                       where c.Element("SourceID").Value == node.NodeId.ToString()
//                                       select c.Element("SinkID").Value;

//                        // 结束当前的点
//                        node.RunState = RunStateEnum.end.ToString();
//                        nir.Modify(node);

//                        foreach (var item in custsExc)
//                        {
//                            // 获取节点名称
//                            var nodeInfos = from c in doc.Elements("DesignerItems").Elements("DesignerItem")
//                                            where c.Element("ID").Value == item
//                                            select c;
//                            foreach (var nodeInfo in nodeInfos)
//                            {
//                                TransRouting.Routing(doc, nodeInfo, node, Context, newActivities);
//                            }
//                        }
//                    }


//                    // 回到父流程节点
//                    var finisheds = TransRoutingHelper.InstanceFinished(newActivities, node.TaskId, node.InstanceId, Context);
//                    // 新生成的节点
//                    foreach (var item in finisheds)
//                    {

//                        // 首先获取模板上面的ID
//                        var parentNode = nir.Get(item);

//                        if (parentNode != null)
//                        {
//                            var instnace = iir.Get(parentNode.InstanceId);
//                            XElement parentDoc =XElement.Parse(tr.Get(instance.TemplateId).TemplateText);
//                            // 获取节点名称
//                            var nodeInfos = from c in parentDoc.Elements("DesignerItems").Elements("DesignerItem")
//                                            where c.Element("ID").Value == parentNode.NodeId.ToString()
//                                            select c;
//                            foreach (var nodeInfo in nodeInfos)
//                            {
//                                TransRouting.Routing(doc, nodeInfo, parentNode, Context, newActivities);
//                            }
//                        }
//                    }
//                }
//            }

//            try
//            {
//                Context.SaveChanges();
//            }
//            catch (DbEntityValidationException e)
//            {
//                StringBuilder sb = new StringBuilder();
//                foreach (var eve in e.EntityValidationErrors)
//                {
//                    sb.Append(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
//                        eve.Entry.Entity.GetType().Name, eve.Entry.State));
//                    foreach (var ve in eve.ValidationErrors)
//                    {
//                        sb.Append(string.Format("- Property: \"{0}\", Error: \"{1}\"",
//                            ve.PropertyName, ve.ErrorMessage));
//                    }
//                }
//                return sb.Append("持久化失败!").ToString();
//            }
//            catch (Exception ex)
//            {

//                return "提交失败";
//            }

//            return "提交成功!";
//        }

        public string SubmitWorkflow(SubmitInfo_DTO submitInfo)
        {
            StringBuilder result = new StringBuilder();

            try
            {
                #region 验证
                if (submitInfo == null)
                {
                    return("提交信息不能为空!");
                }

                if (!Locker.Add(submitInfo.NodeId))
                {
                    return("请不要重复提交!");
                }
                #endregion (验证)

                #region 获取节点信息
                TransInfoDto transInfoDto = new TransInfoDto();
                transInfoDto.Persistence  = DBFactory.GetPersistencePlugIn();
                transInfoDto.Context      = transInfoDto.Persistence.Context;
                transInfoDto.GroupCounter = submitInfo.ExpandDatas == null ? 0 : submitInfo.ExpandDatas.Count();
                var activity = transInfoDto.Persistence.GetActivityByID(submitInfo.NodeId);
                if (activity == null)
                {
                    return("要办理的节点已经不存在!");
                }
                #endregion (获取节点信息)

                #region 获取模板信息
                var instance = transInfoDto.Persistence.GetInsanceInfo(activity.InstanceId);
                var template = transInfoDto.Persistence.GetTemplateInfo(instance.TemplateId);
                #endregion (获取模板信息)


                #region 生成DTO信息
                transInfoDto.TaskId         = activity.TaskId;
                transInfoDto.InstanceId     = activity.InstanceId;
                transInfoDto.InstanceNodeId = activity.NodeId;
                transInfoDto.TemplateXml    = template.TemplateText;
                transInfoDto.ActivityType   = ActivityTypeEnum.Process;
                transInfoDto.Condition      = submitInfo.Condition;
                transInfoDto.SubmitType     = EnumHelper.GetEnumByString <SubmitTypeEnum>(submitInfo.SubmitResult);
                #endregion (生成DTO信息)

                var currentActivity = XmlHelper.GetActivitiesByName(template.TemplateText, activity.NodeName).First();
                transInfoDto.Activity = currentActivity;
                if (!string.IsNullOrEmpty(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult, transInfoDto)))
                {
                    Locker.Remove(submitInfo.NodeId);
                    return(_iSubmitValidation.ValidateMsg(submitInfo.SubmitResult, transInfoDto));
                }

                #region 提交
                new RoutingHost().EndRouing(transInfoDto);
                #endregion (提交)

                transInfoDto.Persistence.Context.SaveChanges();
            }
            catch (WFRoutingException rex)
            {
                LogHelper.WriteLog(rex.Message + rex.ToString());
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex.ToString());
            }

            return(result.ToString());
        }
Ejemplo n.º 15
0
 public void Transact(TransInfoDto transInfoDto)
 {
     TransactBuiness(transInfoDto);
 }
Ejemplo n.º 16
0
        public string ValidateMsg(string submitMsg, TransInfoDto dto)
        {
            // 如果是以命令开头
            if (submitMsg.StartsWith("_"))
            {
                if (submitMsg == SubmitTypeEnum._SP.ToString())
                {
                    List <Guid> searchNodes = new List <Guid>();
                    var         nodeId      = Guid.Parse(XmlHelper.GetSafeValue(dto.Activity, ActivityConst.ID));
                    searchNodes.Add(nodeId);
                    Stack <string> parallelStarts       = new Stack <string>();
                    Stack <string> parallelEnds         = new Stack <string>();
                    bool?          stopParallelValidate = null;
                    // 检查是否有起始的节点
                    Action <XElement> next    = null;
                    Action <XElement> forward = null;

                    forward = (e) =>
                    {
                        var parentActivities = XmlHelper.GetAllForwardActivities(dto.TemplateXml, nodeId);
                        foreach (var parentActivity in parentActivities)
                        {
                            var id = Guid.Parse(XmlHelper.GetSafeValue(parentActivity, ActivityConst.ID));

                            string bType = XmlHelper.GetSafeValue(parentActivity, ActivityConst.TYPE);
                            if (bType == ActivityTypeEnum.Process.ToString())
                            {
                                StandBookmark bookmark = JsonHelper.JsonToT <StandBookmark>(XmlHelper.GetSafeValue(parentActivity, ActivityConst.DETAILS));
                                if (bookmark.IsParallel)
                                {
                                    if (parallelEnds.Contains(bookmark.GroupName))
                                    {
                                        parallelEnds.Pop();
                                    }
                                    else
                                    {
                                        if (parallelEnds.Count() == 0)
                                        {
                                            stopParallelValidate = true;
                                        }
                                    }
                                }
                            }
                            else if (bType == ActivityTypeEnum.Parallel.ToString())
                            {
                                var groupName = XmlHelper.GetSafeValue(parentActivity, ActivityConst.GROUPNAME);
                                if (parallelEnds.Contains(XmlHelper.GetSafeValue(parentActivity, ActivityConst.GROUPNAME)))
                                {
                                    parallelEnds.Push(groupName);
                                    break;
                                }
                            }

                            if (!stopParallelValidate.HasValue && !searchNodes.Contains(id))
                            {
                                searchNodes.Add(id);
                                forward(parentActivity);
                            }
                        }
                    };

                    forward(dto.Activity);

                    if (stopParallelValidate != true)
                    {
                        return("该节点不支持并发结束");
                    }
                    return(string.Empty);
                }
                else if (submitMsg.StartsWith(SubmitTypeEnum._BK.ToString()))
                {
                    if (submitMsg.Split(':').Count() == 2)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return("退回必须要填写退回的节点名称!");
                    }
                }
                else if (submitMsg.StartsWith(SubmitTypeEnum._SB.ToString()) || submitMsg.StartsWith(SubmitTypeEnum._SP.ToString()))
                {
                    return(string.Empty);
                }
                else
                {
                    return("提交结构不合法!");
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 17
0
 public WFArgs(TransInfoDto transDto)
 {
     this.Parameter = transDto;
 }
Ejemplo n.º 18
0
        public static void Routing(XElement templateInfo, XElement currentNode, NSNodeInfo node, MainWorkflowUnitOfWork context, HashSet <Guid> newActivities)
        {
            switch (currentNode.Element("BType").Value)
            {
            case "Decision":
            {
                // 查找下一个节点,所有父为Switch的下一个节点的
                var childrenIds = from c in templateInfo.Elements("Connections").First().Elements("Connection")
                                  where c.Element("SourceID").Value == currentNode.Element("ID").Value&& c.Element("Condition").Value == node.SubmitResult
                                  select c.Element("SinkID").Value;

                if (childrenIds.Count() == 0)
                {
                    return;
                }

#warning  找到匹配的那个条件---条件待匹配
                var nodeInfos = from c in templateInfo.Elements("DesignerItems").Elements("DesignerItem")
                                where childrenIds.Contains(c.Element("ID").Value)
                                select c;

                foreach (var item in nodeInfos)
                {
                    Routing(templateInfo, item, node, context, newActivities);
                }
            }
            break;

            case "Parallel":
            {
                // 查询是否所有的节点都已经执行完成??
                // 查找下一个节点,所有父为Switch的下一个节点的
                var parentIds = from c in templateInfo.Elements("Connections").First().Elements("Connection")
                                where c.Element("SinkID").Value == currentNode.Element("ID").Value
                                select c.Element("SourceID").Value;

                // 查找是否已经存在了没有完成的计数器
                NSNodeGroup alreadyExistGroup = context.NsNodeGroups.Where(p => p.TaskId == node.TaskId &&
                                                                           p.InstanceId == node.InstanceId &&
                                                                           p.Finshed == false || p.Finshed == null).FirstOrDefault();

                if (alreadyExistGroup != null)
                {
                    alreadyExistGroup.GroupCounter = ++alreadyExistGroup.GroupCounter;
                    context.SetModified <NSNodeGroup>(alreadyExistGroup);
                }
                else
                {
                    if (alreadyExistGroup == null)
                    {
                        alreadyExistGroup = new NSNodeGroup();
                    }

                    alreadyExistGroup.Id           = Guid.NewGuid();
                    alreadyExistGroup.GroupCounter = 1;
                    alreadyExistGroup.GroupName    = "Parallel";
                    alreadyExistGroup.TaskId       = node.TaskId;
                    alreadyExistGroup.InstanceId   = node.InstanceId;
                    alreadyExistGroup.Finshed      = false;
                    context.NsNodeGroups.Add(alreadyExistGroup);
                }

                if (parentIds.Count() == alreadyExistGroup.GroupCounter)
                {
                    // 查找下一个节点,所有父为Switch的下一个节点的
                    var childrenIds = from c in templateInfo.Elements("Connections").First().Elements("Connection")
                                      where c.Element("SourceID").Value == currentNode.Element("ID").Value
                                      select c.Element("SinkID").Value;

                    alreadyExistGroup.Finshed = true;
                    if (childrenIds.Count() == 0)
                    {
                        return;
                    }

                    var nodeInfos = from c in templateInfo.Elements("DesignerItems").Elements("DesignerItem")
                                    where childrenIds.Contains(c.Element("ID").Value)
                                    select c;
                    foreach (var item in nodeInfos)
                    {
                        Routing(templateInfo, item, node, context, newActivities);
                    }
                    return;
                }
            }
            break;

            case "Process":
            {
                NSNodeInfo nsNodeInfo = new NSNodeInfo();
                nsNodeInfo.Id         = Guid.NewGuid();
                nsNodeInfo.InstanceId = node.InstanceId;
                nsNodeInfo.TaskId     = node.TaskId;
                nsNodeInfo.NodeName   = currentNode.Element("Name").Value;
                nsNodeInfo.NodeId     = Guid.Parse(currentNode.Element("ID").Value);
                nsNodeInfo.RunState   = RunStateConst.RUNNING;
                nsNodeInfo.CreateTime = DateTime.Now;
                context.NSNodeInfos.Add(nsNodeInfo);
                newActivities.Add(nsNodeInfo.NodeId);
            }
            break;

            case "SubRouting":
            {
                SubRoutingBookmark submitRoutingBookmark = new SubRoutingBookmark();
                var dbPlugIn = DBFactory.GetPersistencePlugIn();

                TransInfoDto tranInfoDto = new TransInfoDto();
                tranInfoDto.InstanceId = node.InstanceId;
                tranInfoDto.TaskId     = node.TaskId;
                //TODO:容易出错的地方,暂时没有处理的
                tranInfoDto.TemplateXml = dbPlugIn.GetTemplateInfo(dbPlugIn.GetInsanceInfo(node.InstanceId).Id).TemplateText;
                tranInfoDto.ParentId    = node.Id;

                submitRoutingBookmark.Start(tranInfoDto);

                return;

                // 生成第一节点 调用启动流程
                NSNodeInfo parentNodeInfo = new NSNodeInfo();
                parentNodeInfo.Id         = Guid.NewGuid();
                parentNodeInfo.InstanceId = node.InstanceId;
                parentNodeInfo.TaskId     = node.TaskId;
                parentNodeInfo.NodeName   = currentNode.Element("Name").Value;
                parentNodeInfo.NodeId     = Guid.Parse(currentNode.Element("ID").Value);
                parentNodeInfo.RunState   = RunStateConst.RUNNING;
                parentNodeInfo.CreateTime = DateTime.Now;
                context.NSNodeInfos.Add(parentNodeInfo);

                NSInstanceInfo instance = new NSInstanceInfo();
                instance.InstanceName = "";             //读取的模板名称
                instance.TaskId       = node.TaskId;
                instance.TemplateId   = Guid.NewGuid(); // 湖区模板ID
                instance.RunState     = RunStateConst.RUNNING;
                instance.StartTime    = DateTime.Now;
                instance.Id           = Guid.NewGuid();
                instance.TemplateId   = JsonHelper.JsonToT <SubRoutingBookmark>(currentNode.Element("Details").Value).TemplateId;
                context.NsInstanceInfos.Add(instance);
                // 如果有个字段用来区分是子流程,那么就可以轻松的进行操作。

                // 生成第一个点
                var      childTemplate = context.NSTemplateInfos.First(p => p.Id == instance.TemplateId);
                string   templateXML   = childTemplate.TemplateText;
                XElement doc           = XElement.Parse(templateXML);
                var      nodeInfos     = from c in doc.Elements("DesignerItems").Elements("DesignerItem")
                                         where c.Element("BType").Value == "Start"
                                         select c;
                // start node
                var startNode = nodeInfos.First();
                // start node id
                string id = startNode.Element("ID").Value;
                // start node next nodes
                var custs = from c in doc.Elements("Connections").First().Elements("Connection")
                            where c.Element("SourceID").Value == id
                            select c.Element("SinkID").Value;

                // get all nodes startnode link
                foreach (var item in custs)
                {
                    // get nodeinfo
                    var nodeInfo = from c in doc.Elements("DesignerItems").Elements("DesignerItem")
                                   where c.Element("ID").Value == item
                                   select c;

                    //  create node info if need
                    if (TransRouting.CreateNodeInfo(nodeInfo.First()))
                    {
                        NSNodeInfo nsNodeInfo = new NSNodeInfo();
                        nsNodeInfo.Id         = Guid.NewGuid();
                        nsNodeInfo.InstanceId = instance.Id;
                        nsNodeInfo.TaskId     = instance.TaskId;
                        nsNodeInfo.NodeId     = Guid.Parse(item.ToString());
                        nsNodeInfo.NodeName   = nodeInfo.First().Element("Name").Value;
                        nsNodeInfo.NodeId     = Guid.Parse(nodeInfo.First().Element("ID").Value);
                        nsNodeInfo.RunState   = RunStateConst.RUNNING;
                        nsNodeInfo.CreateTime = DateTime.Now;
                        context.NSNodeInfos.Add(nsNodeInfo);
                    }
                    else
                    {
                        // only prepare taskid and instanceid
                        NSNodeInfo nsNodeInfo = new NSNodeInfo();
                        nsNodeInfo.Id         = Guid.NewGuid();
                        nsNodeInfo.InstanceId = instance.Id;
                        nsNodeInfo.TaskId     = instance.TaskId;
                        // running routting
                        TransRouting.Routing(doc, nodeInfo.First(), nsNodeInfo, context, newActivities);
                    }
                }

                NSRoutingInfo routingInfo = new NSRoutingInfo();
                routingInfo.InstanceId = instance.Id;
                routingInfo.TaskId     = node.TaskId;
                routingInfo.Id         = Guid.NewGuid();
                routingInfo.ParentId   = parentNodeInfo.Id;

                context.NsRoutingInfos.Add(routingInfo);
            }
            break;
            }
        }