187 lines
7.8 KiB
VB.net
187 lines
7.8 KiB
VB.net
Imports System.Console
|
|
Imports System.IO
|
|
Imports System.Xml
|
|
Imports NLog
|
|
|
|
Module Main
|
|
Private logger As Logger
|
|
|
|
Private mainDoc As XmlDocument
|
|
Private markDoc As XmlDocument
|
|
|
|
Private MainFile As String = "Importer-SearchData.xml"
|
|
|
|
Private p As New Parser()
|
|
Private dpma As DPMAConnect
|
|
Private db As DB
|
|
|
|
Private config As ConfigValues
|
|
Private marks As New List(Of Mark)
|
|
Private props = New List(Of String) From {
|
|
"RegistrationOfficeCode",
|
|
"RegistrationDate",
|
|
"RegistrationNumber",
|
|
"MarkCurrentStatusCode",
|
|
"MarkVerbalElementText",
|
|
"MarkFeature",
|
|
"ApplicationDate",
|
|
"Applicant",
|
|
"Representative",
|
|
"PublicationDate",
|
|
"ExpiryDate",
|
|
"TerminationDate",
|
|
"OppositionPeriodStartDate",
|
|
"OppositionPeriodEndDate",
|
|
"Classification",
|
|
"ClassificationLong"
|
|
}
|
|
|
|
Sub Main()
|
|
Try
|
|
logger = LogManager.GetLogger("Main")
|
|
config = AppConfig.GetConfiguration()
|
|
|
|
logger.Info("{0} started", My.Application.Info.Title)
|
|
|
|
' Abfrage starten
|
|
logger.Info("Sending request with query: {0}", config.query)
|
|
dpma = New DPMAConnect(config.username, config.password)
|
|
mainDoc = dpma.Search(config.query)
|
|
mainDoc.Save(MainFile)
|
|
|
|
' Ergebnis auslesen und Marken-Klassen erstellen
|
|
marks = p.ReadMarkXMLFile(MainFile)
|
|
|
|
logger.Info("Importing Marks..")
|
|
|
|
For Each mark As Mark In marks
|
|
Dim akz As String = mark.ApplicationNumber
|
|
Dim file As String = String.Format("Importer-RegisterData-{0}.xml", akz)
|
|
|
|
logger.Debug("Getting Register Info for {0}", akz)
|
|
|
|
markDoc = dpma.GetRegisterInfo(akz)
|
|
markDoc.Save(file)
|
|
|
|
p.ReadMarkRegisterInfoXMLFile(file, mark)
|
|
Next
|
|
|
|
logger.Info("{0} Marks imported", marks.Count)
|
|
logger.Debug("=================== DPMA END ===================")
|
|
|
|
' =========================================================================================
|
|
|
|
db = New DB(config.connstring, "DD_ECM")
|
|
Dim formId As Integer = db.GetFormId()
|
|
Dim changedMarks As Integer = 0
|
|
Dim addedMarks As Integer = 0
|
|
|
|
For Each m As Mark In marks
|
|
|
|
Dim mainControlId As Integer
|
|
|
|
' Das eindeutige Control suchen
|
|
mainControlId = db.GetControlId(formId)
|
|
|
|
' Über mainControlId überprüfen, ob marke vorhanden
|
|
Dim markExists As Integer = db.GetRecordId(mainControlId, m.ApplicationNumber)
|
|
logger.Debug("Mark {0} exists: {1}", markExists, CBool(markExists))
|
|
|
|
' Wenn noch nicht vorhanden
|
|
If (markExists = 0) Then
|
|
' Einen Record erstellen
|
|
Dim recordId = db.InsertRecord(formId)
|
|
logger.Info("New record created with GUID: " & recordId)
|
|
' Den Leit-Wert einfügen für mainControlId
|
|
Dim valueId = db.InsertValue(mainControlId, recordId, m.ApplicationNumber)
|
|
addedMarks = addedMarks + 1
|
|
logger.Debug("Value inserted - Property: {0}, Value: {1}, ControlId: {2}", "ApplicationNumber", m.ApplicationNumber, mainControlId)
|
|
|
|
' alle anderen properties zu dieser marke einfügen einfügen
|
|
For Each prop As String In props
|
|
' ControlID für die aktuelle property holen
|
|
Dim controlId = db.GetControlId(formId, prop)
|
|
' Wert für die aktuelle property holen
|
|
Dim value = db.GetProperty(m, prop)
|
|
' Wert einfügen
|
|
db.InsertValue(controlId, recordId, value)
|
|
|
|
' Wenn Bildmarke oder Wort- und Bildmarke, Bild einfügen
|
|
If prop = "MarkFeature" Then
|
|
If value = "wort-bildmarke" Or value = "bildmarke" Then
|
|
Dim imageControlId = db.GetControlId(formId, "MarkImage")
|
|
Dim bimage() As Byte = Image.ToByteArray(m.Image.BinaryImage)
|
|
db.InsertImage(bimage, imageControlId, recordId)
|
|
End If
|
|
End If
|
|
|
|
logger.Debug("Value inserted - Property: {0}, Value: {1}, ControlId: {2}", prop, value, controlId)
|
|
Next
|
|
Else
|
|
' Marke aktualisieren
|
|
Dim recordId As Integer = markExists
|
|
Dim propsChanged = False
|
|
|
|
logger.Info("Existing Record updated with GUID: {0}", recordId)
|
|
|
|
For Each prop As String In props
|
|
' ControlID für die aktuelle property holen
|
|
Dim controlId = db.GetControlId(formId, prop)
|
|
' Wert für die aktuelle property holen
|
|
Dim value = db.GetProperty(m, prop)
|
|
|
|
' Wert aktualisieren
|
|
db.UpdateValue(controlId, recordId, value)
|
|
|
|
' Wenn Bildmarke oder Wort- und Bildmarke, Bild aktualisieren
|
|
If prop = "MarkFeature" Then
|
|
If value = "wort-bildmarke" Or value = "bildmarke" Then
|
|
Dim imageControlId = db.GetControlId(formId, "MarkImage")
|
|
Dim bimage() As Byte = Image.ToByteArray(m.Image.BinaryImage)
|
|
db.UpdateImage(bimage, imageControlId, recordId)
|
|
End If
|
|
End If
|
|
|
|
logger.Debug("Value updated - Property: {0}, ControlId: {1}", prop, controlId)
|
|
|
|
'Dim hasChanged As Boolean = Not db.IsEqual(controlId, recordId, value)
|
|
'logger.Debug("Value for {0} has changed", recordId)
|
|
|
|
'If hasChanged Then
|
|
' propsChanged = True
|
|
' ' Wert aktualisieren
|
|
' db.UpdateValue(controlId, recordId, value)
|
|
' logger.Debug("Value updated - Property: {0}, ControlId: {1}", prop, controlId)
|
|
'End If
|
|
Next
|
|
|
|
If propsChanged Then
|
|
changedMarks = changedMarks + 1
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
logger.Info("{0} Marks added, {1} updated", addedMarks, changedMarks)
|
|
logger.Debug("=================== DATABASE END ===================")
|
|
|
|
Catch ex As Exception
|
|
logger.Error("An Error occurred: {0}", GetExceptionInfo(ex))
|
|
logger.Error("{0}, {1}, {2}, {3}, {4}", config.username, config.password, config.query, config.connstring, config.database)
|
|
Environment.Exit(1)
|
|
End Try
|
|
End Sub
|
|
|
|
Public Function GetExceptionInfo(ex As Exception) As String
|
|
Dim Result As String
|
|
Dim hr As Integer = Runtime.InteropServices.Marshal.GetHRForException(ex)
|
|
Result = ex.GetType.ToString & "(0x" & hr.ToString("X8") & "): " & ex.Message & Environment.NewLine & ex.StackTrace & Environment.NewLine
|
|
Dim st As StackTrace = New StackTrace(ex, True)
|
|
For Each sf As StackFrame In st.GetFrames
|
|
If sf.GetFileLineNumber() > 0 Then
|
|
Result &= "Line:" & sf.GetFileLineNumber() & " Filename: " & IO.Path.GetFileName(sf.GetFileName) & Environment.NewLine
|
|
End If
|
|
Next
|
|
Return Result
|
|
End Function
|
|
End Module
|