简体   繁体   English

FactRetriever如何执行策略?

[英]How the Policy Execution works using FactRetriever?

I'm checking the document for FactRetriever class using following link: 我正在使用以下链接检查FactRetriever类的文档:

http://msdn.microsoft.com/en-us/library/ee253709%28v=bts.10%29.aspx http://msdn.microsoft.com/en-us/library/ee253709%28v=bts.10%29.aspx

It says: 它说:

A fact retriever is a component that is used to assert instances of long-term facts into a policy during its execution. 事实检索器是一个组件,用于在执行过程中将长期事实的实例声明到策略中。 You can implement the IFactRetriever interface and configure a policy version to use this implementation at run time to bring in the long-term fact instances. 您可以实现IFactRetriever接口,并配置策略版本以在运行时使用此实现来引入长期事实实例。 The policy version invokes the UpdateFacts method of the fact retriever implementation on every execution cycle , if a fact retriever is configured for that particular version. 如果为该特定版本配置了事实检索器,则该策略版本会在每个执行周期中调用事实检索器实现的UpdateFacts方法。

I'm trying to use Business Rule Composer independently (Not using orchestrations). 我试图独立使用Business Rule Composer (不使用业务流程)。

Question 1: When does an execution cycle happen? 问题1: 执行周期何时发生? How does it get triggered? 如何触发?

  • Is it based on an time interval? 是否基于时间间隔? If so, is it configurable? 如果是这样,它是否可配置?
  • Is there some mechanism that a policy executes, if a fact changed? 如果事实发生变化,是否有某种机制可以执行策略? If so then what's the answer for question 2. 如果是这样, 那么问题2的答案是什么?

Question 2: What does an execution cycle do exactly? 问题2: 执行周期到底能做什么? What's the algorithm? 算法是什么?

  • Possible Algorithm 1. First the Policy executes, then during its execution, it will call the UpdateFacts so it brings the fresh objects into memory to apply policy on. 可能的算法1.首先执行Policy ,然后在其执行期间,它将调用UpdateFacts以便将新鲜对象带入内存以对其应用策略。
  • Possible Algorithm 2. First the UpdateFacts executes in some way, then, if some related facts are changed and there are some policies related to those facts, they will trigger to execute on the changed facts. 可能的算法2.首先, UpdateFacts以某种方式执行,然后,如果某些相关事实被更改,并且有与这些事实相关的某些策略,它们将触发对更改后的事实执行。

A1: You can read that literally. A1:您可以按字面意思阅读。 Every time the Policy is executed, the UpdateFacts method of your implementation if IFactRetriever is called prior to any other actual Rule processing. 每次执行Policy时,如果在执行任何其他实际规则之前调用IFactRetriever,则将执行实现的UpdateFacts方法。 There is no timer and there is nothing else really to configure. 没有计时器,也没有其他要配置的东西。 Every time means every time. 每次意味着每次。

There is no way, and no reason either, to update a Long Term Fact outside of a Policy execution. 无法,也没有理由在策略执行之外更新长期事实。 Sure, a Fact may change, but if the Policy is not executed, that update was a waste. 当然,事实可能会发生变化,但是如果不执行该策略,则该更新是浪费的。 It's your job, as implementer of IFactRetriever, to keep track of changes to your Facts and provide the most current Facts via UpdateFacts. 作为IFactRetriever的实现者,您的职责是跟踪事实的变更并通过UpdateFacts提供最新的事实。 There's no way for the engine or Policy to just 'know' when to update a Fact. 引擎或策略无法“知道”何时更新事实。 Technically, the Policy doesn't care that a Fact has changed. 从技术上讲,该政策并不关心事实已经改变。 It will always evaluate the Rules based on the Facts it has. 它将始终根据其事实评估规则。

A2: An execution cycle is just that, a single invocation of a Policy, such as by Policy.Execute(), by any caller. A2:一个执行周期就是,任何调用者对Policy的单次调用,例如Policy.Execute()的调用。 You can see an example here: http://msdn.microsoft.com/en-us/library/aa995566.aspx 您可以在此处看到一个示例: http : //msdn.microsoft.com/en-us/library/aa995566.aspx

The algorithm is as simple as possible. 该算法尽可能简单。 For our purposes, assume that UpdateFacts is the first thing the Rules Engine does after you call Execute, if a Fact Retriever is configured of course. 就我们的目的而言,假设已配置了事实检索器,则假定UpdateFacts是规则引擎在调用Execute之后执行的第一件事。 That happens every time. 每次都会发生这种情况。 Update Facts is never called at any other point other than immediately after Execute. 除了在执行后立即执行更新事实,决不会在其他任何时间调用更新事实。 This is per Execute. 这是按执行。

However, it's also worth pointing out that the engine can create multiple instances of the Policy in memory so that it can service multiple callers in the same Process (technically, it might be the AppDomain, never bothered to check). 但是,还值得指出的是,引擎可以在内存中创建Policy的多个实例,以便可以在同一Process中为多个调用者提供服务(从技术上讲,它可能是AppDomain,从不费力检查)。 So, UpdateFacts is called for every Execute on any given Instance of the Policy. 因此,对策略的任何给定实例上的每个执行都调用UpdateFacts。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM