Click here to Skip to main content
15,885,546 members
Articles / Hosted Services / Serverless

Peer Graph - Search Criteria Helper

Rate me:
Please Sign up or sign in to vote.
4.17/5 (2 votes)
16 Jan 20067 min read 35.9K   510   14  
Expression conversion to XML search criteria for a Peer Graph, using Microsoft's Peer-to-Peer technology.
Imports System.Text

Interface IASTNode
    Sub WriteToXML(ByVal xw As System.Xml.XmlTextWriter)
End Interface

Class SearchItem
    Implements IASTNode

    Friend Operation As String 'and/or/blank
    Friend Compare As Comparison

    Public Sub New(ByVal Comparison As Comparison, Optional ByVal Op As String = "")
        Compare = Comparison
        Operation = Op.ToLower
    End Sub

    Public Sub WriteToXML(ByVal xw As System.Xml.XmlTextWriter) Implements IASTNode.WriteToXML
        Compare.WriteToXML(xw)
    End Sub
End Class

Class SearchList
    Implements IASTNode

    Friend List As New ArrayList '(Of SearchItem)
    Public Sub New(ByVal item As SearchItem)
        List.Add(item)
    End Sub
    Public Sub Add(ByVal item As SearchItem)
        List.Add(item)
    End Sub

    Public Sub WriteToXML(ByVal xw As System.Xml.XmlTextWriter) Implements IASTNode.WriteToXML
        Dim item As SearchItem = CType(List(0), SearchItem)
        If List.Count = 1 Then
            item.WriteToXML(xw)
        Else
            ' operation is always the second item in the list
            Dim Operation As String = CType(List(1), SearchItem).Operation
            xw.WriteStartElement(Operation)

            Dim i As Integer = 0
            Do
                item.WriteToXML(xw)
                i += 1
                item = CType(List(i), SearchItem)
            Loop While i < List.Count - 1

            ' don't forget the last item
            item.WriteToXML(xw)
            xw.WriteEndElement()
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
Adrian Moore is the Development Manager for the SCADA Vision system developed by ABB Inc in Calgary, Alberta.

He has been interested in compilers, parsers, real-time database systems and peer-to-peer solutions since the early 90's. In his spare time, he is currently working on a SQL parser for querying .NET DataSets (http://www.queryadataset.com).

Adrian is a Microsoft MVP for Windows Networking.

Comments and Discussions