.net工作流引擎ccflow集成並增加自定義功能


一、為什么需要自定義擴展

1、第三方類庫已滿足大部分需求,剩下的根據具體業務需求抽象成公共功能進行擴展

2、第三方呈現的web頁面與原類庫耦合度較高,希望在原頁面上擴展而不影響原來的功能

3、在完全不修改第三方類庫及web頁面的情況下,加入自己的代碼

4、未來可以同步更新第三方類庫

二、主要實現思路

1、類庫通過繼承的方式擴展

2、asp.net頁面通過增加一個分部類來調用擴展后的類庫

三、具體集成ccflow操作步驟

1、解決方案引入ccflow核心三大類庫,確保三大類庫的與解決方案不在同一個目錄,由ccflow維護更新

2、新建自己業務的擴展類庫,擴展類庫命名空間必須以BP開頭,與ccflow類庫命名規則保持一致,否則無法反射完成初始化

 

3、在擴展類庫中新建一個BP.Def.FlowExt類,以繼承BP.WF.Template.FlowExt類為例,關鍵是重寫子類的EnMap屬性

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using BP.En;
  6 using BP.Web;
  7 using BP.Sys;
  8 
  9 namespace BP.Def
 10 {
 11 
 12     public class FlowExtAttr : BP.WF.Template.FlowAttr
 13     {
 14         /// <summary>
 15         /// 自定義業務編號
 16         /// </summary>
 17         public const string DefNoFormat = "DefNoFormat";
 18         /// <summary>
 19         /// 自定義業務名稱
 20         /// </summary>
 21         public const string DefNameFormat = "DefNameFormat";
 22         /// <summary>
 23         /// 刪除流程時是否同時刪除自定義
 24         /// </summary>
 25         public static string IsDeleteDef = "IsDeleteDef";
 26     }
 27 
 28     public class FlowExt : BP.WF.Template.FlowExt
 29     {
 30         public FlowExt()
 31         {
 32            
 33         }
 34 
 35         public FlowExt(string _No)
 36         {
 37             this.No = _No;
 38             this.Retrieve();
 39         }
 40 
 41         /// <summary>
 42         /// 重寫基類方法
 43         /// </summary>
 44         public override Map EnMap
 45         {
 46             get
 47             {
 48                 //web界面中的Tab展示控制
 49                 EnCfg en = new EnCfg(this.ToString());
 50                 if (en.GroupTitle.Contains(FlowExtAttr.DefNoFormat) == false)
 51                 {
 52                     en.SetValByKey(EnCfgAttr.GroupTitle, en.GroupTitle + "@" + FlowExtAttr.DefNoFormat + "=自定義擴展");
 53                     en.Save();
 54                 }
 55 
 56                 //首次構造返回基類
 57                 if (this._enMap == null)
 58                 {
 59                     this._enMap = base.EnMap;
 60                     return this._enMap;
 61                 }
 62 
 63                 //基類構造完成后,后續使用子類
 64                 int index = this._enMap.Attrs.GetIndexByKey(FlowExtAttr.DefNoFormat);
 65 
 66                 //新增加的配置
 67                 if (this._enMap != null && this.Row.Count > 0 && string.IsNullOrEmpty(this.No) == false && index < 0)
 68                 {
 69                     this._enMap.AddTBString(FlowExtAttr.DefNoFormat, "", "自定義業務編號", true, false, 0, 50, 10, true);
 70                     this._enMap.AddTBString(FlowExtAttr.DefNameFormat, "", "自定義業務名稱", true, false, 0, 50, 10, true);
 71                     this._enMap.AddBoolean(FlowExtAttr.IsDeleteDef, false, "刪除流程時是否同時刪除自定義", true, true, true);
 72                 }
 73 
 74                 return this._enMap;
 75             }
 76         }
 77 
 78         /// <summary>
 79         /// 自定義業務編號
 80         /// </summary>
 81         public string DefNoFormat
 82         {
 83             get
 84             {
 85                 return this.GetValStrByKey(FlowExtAttr.DefNoFormat);
 86             }
 87             set
 88             {
 89                 this.SetValByKey(FlowExtAttr.DefNoFormat, value);
 90             }
 91         }
 92 
 93         /// <summary>
 94         ///自定義業務名稱
 95         /// </summary>
 96         public string DefNameFormat
 97         {
 98             get
 99             {
100                 return this.GetValStrByKey(FlowExtAttr.DefNameFormat);
101             }
102             set
103             {
104                 this.SetValByKey(FlowExtAttr.DefNameFormat, value);
105             }
106         }
107 
108         /// <summary>
109         /// 刪除流程時是否同時刪除自定義
110         /// </summary>
111         public bool IsDeleteDef
112         {
113             get
114             {
115                 return this.GetValBooleanByKey(FlowExtAttr.IsDeleteDef);
116             }
117         }
118     }
119 
120     public class FlowExts : BP.WF.Template.FlowExts
121     {
122         public FlowExts()
123         {
124         }
125 
126         public override Entity GetNewEntity
127         {
128             get { return new FlowExt(); }
129         }
130     }
131 }
View Code

 

 4、在解決方案新建一個web項目,完全拷貝ccflow下的WF、DataUser目錄到web項目里,最終整個結構如下

5、為后台頁面增加一個分部類,在分部類里修改asp.net頁面入口,轉向訪問自定義的BP.Def類庫

6、最終效果達到在完全不修改ccflow的前后台源碼下實現自定義功能的擴展

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM