Im trying to receive events from specific event types only. The idea is to then create a custom Eventfilter for each available EventType on the server, allowing to receive EventType specific properties only. But once I implement a Contentfilter (where clause), no events are received anymore.
In this example I would like filter out all events except BaseEvents. Does anybody know how to write a correct Contentfilter for that? Thank you in advance.
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))
}
)
})
);
I don't know if this is all that is wrong, but for one thing the BrowseName of the variable holding the event type is "EventType", not "BaseEventType", so your SimpleAttributeOperand
is targeting the wrong property.
Second, The Equals operator is going to expect 2 operands (what is it comparing the value of "EventType" to?). So you need another operand that is just the NodeId of BaseEventType (so probably a LiteralOperand
containing a Variant
that contains Identifiers.BaseEventType
).
So possibly something like this:
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))
)
}
)
});