/// <summary> /// Fetches the operand value. /// </summary> public FilterOperand GetOperand(TypeInfo typeInfo) { if (Element != null) { return(new ElementOperand((uint)Element)); } if (Literal != null) { object targetLiteral = TypeInfo.Cast(Literal, typeInfo.BuiltInType); return(new LiteralOperand(targetLiteral)); } if (Attribute != null) { AttributeOperand attributeOperand = new AttributeOperand(new NodeId(Attribute.NodeId), Attribute.BrowsePath); attributeOperand.Alias = Attribute.Alias; attributeOperand.AttributeId = Attribute.AttributeId.ResolveAttributeId(); attributeOperand.IndexRange = Attribute.IndexRange; return(attributeOperand); } if (SimpleAttribute != null) { List <QualifiedName> browsePaths = new List <QualifiedName>(); if (SimpleAttribute.BrowsePaths != null) { foreach (var browsePath in SimpleAttribute.BrowsePaths) { browsePaths.Add(new QualifiedName(browsePath)); } } SimpleAttributeOperand simpleAttributeOperand = new SimpleAttributeOperand(new NodeId(SimpleAttribute.TypeId), browsePaths.ToArray()); simpleAttributeOperand.AttributeId = SimpleAttribute.AttributeId.ResolveAttributeId(); simpleAttributeOperand.IndexRange = SimpleAttribute.IndexRange; return(simpleAttributeOperand); } return(null); }
/// <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); }