• BizTalk开发小技巧.Net 调用BizTalk Business Rule Engine


    BizTalk开发小技巧-.Net 调用BizTalk Business Rule Engine

    BizTalk Business Rule Engine:BizTalk业务规则引擎,它的主要功能和特点是在不改变流程,不重新部署工程的情况下,动态的配置策略信息,修改策略逻辑.达到动态的业务配置目的。类似WF的工作原理类似。

    这次就是讲在.net windows form的应用程序中调用BizTalk Business Rule Engine配置好业务规则。

    实验的场景:

         模拟报销审批的简单示例,报销金额<多少,审批通过。

    源代码

    private void button1_Click(object sender, RoutedEventArgs e)

    {

    BizTalkRules.Expenses.ExpenseClaim claim = new BizTalkRules.Expenses.ExpenseClaim()

    {

    Amount = Convert.ToInt32( this.textAmount.Text),

    Category = this.cobCategory.Text,

    Department = this.cboDepartment.Text,

    Description = this.textDescription.Text,

    Name = this.textName.Text,

    Project = this.textProject.Text

    };

    if (claim.Category == "Software" && claim.Amount <= 500)

    {

    claim.Status = "Approved";

    }

    else if (claim.Category == "Book" && claim.Amount <= 300)

    {

    claim.Status = "Approved";

    }

    else

    {

    claim.Status = "Require Approval";

    }

    //Microsoft.RuleEngine.Policy policy = new Microsoft.RuleEngine.Policy("ExpensesApproval");

    //policy.Execute(claim);

    this.textStatus.Text = claim.Status;

    }

     

    使用.net无非就是写几行IF Else IF Else 搞定的事情,但如果修改修改审批金额那就必须重新编译发布。

    为了达到这个目的,简化代码,作为一个BizTalk开发人员。就想到了类似的简单判断可以通过BizTalk业务规则引擎来实现。

    如何集成和调用BizTalk业务规则引擎

    1新建一个业务实体对象BizTalkRules.Expenses.ExpenseClaim在BizTalk业务规则引擎中称Facts(事实类型)判断的依据。因为这个Dll需要配置到GAC中才会被BizTalk 业务规则引擎获取因此需要签名

        

    2编译BizTalkRules.Expenses 将Dll部署到GAC中 运行 gacutil –i BizTalkRules.Expenses.dll

    3配置BizTalk Business Rule Engine 打开Business Rule Composer开始配置

    配置(Conditions)条件和(Actions)步骤

    说明一下Priority这个属性如果这值越大就优先执行。

    4.net中调用此规则。引用Microsoft.RuleEngine.dll,这个文件在C:\Program Files (x86)\Common Files\Microsoft BizTalk或C:\Program Files (x86)\Microsoft BizTalk Server 2010

    代码如下

    private void button1_Click(object sender, RoutedEventArgs e)

    {

    BizTalkRules.Expenses.ExpenseClaim claim = new BizTalkRules.Expenses.ExpenseClaim()

    {

    Amount = Convert.ToInt32( this.textAmount.Text),

    Category = this.cobCategory.Text,

    Department = this.cboDepartment.Text,

    Description = this.textDescription.Text,

    Name = this.textName.Text,

    Project = this.textProject.Text

    };

     

    Microsoft.RuleEngine.Policy policy = new Microsoft.RuleEngine.Policy("ExpensesApproval");

    policy.Execute(claim);

    this.textStatus.Text = claim.Status;

    }

     

        

     

    功能就是这样,如果需要修改规则直接发布和部署新的Policies和Rules,而前端应用程序不需要重新便宜

     

    扩展

    可以对Microsoft.RuleEngine进行封装后发布webService或WCF这样就可以给更多的应用使用。

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    JAVA后端开发规范
    IntelliJ IDEA配置
  • 原文地址:https://www.cnblogs.com/neozhu/p/2274466.html
Copyright © 2020-2023  润新知