钝化程序模式SOA架构BPM

来源:互联网 发布:淘宝店铺申请企业店铺 编辑:程序博客网 时间:2024/04/29 14:00

钝化程序模式SOA架构BPM

    在SOA架构中,通常都会存在着N多个服务接口,每个服务接口的消费者有着明确的角色定义,通过将一系列的服务接口串联起来就可以组成一个完整的业务流程,这也被称为业务流程管理(Business Process Manager)。那么扮演关业务流程管理的这段逻辑角色要能够支持多地区调用,某个业务内的流程管理器所要面对的是这个业务内的所有要参与其中的角色,每个角色调用不同的服务方法,但彼此又是相互影响的。
 
BPM每个阶段产生的数据都将作为下一个阶段需要输入的数据,将多个完本独立的SOA接口组成一个可以用来产生实际业务价值的业务功能块,这也是实施SOA(面向服务的体系结构-Service-Oriented Architecture)架构的价值之一。
钝化模式绝对是BPM框架的核心模式之一,下面我们就提供一个订单审批流程管理器

订单审批流程共需3个角色参与:
1.信息员检查订单
2.业务经理确认
3.总经理最终确认签字
 
第一次启动输出:
 
第二次启动输出:
第三次启动输出:
第四次启动输出:
 
附上代码:

类:Program

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.IO;  
  7. using System.Runtime.Serialization.Formatters.Binary;  
  8.   
  9. namespace ConsoleApplication52  
  10. {  
  11.     public class Program  
  12.     {  
  13.         static void Main(string[] args)  
  14.         {  
  15.   
  16.   
  17.             string path = AppDomain.CurrentDomain.BaseDirectory + "approve001.xml";  
  18.   
  19.             ApproveManager approveManager = null;  
  20.             if (File.Exists(path))  
  21.             {  
  22.                 using (Stream stream = File.Open(path, FileMode.Open))  
  23.                 {  
  24.                     BinaryFormatter binaryFormatter = new BinaryFormatter();  
  25.   
  26.                     approveManager = (ApproveManager)binaryFormatter.Deserialize(stream);  
  27.                 }  
  28.             }  
  29.             else  
  30.             {  
  31.                 approveManager = new ApproveManager(new OrderInfo { });  
  32.   
  33.             }  
  34.   
  35.             approveManager.RunFlow();  
  36.   
  37.             using (Stream stream = File.Open(path, FileMode.OpenOrCreate))  
  38.             {  
  39.                 BinaryFormatter binaryFormatter = new BinaryFormatter();  
  40.   
  41.                 binaryFormatter.Serialize(stream, approveManager);  
  42.             }  
  43.   
  44.             Console.ReadKey();  
  45.         }  
  46.     }  
  47. }  

类:Informationer

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication52  
  8. {  
  9.     [Serializable]  
  10.     public class Informationer  
  11.     {  
  12.   
  13.         public void CheckPrice(OrderInfo orderInfo, ref ApproveHander approveHander)  
  14.         {  
  15.             if (orderInfo.approveStatus == ApproveStatus.客服检查)  
  16.             {  
  17.                 Console.WriteLine("CheckPrice");  
  18.                 approveHander -= this.CheckPrice;  
  19.             }  
  20.   
  21.         }  
  22.   
  23.         public void CheckNum(OrderInfo orderInfo, ref ApproveHander approveHander)  
  24.         {  
  25.             if (orderInfo.approveStatus == ApproveStatus.客服检查)  
  26.             {  
  27.                 Console.WriteLine("CheckNum");  
  28.                 approveHander -= this.CheckNum;  
  29.             }  
  30.         }  
  31.     }  
  32. }  

