递归在算法在工作流程引擎中的应用
递归在算法在工作流程引擎中的应用
递归做为一种算法在程序设计语言中广泛应用.是指函数/过程/子程序在运行过程中直接或间接调用自身而产生的重入现象.递归是计算机科学的一个重要概念,递归的方法是程序设计中有效的方法,采用递归编写程序能使程序变得简洁和清晰.。
递归在工作流程引擎中有广泛的应用,以以下事例来说明:
应用一:退回到指定的节点,要把当前节电与退回节点之间的节点数据清空。
/// <summary> /// 递ÌY归¨¦删¦?除y两¢?个?节¨²点Ì?之?间?的Ì?数ºy据Y /// </summary> /// <param name="nds">到Ì?达ä?的Ì?节¨²点Ì?集¡¥合?</param> publicvoid DeleteToNodesData(Nodes nds) { /*开a始º?遍À¨¦历¤¨²到Ì?达ä?的Ì?节¨²点Ì?集¡¥合?*/ foreach (Node nd in nds) { Work wk = nd.HisWork; wk.OID = this.WorkID; if (wk.Delete() == 0) { wk.FID = this.WorkID; if (wk.Delete(WorkAttr.FID, this.WorkID) == 0) continue; }
/*说¦Ì明¡Â:已°?经-删¦?除y该?节¨²点Ì?数ºy据Y。¡ê*/ DBAccess.RunSQL("DELETE WF_GenerWorkerList WHERE (WorkID=" + this.WorkID + " OR FID=" + this.WorkID + ") AND FK_Node=" + nd.NodeID);
//删¦?除y正y常¡ê的Ì?垃¤?圾?数ºy据Y。¡ê DBAccess.RunSQL("DELETE WF_GenerWorkFlow WHERE WorkID NOT IN (SELECT WorkID FROM WF_GenerWorkerList )"); DBAccess.RunSQL("DELETE WF_GenerFH WHERE FID NOT IN (SELECT FID FROM WF_GenerWorkerList)");
DeleteToNodesData(nd.HisToNodes); } }
|
应用二:在分合流程过程中,流程结束时,要根据用户的需要判断并杀掉没有完成的进程。
/// <summary> /// 结¨¢束º?流¢¡Â程¨¬ /// </summary> /// <returns></returns> publicstring DoFlowOver() { // 建¡§立¢¡é流¢¡Â程¨¬事º?例¤y。¡ê GenerWorkFlow gwf = newGenerWorkFlow(this.WorkID); Node nd = newNode(gwf.FK_Node); string msg = this.BeforeFlowOver();
//先¨¨让¨?它¨¹的Ì?子Á¨®流¢¡Â程¨¬结¨¢束º?。¡ê WorkerLists wls = newWorkerLists(); wls.Retrieve(WorkerListAttr.FID, this.WorkID); foreach (WorkerList wl in wls) { WorkFlow wf = newWorkFlow(wl.FK_Flow, wl.WorkID); wf.DoFlowOver(); } 。。。。。。。。。。。。。。 } |
应用三:根据当前节点的ID,向上追溯一个分流节点。
/// <summary> /// 获?取¨?它¨¹的Ì?上¦?一°?步?的Ì?分¤?流¢¡Â点Ì? /// </summary> privateNode _GetHisPriFLNode(Nodes nds) { foreach (Node mynd in nds) { if (mynd.IsHL) return mynd; else return _GetHisPriFLNode(mynd.HisFromNodes); } returnnull; } /// <summary> /// 它¨¹的Ì?上¦?一°?步?分¤?流¢¡Â节¨²点Ì? /// </summary> publicNode HisPriFLNode { get { return _GetHisPriFLNode(this.HisFromNodes); } }
|
类别:工作流开发 查看评论