9.5.3 属性示例、持续(Property example, continued)

9.4.1节中的例子需要一个可选的Key项。本节中的例子示范Key项的应用。规则引擎可以包含检测域(FieldDetector)规则。这些规则定义场景中每个对象的ObjectsInside属性。当一个新的对象出现在这样一个域之外时,将产生以下通知:

  1. <wsnt:NotificationMessage>
  2. ...
  3. <wsnt:Topic Dialect="...Concrete">
  4. tns1:RuleEngine/FieldDetector/ObjectsInside
  5. </wsnt:Topic>
  6. <wsnt:Message>
  7. <tt:Message UtcTime="..." PropertyOperation="Initialized">
  8. <tt:Source>
  9. <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
  10. <tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
  11. <tt:SimpleItem Name="Rule" Value="myImportantField"/>
  12. </tt:Source>
  13. <tt:Key>
  14. <tt:SimpleItem Name="ObjectId" Value="5"/>
  15. </tt:Key>
  16. <tt:Data>
  17. <tt:SimpleItem Name="IsInside" Value="false"/>
  18. </tt:Data>
  19. </tt:Message>
  20. </wsnt:Message>
  21. </wsnt:NotificationMessage>

Source项描述产生通知的规则。当多个对象在场景中时,每个对象都有其自己的ObjectsInside属性。因此,为了使属性唯一,对象ID用来作为一个额外的Key项。IsInside项是一个布尔值,指示该对象是在域内或者域外。当对象进入域时,该规则产生一个“属性更改”的消息和类似于以下的内容:

  1. <wsnt:NotificationMessage>
  2. ...
  3. <wsnt:Topic Dialect="...Concrete">
  4. tns1:RuleEngine/FieldDetector/ObjectsInside
  5. </wsnt:Topic>
  6. <wsnt:Message>
  7. <tt:Message UtcTime="..." PropertyOperation="Changed">
  8. <tt:Source>
  9. <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
  10. <tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
  11. <tt:SimpleItem Name="Rule" Value="myImportantField"/>
  12. </tt:Source>
  13. <tt:Key>
  14. <tt:SimpleItem Name="ObjectId" Value="5"/>
  15. </tt:Key>
  16. <tt:Data>
  17. <tt:SimpleItem Name="IsInside" Value="true"/>
  18. </tt:Data>
  19. </tt:Message>
  20. </wsnt:Message>
  21. </wsnt:NotificationMessage>

最后,当对象离开场景时,产生“属性删除”消息:

  1. <wsnt:NotificationMessage>
  2. ...
  3. <wsnt:Topic Dialect="...Concrete">
  4. tns1:RuleEngine/FieldDetector/ObjectsInside
  5. </wsnt:Topic>
  6. <wsnt:Message>
  7. <tt:Message UtcTime="..." PropertyOperation="Deleted">
  8. <tt:Source>
  9. <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
  10. <tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
  11. <tt:SimpleItem Name="Rule" Value="myImportantField"/>
  12. </tt:Source>
  13. <tt:Key>
  14. <tt:SimpleItem Name="ObjectId" Value="5"/>
  15. </tt:Key>
  16. </tt:Message>
  17. </wsnt:Message>
  18. </wsnt:NotificationMessage>

在这种情况下,Data项可以省略,因为对象和它相应的属性已不存在。

上一章|继续阅读