类:BusinessManager

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication52  
  8. {  
  9.     [Serializable]  
  10.     public class BusinessManager  
  11.     {  
  12.         public void CallPhone(OrderInfo order, ref ApproveHander approveManager)  
  13.         {  
  14.             if (order.approveStatus == ApproveStatus.业务员确认)  
  15.             {  
  16.                 Console.WriteLine("CallPhone");  
  17.                 approveManager -= this.CallPhone;  
  18.             }  
  19.         }  
  20.   
  21.         public void SendMail(OrderInfo order, ref ApproveHander approveManager)  
  22.         {  
  23.             if (order.approveStatus == ApproveStatus.业务员确认)  
  24.             {  
  25.                 Console.WriteLine("SendMail");  
  26.                 approveManager -= this.SendMail;  
  27.             }  
  28.         }  
  29.   
  30.     }  
  31. }  

类:GeneralManager

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication52  
  8. {  
  9.     [Serializable]  
  10.    public  class GeneralManager  
  11.     {  
  12.   
  13.        public void FinalConfirm(OrderInfo order, ref ApproveHander approveHander)  
  14.        {  
  15.   
  16.            if (order.approveStatus == ApproveStatus.主管签字)  
  17.            {  
  18.                approveHander -= this.FinalConfirm;  
  19.                Console.WriteLine("FinalConfirm");  
  20.            }  
  21.   
  22.        }  
  23.   
  24.        public void SignRecord(OrderInfo order, ref ApproveHander approveHander)  
  25.        {  
  26.   
  27.            if (order.approveStatus == ApproveStatus.主管签字)  
  28.            {  
  29.                approveHander -= this.SignRecord;  
  30.                Console.WriteLine("SignRecord");  
  31.            }  
  32.   
  33.        }  
  34.   
  35.     }  
  36. }  

类:ApproveManager

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication52  
  8. {  
  9.   
  10.     public delegate void ApproveHander(OrderInfo orderInfo, ref ApproveHander approveHander);  
  11.   
  12.     [Serializable]  
  13.     public class ApproveManager  
  14.     {  
  15.         public ApproveHander approveHander;  
  16.   
  17.         private OrderInfo order;  
  18.   
  19.         public ApproveManager(OrderInfo order)  
  20.         {  
  21.             Informationer informationer = new Informationer();  
  22.             approveHander += informationer.CheckNum;  
  23.             approveHander += informationer.CheckPrice;  
  24.   
  25.   
  26.             BusinessManager businessManager = new BusinessManager();  
  27.             approveHander += businessManager.CallPhone;  
  28.             approveHander += businessManager.SendMail;  
  29.   
  30.             GeneralManager generalManager = new GeneralManager();  
  31.             approveHander += generalManager.FinalConfirm;  
  32.             approveHander += generalManager.SignRecord;  
  33.   
  34.   
  35.             this.order = order;  
  36.   
  37.         }  
  38.   
  39.         public void RunFlow()  
  40.         {  
  41.             if (order.approveStatus == ApproveStatus.提交 )  
  42.             {  
  43.                 order.approveStatus = ApproveStatus.客服检查;  
  44.             }  
  45.             else if (order.approveStatus == ApproveStatus.客服检查)  
  46.             {  
  47.                 order.approveStatus = ApproveStatus.业务员确认;  
  48.             }  
  49.             else  
  50.             {  
  51.                 order.approveStatus = ApproveStatus.主管签字;  
  52.             }  
  53.             if (approveHander != null)  
  54.             {  
  55.                 this.approveHander(this.order, ref approveHander);  
  56.             }  
  57.             else  
  58.             {  
  59.                 Console.WriteLine("流程已处理完成");  
  60.             }  
  61.         }  
  62.   
  63.     }  
  64.   
  65.      
  66. }  

类:OrderInfo

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication52  
  8. {  
  9.     [Serializable]  
  10.     public class OrderInfo  
  11.     {  
  12.         public ApproveStatus approveStatus { getset; }  
  13.     }  
  14.   
  15.     public enum ApproveStatus  
  16.     {  
  17.         提交,  
  18.         客服检查,  
  19.         业务员确认,  
  20.         主管签字  
  21.     }  
  22. }  
 
0 0