Tips:Rule Engine 设置Priority属性决定rule执行顺序

做一个Rule Engine 应用的时候,我先检查是否存在某个xml element,如果不存在,则用XmlHelper来添加一个节点,使用Microsoft.RuleEnginee.dll

rule_policy  
一开始没有注意,在添加多个节点的时候没有设置他们的优先级,以为是按照rule的排列顺序执行,结果生成出来的xml用xsd校验不通过,xsd设置了sequence,查看test policy的日志,发现执行顺序是有问题

后来发现每个rule都有一个属性 Priority,默认是0,越大表示执行优先级越高,设置大于0就好了.

PS:Rule Version问题

只有version最新的那个才有效,v1.1 > v1.0 ,没运行完的,还执行v1.0.,新的,都执行v1.1的。

 

附:

rule_sequence

 

RULE ENGINE TRACE for RULESET: InsertXmlNodes 2007-6-25 16:30:38

FACT ACTIVITY 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Assert
Object Type: TypedXmlDocument:InsertXmlNode.Employee
Object Instance Identifier: 27997594

CONDITION EVALUATION TEST (MATCH) 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Test Expression: NOT(True == Exists(TypedXmlDocument:InsertXmlNode.Employee, /*[local-name()='Employee' and namespace-uri()='http://InsertXmlNode.Employee']/*[local-name()='FirstName' and namespace-uri()='']))
Left Operand Value: True
Right Operand Value: False
Test Result: True

CONDITION EVALUATION TEST (MATCH) 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Test Expression: NOT(True == Exists(TypedXmlDocument:InsertXmlNode.Employee, /*[local-name()='Employee' and namespace-uri()='http://InsertXmlNode.Employee']/*[local-name()='LastName' and namespace-uri()='']))
Left Operand Value: True
Right Operand Value: False
Test Result: True

FACT ACTIVITY 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Assert
Object Type: TypedXmlDocument:InsertXmlNode.Employee:/Employee
Object Instance Identifier: 50651754

CONDITION EVALUATION TEST (MATCH) 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Test Expression: TypedXmlDocument:InsertXmlNode.Employee:/Employee.ID == 1
Left Operand Value: 1
Right Operand Value: 1
Test Result: True

AGENDA UPDATE 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Add
Rule Name: InsertLocationAttribute
Conflict Resolution Criteria: 0

AGENDA UPDATE 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Add
Rule Name: SetLastNameValue
Conflict Resolution Criteria: 0

AGENDA UPDATE 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Add
Rule Name: InsertAndSetFirstName
Conflict Resolution Criteria: 0

AGENDA UPDATE 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Add
Rule Name: InsertLastName
Conflict Resolution Criteria: 5

RULE FIRED 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Rule Name: InsertLastName
Conflict Resolution Criteria: 5

RULE FIRED 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Rule Name: SetLastNameValue
Conflict Resolution Criteria: 0

RULE FIRED 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Rule Name: InsertAndSetFirstName
Conflict Resolution Criteria: 0

RULE FIRED 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Rule Name: InsertLocationAttribute
Conflict Resolution Criteria: 0

FACT ACTIVITY 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Retract
Object Type: TypedXmlDocument:InsertXmlNode.Employee
Object Instance Identifier: 27997594

FACT ACTIVITY 2007-6-25 16:30:38
Rule Engine Instance Identifier: 6f72b8d0-423b-4ac9-98ab-cea47b0d61d8
Ruleset Name: InsertXmlNodes
Operation: Retract
Object Type: TypedXmlDocument:InsertXmlNode.Employee:/Employee
Object Instance Identifier: 50651754

--------------------------------------------------------------------------------

你可能感兴趣的:(Engine)