use Logging Module EVERYWHERE, fix some MarvMan bugs

This commit is contained in:
Jonathan Jenne
2020-03-04 12:24:43 +01:00
parent 13b36db5fb
commit c8c650922b
22 changed files with 1279 additions and 1178 deletions

View File

@@ -23,7 +23,7 @@ Public Class ClassHotkey_Windream
Dim enumerator1 As New ClassWindowAPI
'Jedes Formularwindow durchlaufen
For Each top As ClassWindowAPI.ApiWindow In enumerator1.GetTopLevelWindows()
If LogErrorsOnly = False Then ClassLogger.Add(" ... top-window Name: " & top.MainWindowTitle, False)
LOGGER.Info(" ... top-window Name: " & top.MainWindowTitle)
If top.MainWindowTitle.Contains(windowname) Or top.MainWindowTitle.ToLower = windowname.ToLower Then
Control_Sequence = 0
For Each vControl As ClassWindowAPI.ApiWindow In enumerator1.GetChildWindows(top.hWnd)
@@ -33,7 +33,7 @@ Public Class ClassHotkey_Windream
If Value.ToUpper = vControl.MainWindowTitle.ToUpper Then
Return True
Else
If LogErrorsOnly = False Then ClassLogger.Add(" ... Control-Sequence: " & myControlNo.ToString & " entspricht nicht dem Matchvalue.", False)
LOGGER.Info(" ... Control-Sequence: " & myControlNo.ToString & " entspricht nicht dem Matchvalue.")
Return False
End If
End If
@@ -45,7 +45,7 @@ Public Class ClassHotkey_Windream
Next top
Catch ex As Exception
MsgBox("Error in IsRelevantWindowt:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
ClassLogger.Add(">> Error in IsRelevantWindow:" & ex.Message, False)
LOGGER.Info(">> Error in IsRelevantWindow:" & ex.Message)
Return False
End Try
End Function
@@ -60,7 +60,7 @@ Public Class ClassHotkey_Windream
For Each vControl As ClassWindowAPI.ApiWindow In enumerator1.GetChildWindows(top.hWnd)
If vControl.MainWindowTitle <> "" Then
If Control_Sequence = myControlID Then
If LogErrorsOnly = False Then ClassLogger.Add(" ... Control-Sequence: " & myControlID.ToString & " - Gelesener Wert: " & vControl.MainWindowTitle, False)
LOGGER.Info(" ... Control-Sequence: " & myControlID.ToString & " - Gelesener Wert: " & vControl.MainWindowTitle)
Return vControl.MainWindowTitle.ToString
End If
End If
@@ -71,7 +71,7 @@ Public Class ClassHotkey_Windream
Next top
Catch ex As Exception
MsgBox("Error in Get_windowContent:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
ClassLogger.Add(">> Error in Get_windowContent:" & ex.Message, False)
LOGGER.Info(">> Error in Get_windowContent:" & ex.Message)
Return Nothing
End Try
End Function
@@ -92,7 +92,7 @@ Public Class ClassHotkey_Windream
End Sub
Public Shared Function RUN_WD_SEARCH(HK_USR_PROFILE_ID As Integer)
Try
If LogErrorsOnly = False Then ClassLogger.Add(" ...RUN_WD_SEARCH with HK_USR_PROFILE_ID '" & HK_USR_PROFILE_ID & "'", False)
LOGGER.Info(" ...RUN_WD_SEARCH with HK_USR_PROFILE_ID '" & HK_USR_PROFILE_ID & "'")
Dim DTWD As DataTable
Dim Objecttype As String
Dim windowname As String
@@ -103,15 +103,15 @@ Public Class ClassHotkey_Windream
Dim _sql = "SELECT WD_SEARCH,HKPROFILE_ID FROM TBHOTKEY_USER_PROFILE WHERE GUID = " & HK_USR_PROFILE_ID
DTWD = ClassDatabase.Return_Datatable(_sql)
If DTWD.Rows.Count = 0 Then
If LogErrorsOnly = False Then ClassLogger.Add(" ...KEINE USER_PROFILES hinterlegt", False)
LOGGER.Info(" ...KEINE USER_PROFILES hinterlegt")
Return "Uncexpected Error in Hotkey - Check Log for Hotkey"
End If
If DTWD.Rows.Count > 1 Then
ClassLogger.Add("Das Ergebnis von '" & _sql & "' liefert mehr als eine Zeile zurück!", True)
LOGGER.Info("Das Ergebnis von '" & _sql & "' liefert mehr als eine Zeile zurück!")
Return "Uncexpected Error in Hotkey - Check Log for Hotkey"
End If
If DTWD.Rows(0).Item(0) = "" Then
If LogErrorsOnly = False Then ClassLogger.Add(">> KEINE Windream-Suche hinterlegt!", False)
LOGGER.Info(">> KEINE Windream-Suche hinterlegt!")
Return "Error in Hotkey - KEINE Windream-Suche hinterlegt - Check Logkey"
End If
Dim BaseSearch = DTWD.Rows(0).Item(0)
@@ -119,7 +119,7 @@ Public Class ClassHotkey_Windream
HKPROFILE_ID = DTWD.Rows(0).Item("HKPROFILE_ID")
Dim windream_temp_search As String = ""
If IO.File.Exists(BaseSearch) = False Then
ClassLogger.Add("Die Windream-Suche existiert nicht oder ist nicht zugreifbar!", True)
LOGGER.Info("Die Windream-Suche existiert nicht oder ist nicht zugreifbar!")
If USER_LANGUAGE = "de-DE" Then
MsgBox("Die Windream-Suche existiert nicht oder ist nicht zugreifbar!", MsgBoxStyle.Critical)
@@ -148,9 +148,9 @@ Public Class ClassHotkey_Windream
Dim WDUnicode = ClassDatabase.Execute_Scalar("SELECT WD_UNICODE FROM TBGI_CONFIGURATION WHERE GUID = 1", MyConnectionString, True)
If WDUnicode = True Then
EncodingFormat = Encoding.GetEncoding(1252) '1252
If LogErrorsOnly = False Then ClassLogger.Add(" ...Unicode is used (Encoding.GetEncoding(1252))", False)
LOGGER.Info(" ...Unicode is used (Encoding.GetEncoding(1252))")
Else
If LogErrorsOnly = False Then ClassLogger.Add(" ...UTF8 (Encoding.GetEncoding(65001))", False)
LOGGER.Info(" ...UTF8 (Encoding.GetEncoding(65001))")
EncodingFormat = Encoding.GetEncoding(65001)
End If
@@ -160,16 +160,16 @@ Public Class ClassHotkey_Windream
For Each row As DataRow In DT_HOOKS.Rows
RelevantWindow = IsRelevantWindow(windowname, row.Item("SEQUENCE_NUMBER"), row.Item("CONTROL_VALUE"))
If RelevantWindow = False Then
If LogErrorsOnly = False Then ClassLogger.Add(" ...Not the relevant window", False)
LOGGER.Info(" ...Not the relevant window")
Return "Not the Relevant window......"
End If
Next
End If
If LogErrorsOnly = False Then ClassLogger.Add(" ...ReadAlltext: " & BaseSearch, False)
LOGGER.Info(" ...ReadAlltext: " & BaseSearch)
fileContents = My.Computer.FileSystem.ReadAllText(BaseSearch, EncodingFormat) ', System.Text.Encoding.Unicode
If LogErrorsOnly = False Then ClassLogger.Add(" ...fileContents geladen", False)
LOGGER.Info(" ...fileContents geladen")
fileContents = fileContents.Replace("Í", "Ö")
'Das Array für die PAtterns anpassen
_sql = "select * from TBHOTKEY_PATTERNS WHERE HKPROFILE_ID = " & HKPROFILE_ID
@@ -212,7 +212,7 @@ Public Class ClassHotkey_Windream
End If
Else
If LogErrorsOnly = False Then ClassLogger.Add(" ...Get Value for Control# '" & row.Item("SEQUENCE_NUMBER").ToString & "'", False)
LOGGER.Info(" ...Get Value for Control# '" & row.Item("SEQUENCE_NUMBER").ToString & "'")
Dim foundresult = Get_windowContent(windowname, row.Item("SEQUENCE_NUMBER").ToString)
If Not IsNothing(foundresult) Then
'Die Nachbearbeitungsschritte laden
@@ -225,15 +225,15 @@ Public Class ClassHotkey_Windream
End If
If Not IsNothing(foundresult) Then
If foundresult.ToString = "<" Or foundresult.ToString = ">" Then
ClassLogger.Add(">> Hot Key received an irregular value.", False)
LOGGER.Info(">> Hot Key received an irregular value.")
Return "Hotkey konnte nur einen irregulären Wert auswerten."
End If
If LogErrorsOnly = False Then ClassLogger.Add(" ...fileContents.length: " & fileContents.Length, False)
If LogErrorsOnly = False Then ClassLogger.Add(" ...Replace pattern '" & row.Item(2).ToString & "' with '" & foundresult & "'", False)
LOGGER.Info(" ...fileContents.length: " & fileContents.Length)
LOGGER.Info(" ...Replace pattern '" & row.Item(2).ToString & "' with '" & foundresult & "'")
fileContents = fileContents.Replace(row.Item(2).ToString, foundresult)
If LogErrorsOnly = False Then ClassLogger.Add(" ...fileContents.length: " & fileContents.Length, False)
LOGGER.Info(" ...fileContents.length: " & fileContents.Length)
Else
ClassLogger.Add(">> Hot Key could not read any value.", False)
LOGGER.Info(">> Hot Key could not read any value.")
Return "Hotkey konnte keinen Wert auswerten - Evtl. ist das konfigurierte Fenster nicht geöffnet?"
End If
End If
@@ -246,7 +246,7 @@ Public Class ClassHotkey_Windream
Try
'Die File schreiben
My.Computer.FileSystem.WriteAllText(windream_temp_search, fileContents, False, EncodingFormat)
If LogErrorsOnly = False Then ClassLogger.Add(" ...wrote Text to windream_temp_search: " & windream_temp_search, False)
LOGGER.Info(" ...wrote Text to windream_temp_search: " & windream_temp_search)
' XML-Datei öffnen und laden
Dim Stream As New IO.StreamReader(CStr(windream_temp_search), EncodingFormat)
Dim Reader As New System.Xml.XmlTextReader(Stream)
@@ -257,9 +257,10 @@ Public Class ClassHotkey_Windream
xml.Load(Reader)
Reader.Close()
xml.Save(windream_temp_search)
If LogErrorsOnly = False Then ClassLogger.Add(" ...Xml Generiert: " & windream_temp_search, False)
LOGGER.Info(" ...Xml Generiert: " & windream_temp_search)
Catch ex As Exception
ClassLogger.Add("TempFile could not be created: " & ex.Message, True)
LOGGER.Info("TempFile could not be created: " & ex.Message)
LOGGER.Error(ex.Message)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected Error in Write XmlSearch:")
End Try
@@ -281,14 +282,14 @@ Public Class ClassHotkey_Windream
Dim rctMain As RECT
GetWindowRect(p.MainWindowHandle, rctMain)
If LogErrorsOnly = False Then
ClassLogger.Add(" ...Top-Position: " & rctMain.Top.ToString, False)
ClassLogger.Add(" ...Left-Position: " & rctMain.Left.ToString, False)
ClassLogger.Add(" ...Right-Position: " & rctMain.Right.ToString, False)
ClassLogger.Add(" ...Bottom-Position: " & rctMain.Bottom.ToString, False)
LOGGER.Info(" ...Top-Position: " & rctMain.Top.ToString)
LOGGER.Info(" ...Left-Position: " & rctMain.Left.ToString)
LOGGER.Info(" ...Right-Position: " & rctMain.Right.ToString)
LOGGER.Info(" ...Bottom-Position: " & rctMain.Bottom.ToString)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error while executing windream-Search:")
ClassLogger.Add("Unexpected error while executing search: " & ex.Message, True)
LOGGER.Info("Unexpected error while executing search: " & ex.Message)
Return "Unexpected error while executing search"
End Try
Dim psList() As Process
@@ -312,17 +313,20 @@ Public Class ClassHotkey_Windream
Next p
Catch ex As Exception
ClassLogger.Add("Unexpected error while Setting foreground: " & ex.Message, True)
LOGGER.Info("Unexpected error while Setting foreground: " & ex.Message)
LOGGER.Error(ex.Message)
End Try
Return ""
Catch ex As Exception
ClassLogger.Add("Unexpected error in Create Search: " & ex.Message, True)
LOGGER.Info("Unexpected error in Create Search: " & ex.Message)
LOGGER.Error(ex.Message)
MsgBox("Error in Create Search:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return "Unexpected error in Create Search"
End Try
Catch ex As Exception
ClassLogger.Add("Unexpected error in RUN_WD_SEARCH: " & ex.Message, True)
LOGGER.Info("Unexpected error in RUN_WD_SEARCH: " & ex.Message)
LOGGER.Error(ex.message)
MsgBox("Error in RUN_WD_SEARCH:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return "Unerwarteter Unexpected error in RUN_WD_SEARCH"
End Try