第9.4.1节中的例子需要一个可选的Key项。本节中的例子示范Key项的应用。规则引擎可以包含检测域(FieldDetector)规则。这些规则定义场景中每个对象的ObjectsInside属性。当一个新的对象出现在这样一个域之外时,将产生以下通知:
<wsnt:NotificationMessage>
...
<wsnt:Topic Dialect="...Concrete">
tns1:RuleEngine/FieldDetector/ObjectsInside
</wsnt:Topic>
<wsnt:Message>
<tt:Message UtcTime="..." PropertyOperation="Initialized">
<tt:Source>
<tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
<tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
<tt:SimpleItem Name="Rule" Value="myImportantField"/>
</tt:Source>
<tt:Key>
<tt:SimpleItem Name="ObjectId" Value="5"/>
</tt:Key>
<tt:Data>
<tt:SimpleItem Name="IsInside" Value="false"/>
</tt:Data>
</tt:Message>
</wsnt:Message>
</wsnt:NotificationMessage>
Source项描述产生通知的规则。当多个对象在场景中时,每个对象都有其自己的ObjectsInside属性。因此,为了使属性唯一,对象ID用来作为一个额外的Key项。IsInside项是一个布尔值,指示该对象是在域内或者域外。当对象进入域时,该规则产生一个“属性更改”的消息和类似于以下的内容:
<wsnt:NotificationMessage>
...
<wsnt:Topic Dialect="...Concrete">
tns1:RuleEngine/FieldDetector/ObjectsInside
</wsnt:Topic>
<wsnt:Message>
<tt:Message UtcTime="..." PropertyOperation="Changed">
<tt:Source>
<tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
<tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
<tt:SimpleItem Name="Rule" Value="myImportantField"/>
</tt:Source>
<tt:Key>
<tt:SimpleItem Name="ObjectId" Value="5"/>
</tt:Key>
<tt:Data>
<tt:SimpleItem Name="IsInside" Value="true"/>
</tt:Data>
</tt:Message>
</wsnt:Message>
</wsnt:NotificationMessage>
最后,当对象离开场景时,产生“属性删除”消息:
<wsnt:NotificationMessage>
...
<wsnt:Topic Dialect="...Concrete">
tns1:RuleEngine/FieldDetector/ObjectsInside
</wsnt:Topic>
<wsnt:Message>
<tt:Message UtcTime="..." PropertyOperation="Deleted">
<tt:Source>
<tt:SimpleItem Name="VideoSourceConfigurationToken" Value="1"/>
<tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="1"/>
<tt:SimpleItem Name="Rule" Value="myImportantField"/>
</tt:Source>
<tt:Key>
<tt:SimpleItem Name="ObjectId" Value="5"/>
</tt:Key>
</tt:Message>
</wsnt:Message>
</wsnt:NotificationMessage>
在这种情况下,Data项可以省略,因为对象和它相应的属性已不存在。