/// <summary> /// Returns the where clause defined by the filter declaration. /// </summary> public ContentFilter GetWhereClause() { ContentFilter whereClause = new ContentFilter(); ContentFilterElement element1 = whereClause.Push(FilterOperator.OfType, EventTypeId); EventFilter filter = new EventFilter(); foreach (FilterDeclarationField field in Fields) { if (field.FilterEnabled) { SimpleAttributeOperand operand1 = new SimpleAttributeOperand(); operand1.TypeDefinitionId = field.InstanceDeclaration.RootTypeId; operand1.AttributeId = (field.InstanceDeclaration.NodeClass == NodeClass.Object) ? Attributes.NodeId : Attributes.Value; operand1.BrowsePath = field.InstanceDeclaration.BrowsePath; LiteralOperand operand2 = new LiteralOperand(); operand2.Value = field.FilterValue; ContentFilterElement element2 = whereClause.Push(field.FilterOperator, operand1, operand2); element1 = whereClause.Push(FilterOperator.And, element1, element2); } } return(whereClause); }
/// <summary> /// Returns the subscription filter to use. /// </summary> public EventFilter GetFilter() { ContentFilter whereClause = new ContentFilter(); ContentFilterElement element1 = whereClause.Push(FilterOperator.OfType, EventTypeId); EventFilter filter = new EventFilter(); for (int ii = 0; ii < Fields.Count; ii++) { filter.SelectClauses.Add(Fields[ii].Operand); if (Fields[ii].FilterValue != Variant.Null) { LiteralOperand operand = new LiteralOperand(); operand.Value = Fields[ii].FilterValue; ContentFilterElement element2 = whereClause.Push(Fields[ii].FilterOperator, Fields[ii].Operand, operand); element1 = whereClause.Push(FilterOperator.And, element1, element2); } } filter.WhereClause = whereClause; return(filter); }
private void CreateElementNotMI_Click(object sender, EventArgs e) { try { if (ItemsLV.SelectedItems.Count != 1) { return; } ContentFilterElement element1 = ItemsLV.SelectedItems[0].Tag as ContentFilterElement; ContentFilter filter = GetFilter(); filter.Push(FilterOperator.Not, element1); Update(filter); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Constructs the event filter for the subscription. /// </summary> /// <returns>The event filter.</returns> public EventFilter ConstructFilter(Session session) { EventFilter filter = new EventFilter(); // the select clauses specify the values returned with each event notification. filter.SelectClauses = SelectClauses; // the where clause restricts the events returned by the server. // it works a lot like the WHERE clause in a SQL statement and supports // arbitrary expession trees where the operands are literals or event fields. ContentFilter whereClause = new ContentFilter(); // the code below constructs a filter that looks like this: // (Severity >= X OR LastSeverity >= X) AND (SuppressedOrShelved == False) AND (OfType(A) OR OfType(B)) // add the severity. ContentFilterElement element1 = null; ContentFilterElement element2 = null; if (Severity > EventSeverity.Min) { // select the Severity property of the event. SimpleAttributeOperand operand1 = new SimpleAttributeOperand(); operand1.TypeDefinitionId = ObjectTypeIds.BaseEventType; operand1.BrowsePath.Add(BrowseNames.Severity); operand1.AttributeId = Attributes.Value; // specify the value to compare the Severity property with. LiteralOperand operand2 = new LiteralOperand(); operand2.Value = new Variant((ushort)Severity); // specify that the Severity property must be GreaterThanOrEqual the value specified. element1 = whereClause.Push(FilterOperator.GreaterThanOrEqual, operand1, operand2); } // add the event types. if (EventTypes != null && EventTypes.Count > 0) { element2 = null; // save the last element. for (int ii = 0; ii < EventTypes.Count; ii++) { // for this example uses the 'OfType' operator to limit events to thoses with specified event type. LiteralOperand operand1 = new LiteralOperand(); operand1.Value = new Variant(EventTypes[ii]); ContentFilterElement element3 = whereClause.Push(FilterOperator.OfType, operand1); // need to chain multiple types together with an OR clause. if (element2 != null) { element2 = whereClause.Push(FilterOperator.Or, element2, element3); } else { element2 = element3; } } // need to link the set of event types with the previous filters. if (element1 != null) { whereClause.Push(FilterOperator.And, element1, element2); } } filter.WhereClause = whereClause; // return filter. return(filter); }
private void SelectNodeMI_Click(object sender, EventArgs e) { try { ReferenceDescription reference = new SelectNodeDlg().ShowDialog(m_browser, ObjectTypes.BaseEventType); if (reference != null) { Node node = m_session.NodeCache.Find(reference.NodeId) as Node; if (node == null) { return; } ContentFilterElement element = null; // build the relative path. QualifiedNameCollection browsePath = new QualifiedNameCollection(); NodeId typeId = m_session.NodeCache.BuildBrowsePath(node, browsePath); switch (node.NodeClass) { case NodeClass.Variable: { IVariable variable = node as IVariable; if (variable == null) { break; } // create attribute operand. SimpleAttributeOperand attribute = new SimpleAttributeOperand( m_session.FilterContext, typeId, browsePath); // create default value. object value = GuiUtils.GetDefaultValue(variable.DataType, variable.ValueRank); // create attribute filter. element = m_filter.Push(FilterOperator.Equals, attribute, value); break; } case NodeClass.Object: { // create attribute operand. SimpleAttributeOperand attribute = new SimpleAttributeOperand( m_session.FilterContext, typeId, browsePath); attribute.AttributeId = Attributes.NodeId; // create attribute filter. element = m_filter.Push(FilterOperator.IsNull, attribute); break; } case NodeClass.ObjectType: { element = m_filter.Push(FilterOperator.OfType, node.NodeId); break; } default: { throw new ArgumentException("Selected an invalid node."); } } // add element. if (element != null) { AddItem(element); AdjustColumns(); } } } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
/// <summary> /// Returns the where clause defined by the filter declaration. /// </summary> private ContentFilter GetWhereClause() { ContentFilter whereClause = new ContentFilter(); ContentFilterElement element1 = null; // filter by source. if (SelectedSources != null && SelectedSources.Count > 0) { SimpleAttributeOperand operand1 = new SimpleAttributeOperand(); operand1.TypeDefinitionId = Opc.Ua.ObjectTypeIds.BaseEventType; operand1.AttributeId = Attributes.Value; operand1.BrowsePath.Add(new QualifiedName(Opc.Ua.BrowseNames.SourceNode)); for (int ii = 0; ii < SelectedSources.Count; ii++) { LiteralOperand operand2 = new LiteralOperand(); operand2.Value = SelectedSources[ii]; ContentFilterElement element2 = whereClause.Push(FilterOperator.Equals, operand1, operand2); element1 = (element1 != null)?whereClause.Push(FilterOperator.Or, element1, element2):element2; } } // add condition/tracking categories if no other categories selected. if (RevisedCategories == null || RevisedCategories.Count == 0) { if (EventTypes == (OpcRcw.Ae.Constants.SIMPLE_EVENT | OpcRcw.Ae.Constants.TRACKING_EVENT)) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.ConditionType); ContentFilterElement element3 = whereClause.Push(FilterOperator.Not, element2); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element3) : element3; } else if (EventTypes == (OpcRcw.Ae.Constants.SIMPLE_EVENT | OpcRcw.Ae.Constants.CONDITION_EVENT)) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.AuditEventType); ContentFilterElement element3 = whereClause.Push(FilterOperator.Not, element2); ContentFilterElement element4 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.TransitionEventType); ContentFilterElement element5 = whereClause.Push(FilterOperator.Not, element4); ContentFilterElement element6 = whereClause.Push(FilterOperator.Or, element3, element5); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element6) : element6; } else if (EventTypes == (OpcRcw.Ae.Constants.TRACKING_EVENT | OpcRcw.Ae.Constants.CONDITION_EVENT)) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.AuditEventType); ContentFilterElement element3 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.TransitionEventType); ContentFilterElement element4 = whereClause.Push(FilterOperator.Or, element2, element3); ContentFilterElement element5 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.ConditionType); ContentFilterElement element6 = whereClause.Push(FilterOperator.Or, element4, element5); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element6) : element6; } else if (EventTypes == OpcRcw.Ae.Constants.TRACKING_EVENT) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.AuditEventType); ContentFilterElement element3 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.TransitionEventType); ContentFilterElement element4 = whereClause.Push(FilterOperator.Or, element2, element3); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element4) : element4; } else if (EventTypes == OpcRcw.Ae.Constants.CONDITION_EVENT) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.ConditionType); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element2) : element2; } else if (EventTypes == OpcRcw.Ae.Constants.SIMPLE_EVENT) { ContentFilterElement element2 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.AuditEventType); ContentFilterElement element3 = whereClause.Push(FilterOperator.Not, element2); ContentFilterElement element4 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.TransitionEventType); ContentFilterElement element5 = whereClause.Push(FilterOperator.Not, element4); ContentFilterElement element6 = whereClause.Push(FilterOperator.Or, element3, element5); ContentFilterElement element7 = whereClause.Push(FilterOperator.OfType, Opc.Ua.ObjectTypeIds.ConditionType); ContentFilterElement element8 = whereClause.Push(FilterOperator.Not, element7); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element8) : element8; } } // filter by event type. if (RevisedCategories.Count > 0) { SimpleAttributeOperand operand1 = new SimpleAttributeOperand(); operand1.TypeDefinitionId = Opc.Ua.ObjectTypeIds.BaseEventType; operand1.AttributeId = Attributes.Value; operand1.BrowsePath.Add(new QualifiedName(Opc.Ua.BrowseNames.EventType)); ContentFilterElement element3 = null; for (int ii = 0; ii < RevisedCategories.Count; ii++) { ContentFilterElement element2 = whereClause.Push(FilterOperator.Equals, operand1, RevisedCategories[ii].TypeId); element3 = (element3 != null) ? whereClause.Push(FilterOperator.Or, element2, element3) : element2; } element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element3) : element3; } // filter by severity. if (LowSeverity > 1 || HighSeverity < 1000) { SimpleAttributeOperand operand1 = new SimpleAttributeOperand(); operand1.TypeDefinitionId = Opc.Ua.ObjectTypeIds.BaseEventType; operand1.AttributeId = Attributes.Value; operand1.BrowsePath.Add(new QualifiedName(Opc.Ua.BrowseNames.Severity)); if (LowSeverity > 1) { LiteralOperand operand2 = new LiteralOperand(); operand2.Value = LowSeverity; ContentFilterElement element2 = whereClause.Push(FilterOperator.GreaterThanOrEqual, operand1, operand2); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element2) : element2; } if (HighSeverity < 1000) { LiteralOperand operand2 = new LiteralOperand(); operand2.Value = HighSeverity; ContentFilterElement element2 = whereClause.Push(FilterOperator.LessThanOrEqual, operand1, operand2); element1 = (element1 != null) ? whereClause.Push(FilterOperator.And, element1, element2) : element2; } } return(whereClause); }