开发学院软件开发C语言 WF4.0 Beta1之旅(5):规则引擎的变化 阅读

WF4.0 Beta1之旅(5):规则引擎的变化

 2010-10-01 08:33:17 来源:WEB开发网   
核心提示: 效果如下图:下面是当点击按钮后,会出现RuleSet的编辑器:usingSystem;usingSystem.Activities;usingSystem.Windows;usingSystem.Windows.Forms;usingSystem.Workflow.Activities.Rule

效果如下图:

WF4.0 Beta1之旅(5):规则引擎的变化

下面是当点击按钮后,会出现RuleSet的编辑器:

using System;
using System.Activities;
using System.Windows;
using System.Windows.Forms;
using System.Workflow.Activities.Rules;
using System.Workflow.Activities.Rules.Design;

namespace Microsoft.Samples.Rules
{
  // Interaction logic for PolicyDesigner.xaml
  public partial class PolicyDesigner
  {
    public PolicyDesigner()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
      // verifiy that TargetObject property has been configured
      object targetObject = ModelItem.Properties["TargetObject"].ComputedValue;
      if (targetObject == null)
      {
        System.Windows.MessageBox.Show("TargetObject needs to be configured before adding the rules");
        return;
      }
      // verify that target object is correctly configured
      InOutArgument arg = targetObject as InOutArgument;
      if (arg == null)
      {
        System.Windows.MessageBox.Show("Invalid target object");
        return;
      }
      // open the ruleset editor
      Type targetObjectType = arg.ArgumentType;
      RuleSet ruleSet = ModelItem.Properties["RuleSet"].ComputedValue as RuleSet;
      if (ruleSet == null)
        ruleSet = new RuleSet();
      RuleSetDialog ruleSetDialog = new RuleSetDialog(targetObjectType, null, ruleSet);
      DialogResult result = ruleSetDialog.ShowDialog();
      // update the model item
      if (result == DialogResult.OK) 
      {
        ModelItem.Properties["RuleSet"].SetValue(ruleSetDialog.RuleSet);
      }
    }
  }
}

这样我们就可以再WF4.0中使用该活动了,如下图:

WF4.0 Beta1之旅(5):规则引擎的变化

系列文章:

WF4.0 Beta1之旅(1):基本介绍

WF4.0 Beta1之旅(2):异常处理

WF4.0 Beta1之旅(3):全新的FlowChart

WF4.0 Beta1之旅(4):Bookmark的使用

上一页  1 2 3 

Tags:WF 之旅

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接