筛选事件类型



我尝试仅接收来自特定事件类型的事件。这个想法是为服务器上的每个可用事件类型创建一个自定义事件过滤器,只允许接收特定于事件类型的属性。但是一旦我实现了内容过滤器(where 子句),就不再收到任何事件。

在此示例中,我想过滤掉除基本事件之外的所有事件。有谁知道如何为此编写正确的内容过滤器?提前谢谢你。

EventFilter eventFilter = new EventFilter(
new SimpleAttributeOperand[]{
new SimpleAttributeOperand(
Identifiers.BaseEventType,
new QualifiedName[]{new QualifiedName(0, "EventId")},
AttributeId.Value.uid(),
null)
},
new ContentFilter(new ContentFilterElement[]{
new ContentFilterElement(
FilterOperator.Equals,
new ExtensionObject[]{
ExtensionObject.encode(client.getSerializationContext(),  
new SimpleAttributeOperand(
Identifiers.BaseEventType,
new QualifiedName[]{new QualifiedName(0, "BaseEventType")},
AttributeId.Value.uid(),
null))
}
)
})
);

我不知道这是否是全部错误,但首先,保存事件类型的变量的 BrowseName 是"事件类型",而不是"BaseEventType",所以你的SimpleAttributeOperand针对的是错误的属性。

其次,等于运算符将期望 2 个操作数(它将"EventType"的值与什么进行比较?所以你需要另一个操作数,它只是 BaseEventType 的 NodeId(所以可能是一个包含包含Identifiers.BaseEventTypeVariantLiteralOperand)。

所以可能是这样的:

ContentFilter contentFilter = new ContentFilter(new ContentFilterElement[]{
new ContentFilterElement(
FilterOperator.Equals,
new ExtensionObject[]{
ExtensionObject.encode(
client.getStaticSerializationContext(),
new SimpleAttributeOperand(
Identifiers.BaseEventType,
new QualifiedName[]{new QualifiedName(0, "EventType")},
AttributeId.Value.uid(),
null
)
),
ExtensionObject.encode(
client.getStaticSerializationContext(),
new LiteralOperand(new Variant(Identifiers.BaseEventType))
)
}
)
});

最新更新