Imports DpmaXmlParser.DPMA.Patent
Imports System.Xml

Public Class DPMAConnectPatents
    Private _service As DPMAregisterClient

    Private _user As String
    Private _pass As String
    Private _type As String

    Public Sub New(username As String, password As String, type As String)
        _user = username
        _pass = password
        _type = type

        _service = New DPMA.Patent.DPMAregisterClient()
        _service.Open()
    End Sub

    Public Function SearchPatents(query As String) As XmlDocument
        Dim doc As New XmlDocument()
        Dim xmlstring As String

        Try
            xmlstring = _service.search(_user, _pass, query)
            doc.LoadXml(xmlstring)

            Dim ErrorMessage = doc.SelectSingleNode("Hitlist/ErrorMessage")
            If Not IsNothing(ErrorMessage) Then
                Throw New Exception(ErrorMessage.InnerText)
            End If
        Catch ex As Exception
            Throw ex
        End Try

        Return doc
    End Function

    Public Function Search(query As String) As XmlDocument
        Dim doc As New XmlDocument()
        Dim xmlstring As String

        Try
            xmlstring = _service.search(_user, _pass, query)
            doc.LoadXml(xmlstring)

            Dim ErrorMessage = doc.SelectSingleNode("Hitlist/ErrorMessage")
            If Not IsNothing(ErrorMessage) Then
                Throw New Exception(ErrorMessage.InnerText)
            End If

        Catch ex As Exception
            Throw ex
        End Try

        Return doc
    End Function

    Public Function GetRegisterInfo(aktenzeichen As String) As XmlDocument
        Dim doc As New XmlDocument()
        Dim xmlstring As String

        Try
            xmlstring = _service.getRegisterInfo(_user, _pass, aktenzeichen)
            'xmlstring = _service.getRegisterInfoBySt13Akz(_user, _pass, aktenzeichen)
            doc.LoadXml(xmlstring)
        Catch ex As Exception
            Throw ex
        End Try

        Return doc
    End Function




End Class
