public void NonBoolWithUnary(object operandFirst1, object operandFirst2, FilterOperator filterOp1, FilterOperator filterOp2, object expectedResult) { // Setup the First ContentfilterElement (the BitwiseOr or BitwiseAnd filter operation) LiteralOperand loperand1 = new LiteralOperand(); LiteralOperand loperand2 = new LiteralOperand(); loperand1.Value = new Variant(operandFirst1); if (filterOp1 == FilterOperator.Cast) { NodeId uintNoid = new NodeId(operandFirst2, 0); loperand2.Value = new Variant(uintNoid); } else { loperand2.Value = new Variant(operandFirst2); } ContentFilterElement filterElement1 = new ContentFilterElement(); filterElement1.FilterOperator = filterOp1; filterElement1.SetOperands(new List<FilterOperand>() { loperand1, loperand2 }); // Setup the Second ContentfilterElement ElementOperand elementOperand = new ElementOperand(); elementOperand.Index = 1; // link to filterElement1 ContentFilterElement filterElement2 = new ContentFilterElement(); filterElement2.FilterOperator = filterOp2; filterElement2.SetOperands(new List<FilterOperand>() { elementOperand }); Filter.WhereClause.Elements = new[] { filterElement2, filterElement1 }; // apply filter. object result = Filter.WhereClause.Evaluate(FilterContext, TestFilterTarget); Assert.AreEqual(expectedResult, result); }
/// <summary> /// Displays the dialog. /// </summary> public FilterOperand ShowDialog( Session session, IList <ContentFilterElement> elements, int index, FilterOperand operand) { if (session == null) { throw new ArgumentNullException("session"); } if (elements == null) { throw new ArgumentNullException("elements"); } m_session = session; TypeDefinitionIdCTRL.Browser = new Browser(session); TypeDefinitionIdCTRL.RootId = ObjectTypes.BaseEventType; OperandTypeCB.SelectedItem = typeof(LiteralOperand).Name; if (operand != null) { OperandTypeCB.SelectedItem = operand.GetType().Name; } ElementsCB.Items.Clear(); for (int ii = index + 1; ii < elements.Count; ii++) { ElementsCB.Items.Add(elements[ii].ToString(m_session.NodeCache)); } ElementOperand elementOperand = operand as ElementOperand; if (elementOperand != null) { ElementsCB.SelectedIndex = (int)elementOperand.Index - index - 1; } AttributeOperand attributeOperand = operand as AttributeOperand; if (attributeOperand != null) { TypeDefinitionIdCTRL.Identifier = attributeOperand.NodeId; BrowsePathTB.Text = attributeOperand.BrowsePath.Format(session.NodeCache.TypeTree); AttributeIdCB.SelectedItem = Attributes.GetBrowseName(attributeOperand.AttributeId); IndexRangeTB.Text = attributeOperand.IndexRange; AliasTB.Text = attributeOperand.Alias; } LiteralOperand literalOperand = operand as LiteralOperand; if (literalOperand != null) { NodeId datatypeId = TypeInfo.GetDataTypeId(literalOperand.Value.Value); DataTypeCB.SelectedItem = TypeInfo.GetBuiltInType(datatypeId); StringBuilder buffer = new StringBuilder(); Array array = literalOperand.Value.Value as Array; if (array != null) { for (int ii = 0; ii < array.Length; ii++) { if (ii > 0) { buffer.Append("\r\n"); } buffer.AppendFormat("{0}", new Variant(array.GetValue(ii))); } } else { buffer.AppendFormat("{0}", literalOperand.Value); } ValueTB.Text = buffer.ToString(); } if (ShowDialog() != DialogResult.OK) { return(null); } return(operand); }