From b2242cb6a93266134309f92bd06a2b0c6f2a37fc Mon Sep 17 00:00:00 2001 From: OlgunR Date: Thu, 28 Aug 2025 16:01:43 +0200 Subject: [PATCH] Leerer Betreff beim Ablegen Emails wird abgefangen - frmIndex --- Global_Indexer/frmIndex.vb | 580 +++++++++++++++++++++++++++---------- 1 file changed, 424 insertions(+), 156 deletions(-) diff --git a/Global_Indexer/frmIndex.vb b/Global_Indexer/frmIndex.vb index d7ce590..f829b73 100644 --- a/Global_Indexer/frmIndex.vb +++ b/Global_Indexer/frmIndex.vb @@ -775,27 +775,28 @@ Public Class frmIndex ' Textboxen (TextEdit) If oControl.Name.StartsWith("txt") Then - Dim box As DevExpress.XtraEditors.TextEdit = DirectCast(oControl, DevExpress.XtraEditors.TextEdit) - Dim indexName = Replace(box.Name, "txt", "") - Dim optionalIndex As Boolean = DATABASE_ECM.GetScalarValue($"SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = {oDocumentTypeId} AND NAME = '{indexName}'") - - If String.IsNullOrWhiteSpace(box.Text) Then - If Not optionalIndex Then - DxErrorProvider1.SetError(box, If(USER_LANGUAGE = LANG_DE, TEXT_MISSING_INPUT_DE, TEXT_MISSING_INPUT_EN)) - box.Focus() + Dim oBox As DevExpress.XtraEditors.TextEdit = DirectCast(oControl, DevExpress.XtraEditors.TextEdit) + Dim oIndexName = Replace(oBox.Name, "txt", "") + Dim oOptionalIndex As Boolean = DATABASE_ECM.GetScalarValue($"SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = {oDocumentTypeId} AND NAME = '{oIndexName}'") + + If String.IsNullOrWhiteSpace(oBox.Text) Then + If Not oOptionalIndex Then + DxErrorProvider1.SetError(oBox, If(USER_LANGUAGE = LANG_DE, TEXT_MISSING_INPUT_DE, TEXT_MISSING_INPUT_EN)) + oBox.Focus() Return False End If - Indexwert_Postprocessing(indexName, "") + Indexwert_Postprocessing(oIndexName, "") Else - If Not Indexwert_checkValueDB(indexName, box.Text) Then - Dim msg = If(USER_LANGUAGE = LANG_DE, + If Not Indexwert_checkValueDB(oIndexName, oBox.Text) Then + Dim oMsg = If(USER_LANGUAGE = LANG_DE, "Der eingegebene Wert wurde nicht in der Datenbank gefunden!", "The value was not found in the Database!") - DxErrorProvider1.SetError(box, msg) - box.Focus() + DxErrorProvider1.SetError(oBox, oMsg) + oBox.Focus() Return False End If - Indexwert_Postprocessing(indexName, box.Text) + Indexwert_Postprocessing(oIndexName, oBox.Text) + _Logger.Debug($"Der Index: '{oIndexName}' wurde mit dem Wert '{oBox.Text}' beschrieben.") End If oResult = True Continue For @@ -878,6 +879,7 @@ Public Class frmIndex Indexwert_Postprocessing(indexName, "") Else Indexwert_Postprocessing(indexName, dtp.Text) + _Logger.Debug($"Der Index '{indexName}' wurde mit dem Wert '{dtp.Text}' beschrieben.") End If oResult = True Continue For @@ -1145,97 +1147,257 @@ Public Class frmIndex End Try End Function + 'Private Function Write_Indizes() As Boolean + ' Try + + ' _Logger.Info("Indexing file [{0}]", CURRENT_NEWFILENAME) + + ' Dim indexierung_erfolgreich As Boolean = False + ' 'Manuelle Indexe Indexieren + ' Dim DTMan As DataTable = MyDataset.VWDDINDEX_MAN + ' If DTMan.Rows.Count > 0 Then + ' Dim Count As Integer = 0 + ' For Each row As DataRow In DTMan.Rows + ' Dim idxvalue = row.Item("Indexwert") + ' Dim indexname = row.Item("WD_INDEX").ToString + ' _Logger.Debug($"Write_Indizes - Index [{indexname}]...") + ' Dim optional_Index = CBool(row.Item("OPTIONAL")) + ' Dim indexiert = CBool(row.Item("Indexiert")) + ' If indexiert And idxvalue.ToString <> "" And idxvalue <> "EMPTY_OI" Then + ' If indexname <> String.Empty Then + ' If row.Item("SAVE_VALUE") = True Then + ' 'Den Indexwert zwischenspeichern + ' Dim DTTemp As DataTable = MyDataset.TBTEMP_INDEXRESULTS + ' Dim rowexists As Boolean = False + ' For Each rowTemp As DataRow In DTTemp.Rows + ' 'Wenn bereits ein Eintrag existiert..... + ' If rowTemp.Item("Dokumentart") = row.Item("DOKUMENTART") And rowTemp.Item("Indexname") = row.Item("INDEXNAME") Then + ' rowexists = True + ' '......überschreiben + ' rowTemp.Item("Value") = row.Item("Indexwert") + ' End If + ' Next + ' '.....ansonsten neu anlegen + ' If rowexists = False Then + ' Dim newRow As DataRow = DTTemp.NewRow() + ' newRow("Dokumentart") = row.Item("DOKUMENTART").ToString + ' newRow("Indexname") = row.Item("INDEXNAME").ToString + ' newRow("Value") = row.Item("Indexwert") + ' DTTemp.Rows.Add(newRow) + ' End If + ' End If + + ' _Logger.Debug($"Manueller Indexvalue [{idxvalue}]...NOW THE INDEXING...") + ' Count += 1 + + + ' ' den Typ des Zielindexes auslesen + ' Dim oIndexType As Integer = WINDREAM.GetIndexType(indexname) + ' _Logger.Debug($"oIndexType [{oIndexType}]...") + ' If oIndexType = 0 Then + ' MsgBox("Could not get the windream-indextype. Check Your Configuration", MsgBoxStyle.Information, "Attention") + ' Return False + ' End If + ' If oIndexType > 4095 Then + ' _Logger.Debug($"Indexing Vektor - oIndexType [{oIndexType}] ...") + ' Dim oSplitArray = Split(idxvalue, ClassConstants.VECTORSEPARATOR) + ' Dim oListofString As New List(Of String) + ' 'If oSplitArray.Length <= 1 Then + ' ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, idxvalue, CURR_DOKART_OBJECTTYPE) + ' 'Else + ' For Each oStr In oSplitArray + ' oListofString.Add(oStr) + ' Next + ' indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, indexname, oListofString, CURR_DOKART_OBJECTTYPE) + ' 'End If + + ' Else + ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, idxvalue, CURR_DOKART_OBJECTTYPE) + ' End If + + ' 'indexierung_erfolgreich = ClassWindream.DateiIndexieren(CURRENT_NEWFILENAME, indexname, idxvalue) + ' If indexierung_erfolgreich = False Then + ' MsgBox("Error in Indexing file - See log", MsgBoxStyle.Critical) + ' Return False + ' Exit For + ' End If + ' Else + + ' _Logger.Debug("No Indexing: indexname: " & indexname) + ' _Logger.Debug("No Indexing: is optional? " & optional_Index.ToString) + ' End If + ' Else + ' _Logger.Debug("Indexvalue is empty or field is not indexed - Indexname: " & indexname) + ' _Logger.Info("Indexvalue is empty or field is not indexed - Indexname: " & indexname) + ' End If + ' Next + + ' End If + ' 'Automatische Indexe Indexieren + ' Dim DTAut As DataTable = MyDataset.VWDDINDEX_AUTOM + ' If DTAut.Rows.Count > 0 Then + ' _Logger.Debug(" #### Es gibt automatische Atrribute - Anzahl: " & DTAut.Rows.Count.ToString & " #####") + ' Dim Count As Integer = 0 + ' For Each row As DataRow In DTAut.Rows + ' Dim oIsIndexed = CBool(row.Item("Indexiert")) + ' Dim oIndexValue = row.Item("Indexwert").ToString + ' Dim oIndexName = row.Item("INDEXNAME").ToString + ' Dim oOverwrite As Boolean = row.ItemEx("VKT_OVERWRITE", False) + ' Dim oPreventMultipleValues As Boolean = row.ItemEx("VKT_PREVENT_MULTIPLE_VALUES", False) + + ' If oIsIndexed = True And oIndexValue <> "" Then + ' If oIndexValue <> "EMPTY_OI" Then + ' _Logger.Info("Auto Indexname: " & oIndexName.ToString) + ' _Logger.Info("Indexvalue: " & oIndexValue.ToString) + ' Count += 1 + + ' ' den Typ des Zielindexes auslesen + ' Dim oIndexType As Integer = WINDREAM.GetIndexType(oIndexName) + ' _Logger.Debug("WMIndexType: " & oIndexType.ToString) + ' If oIndexType > 4095 Then + ' _Logger.Debug("Es Handelt sich um einen VektorIndex...") + ' Dim oExistingItems = WINDREAM.GetIndexValue(CURRENT_NEWFILENAME, oIndexName) + + ' Dim oSplitArray = Split(oIndexValue, ClassConstants.VECTORSEPARATOR) + ' Dim oListofString As New List(Of String) + ' If oSplitArray.Length = 0 Then + ' _Logger.Debug("oSplitArray.Length = 0") + ' oListofString.Add(oIndexValue) + ' Else + ' _Logger.Debug("oSplitArray is > 0 ...") + ' For Each oStr In oSplitArray + ' _Logger.Debug("oSplitArray - oStr: {0}", oStr) + ' oListofString.Add(oStr) + ' Next + ' End If + + ' 'If oSplitArray.Length <= 1 Then + ' ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, oIndexName, oIndexValue, CURR_DOKART_OBJECTTYPE) + ' 'Else + ' If oOverwrite = False And oExistingItems.Count > 0 And oIndexType <> 4100 Then + ' _Logger.Debug("oOverwrite = False and WMObject already contains [{0}] values in attribute,Values will be concatted", oExistingItems.Count) + ' oListofString = oExistingItems.Concat(oListofString).ToList() + ' End If + ' If oPreventMultipleValues = True Then + ' _Logger.Debug("Preventing multiple values in Vektor") + ' oListofString = oListofString.Distinct().ToList() + ' End If + ' indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, oIndexName, oListofString, CURR_DOKART_OBJECTTYPE) + ' 'End If + + ' Else + ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, oIndexName, oIndexValue, CURR_DOKART_OBJECTTYPE) + ' End If + + ' 'indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, Indexvalue, CURR_DOKART_OBJECTTYPE) + ' If indexierung_erfolgreich = False Then + ' MsgBox("Error in indexing file - See log", MsgBoxStyle.Critical) + ' Return False + ' Exit For + ' End If + ' End If + ' End If + ' Next + ' End If + ' If DropType = "|OUTLOOK_MESSAGE|" Or DropType = "|FW_MSGONLY|" Or DropType = "|MSGONLY|" Or CURRENT_NEWFILENAME.ToUpper.EndsWith(".MSG") Or CURRENT_NEWFILENAME.ToUpper.EndsWith(".EML") Then + ' indexierung_erfolgreich = SetEmailIndicies(False) + ' If indexierung_erfolgreich = False Then + ' MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical) + ' Return False + ' End If + ' ElseIf DropType = "|ATTMNTEXTRACTED|" Or DropType = "|OUTLOOK_ATTACHMENT|" Then + ' indexierung_erfolgreich = SetEmailIndicies(True) + ' If indexierung_erfolgreich = False Then + ' MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical) + ' Return False + ' End If + ' End If + ' Catch ex As Exception + ' ShowErrorMessage(ex, "Write_Indizes") + ' Return False + ' Finally + + ' End Try + ' Return True + 'End Function + Private Function Write_Indizes() As Boolean Try - - _Logger.Info("Indexing file [{0}]", CURRENT_NEWFILENAME) + _Logger.Info("Starting indexing for file [{0}] (DropType = {1})", CURRENT_NEWFILENAME, DropType) Dim indexierung_erfolgreich As Boolean = False - 'Manuelle Indexe Indexieren + + ' ---------------------- + ' Manuelle Indizes + ' ---------------------- Dim DTMan As DataTable = MyDataset.VWDDINDEX_MAN If DTMan.Rows.Count > 0 Then - Dim Count As Integer = 0 + _Logger.Info("Processing {0} manual indexes...", DTMan.Rows.Count) For Each row As DataRow In DTMan.Rows Dim idxvalue = row.Item("Indexwert") Dim indexname = row.Item("WD_INDEX").ToString - _Logger.Debug($"Write_Indizes - Index [{indexname}]...") Dim optional_Index = CBool(row.Item("OPTIONAL")) Dim indexiert = CBool(row.Item("Indexiert")) - If indexiert And idxvalue.ToString <> "" And idxvalue <> "EMPTY_OI" Then + + If indexiert AndAlso Not String.IsNullOrEmpty(idxvalue.ToString) AndAlso idxvalue <> "EMPTY_OI" Then If indexname <> String.Empty Then + _Logger.Debug("Manual Index: [{0}] Value: [{1}]", indexname, idxvalue) + + ' Zwischenspeichern falls SAVE_VALUE If row.Item("SAVE_VALUE") = True Then - 'Den Indexwert zwischenspeichern Dim DTTemp As DataTable = MyDataset.TBTEMP_INDEXRESULTS - Dim rowexists As Boolean = False - For Each rowTemp As DataRow In DTTemp.Rows - 'Wenn bereits ein Eintrag existiert..... - If rowTemp.Item("Dokumentart") = row.Item("DOKUMENTART") And rowTemp.Item("Indexname") = row.Item("INDEXNAME") Then - rowexists = True - '......überschreiben - rowTemp.Item("Value") = row.Item("Indexwert") - End If - Next - '.....ansonsten neu anlegen - If rowexists = False Then + Dim rowexists As Boolean = DTTemp.Rows.Cast(Of DataRow)().Any(Function(r) r.Item("Dokumentart") = row.Item("DOKUMENTART") AndAlso r.Item("Indexname") = row.Item("INDEXNAME")) + If rowexists Then + DTTemp.Rows.Cast(Of DataRow)().First(Function(r) r.Item("Dokumentart") = row.Item("DOKUMENTART") AndAlso r.Item("Indexname") = row.Item("INDEXNAME")).Item("Value") = idxvalue + Else Dim newRow As DataRow = DTTemp.NewRow() newRow("Dokumentart") = row.Item("DOKUMENTART").ToString newRow("Indexname") = row.Item("INDEXNAME").ToString - newRow("Value") = row.Item("Indexwert") + newRow("Value") = idxvalue DTTemp.Rows.Add(newRow) End If End If - _Logger.Debug($"Manueller Indexvalue [{idxvalue}]...NOW THE INDEXING...") - Count += 1 - - - ' den Typ des Zielindexes auslesen + ' Indextyp prüfen Dim oIndexType As Integer = WINDREAM.GetIndexType(indexname) - _Logger.Debug($"oIndexType [{oIndexType}]...") If oIndexType = 0 Then + LOGGER.Error("Could not get the Windream index type for [{0}]. Check configuration.", indexname) MsgBox("Could not get the windream-indextype. Check Your Configuration", MsgBoxStyle.Information, "Attention") Return False End If + + ' Vektor oder normal If oIndexType > 4095 Then - _Logger.Debug($"Indexing Vektor - oIndexType [{oIndexType}] ...") + _Logger.Debug("Index [{0}] is a vector type.", indexname) Dim oSplitArray = Split(idxvalue, ClassConstants.VECTORSEPARATOR) - Dim oListofString As New List(Of String) - 'If oSplitArray.Length <= 1 Then - ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, idxvalue, CURR_DOKART_OBJECTTYPE) - 'Else - For Each oStr In oSplitArray - oListofString.Add(oStr) - Next - indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, indexname, oListofString, CURR_DOKART_OBJECTTYPE) - 'End If - + Dim oListOfString As New List(Of String)(oSplitArray) + indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, indexname, oListOfString, CURR_DOKART_OBJECTTYPE) Else indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, idxvalue, CURR_DOKART_OBJECTTYPE) End If - 'indexierung_erfolgreich = ClassWindream.DateiIndexieren(CURRENT_NEWFILENAME, indexname, idxvalue) If indexierung_erfolgreich = False Then + LOGGER.Error("Failed to index manual field [{0}] with value [{1}]", indexname, idxvalue) MsgBox("Error in Indexing file - See log", MsgBoxStyle.Critical) Return False - Exit For End If Else - - _Logger.Debug("No Indexing: indexname: " & indexname) - _Logger.Debug("No Indexing: is optional? " & optional_Index.ToString) + _Logger.Warn("Skipping manual index: Indexname empty. Optional: {0}", optional_Index) End If Else - _Logger.Debug("Indexvalue is empty or field is not indexed - Indexname: " & indexname) - _Logger.Info("Indexvalue is empty or field is not indexed - Indexname: " & indexname) + _Logger.Debug("Skipping manual index [{0}] - value empty or not indexed.", indexname) End If Next - + Else + _Logger.Debug("No manual indexes to process.") End If - 'Automatische Indexe Indexieren + + ' ---------------------- + ' Automatische Indizes + ' ---------------------- Dim DTAut As DataTable = MyDataset.VWDDINDEX_AUTOM If DTAut.Rows.Count > 0 Then - _Logger.Debug(" #### Es gibt automatische Atrribute - Anzahl: " & DTAut.Rows.Count.ToString & " #####") - Dim Count As Integer = 0 + _Logger.Info("Processing {0} automatic indexes...", DTAut.Rows.Count) For Each row As DataRow In DTAut.Rows Dim oIsIndexed = CBool(row.Item("Indexiert")) Dim oIndexValue = row.Item("Indexwert").ToString @@ -1243,81 +1405,70 @@ Public Class frmIndex Dim oOverwrite As Boolean = row.ItemEx("VKT_OVERWRITE", False) Dim oPreventMultipleValues As Boolean = row.ItemEx("VKT_PREVENT_MULTIPLE_VALUES", False) - If oIsIndexed = True And oIndexValue <> "" Then - If oIndexValue <> "EMPTY_OI" Then - _Logger.Info("Auto Indexname: " & oIndexName.ToString) - _Logger.Info("Indexvalue: " & oIndexValue.ToString) - Count += 1 + If oIsIndexed AndAlso Not String.IsNullOrEmpty(oIndexValue) AndAlso oIndexValue <> "EMPTY_OI" Then + _Logger.Info("Automatic Index: [{0}] Value: [{1}]", oIndexName, oIndexValue) + Dim oIndexType As Integer = WINDREAM.GetIndexType(oIndexName) + _Logger.Debug("WMIndexType for [{0}] = {1}", oIndexName, oIndexType) - ' den Typ des Zielindexes auslesen - Dim oIndexType As Integer = WINDREAM.GetIndexType(oIndexName) - _Logger.Debug("WMIndexType: " & oIndexType.ToString) - If oIndexType > 4095 Then - _Logger.Debug("Es Handelt sich um einen VektorIndex...") - Dim oExistingItems = WINDREAM.GetIndexValue(CURRENT_NEWFILENAME, oIndexName) - - Dim oSplitArray = Split(oIndexValue, ClassConstants.VECTORSEPARATOR) - Dim oListofString As New List(Of String) - If oSplitArray.Length = 0 Then - _Logger.Debug("oSplitArray.Length = 0") - oListofString.Add(oIndexValue) - Else - _Logger.Debug("oSplitArray is > 0 ...") - For Each oStr In oSplitArray - _Logger.Debug("oSplitArray - oStr: {0}", oStr) - oListofString.Add(oStr) - Next - End If + If oIndexType > 4095 Then + _Logger.Debug("Index [{0}] is a vector type.", oIndexName) + Dim oExistingItems = WINDREAM.GetIndexValue(CURRENT_NEWFILENAME, oIndexName) + Dim oSplitArray = Split(oIndexValue, ClassConstants.VECTORSEPARATOR) + Dim oListOfString As New List(Of String)(oSplitArray) - 'If oSplitArray.Length <= 1 Then - ' indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, oIndexName, oIndexValue, CURR_DOKART_OBJECTTYPE) - 'Else - If oOverwrite = False And oExistingItems.Count > 0 And oIndexType <> 4100 Then - _Logger.Debug("oOverwrite = False and WMObject already contains [{0}] values in attribute,Values will be concatted", oExistingItems.Count) - oListofString = oExistingItems.Concat(oListofString).ToList() - End If - If oPreventMultipleValues = True Then - _Logger.Debug("Preventing multiple values in Vektor") - oListofString = oListofString.Distinct().ToList() - End If - indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, oIndexName, oListofString, CURR_DOKART_OBJECTTYPE) - 'End If - - Else - indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, oIndexName, oIndexValue, CURR_DOKART_OBJECTTYPE) + If Not oOverwrite AndAlso oExistingItems.Count > 0 AndAlso oIndexType <> 4100 Then + oListOfString = oExistingItems.Concat(oListOfString).ToList() + _Logger.Debug("Concatenated existing values for vector index [{0}]", oIndexName) End If - 'indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, indexname, Indexvalue, CURR_DOKART_OBJECTTYPE) - If indexierung_erfolgreich = False Then - MsgBox("Error in indexing file - See log", MsgBoxStyle.Critical) - Return False - Exit For + If oPreventMultipleValues Then + oListOfString = oListOfString.Distinct().ToList() + _Logger.Debug("Removed duplicate values for vector index [{0}]", oIndexName) End If + + indexierung_erfolgreich = WINDREAM.SetFileIndexLoS(CURRENT_NEWFILENAME, oIndexName, oListOfString, CURR_DOKART_OBJECTTYPE) + Else + indexierung_erfolgreich = WINDREAM.SetFileIndex(CURRENT_NEWFILENAME, oIndexName, oIndexValue, CURR_DOKART_OBJECTTYPE) + End If + + If Not indexierung_erfolgreich Then + LOGGER.Error("Failed to index automatic field [{0}] with value [{1}]", oIndexName, oIndexValue) + MsgBox("Error in indexing file - See log", MsgBoxStyle.Critical) + Return False End If End If Next + Else + _Logger.Debug("No automatic indexes to process.") End If + + ' ---------------------- + ' E-Mail Indexing + ' ---------------------- If DropType = "|OUTLOOK_MESSAGE|" Or DropType = "|FW_MSGONLY|" Or DropType = "|MSGONLY|" Or CURRENT_NEWFILENAME.ToUpper.EndsWith(".MSG") Or CURRENT_NEWFILENAME.ToUpper.EndsWith(".EML") Then + _Logger.Info("Indexing email content for main email.") indexierung_erfolgreich = SetEmailIndicies(False) - If indexierung_erfolgreich = False Then - MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical) - Return False - End If ElseIf DropType = "|ATTMNTEXTRACTED|" Or DropType = "|OUTLOOK_ATTACHMENT|" Then + _Logger.Info("Indexing email content for attachment.") indexierung_erfolgreich = SetEmailIndicies(True) - If indexierung_erfolgreich = False Then - MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical) - Return False - End If End If + + If Not indexierung_erfolgreich Then + LOGGER.Error("SetEmailIndices failed. See previous logs.") + MsgBox("Error in SetEmailIndices - See log", MsgBoxStyle.Critical) + Return False + End If + + _Logger.Info("Indexing completed successfully for file [{0}].", CURRENT_NEWFILENAME) + Return True Catch ex As Exception ShowErrorMessage(ex, "Write_Indizes") + LOGGER.Error(ex, "Unexpected exception in Write_Indizes for file [{0}]", CURRENT_NEWFILENAME) Return False - Finally - End Try - Return True End Function + + Private Function WriteIndex2File(pIndexName As String, pIndexValue As String) Try _Logger.Info($"Indexing with Name {pIndexName} and Value: {pIndexValue}") @@ -1328,6 +1479,122 @@ Public Class frmIndex End Try End Function + 'Private Function SetEmailIndicies(pIndexAttachment As Boolean) As Boolean + ' Try + ' Dim oIndexNames As Dictionary(Of String, Object) + + ' Dim oSQL As String = $"SELECT * FROM TBGI_OBJECTTYPE_EMAIL_INDEX WHERE OBJECTTYPE = '{CURR_DOKART_OBJECTTYPE}'" + ' Dim oTable As DataTable = DATABASE_ECM.GetDatatable(oSQL) + + ' If IsNothing(oTable) Then + ' _Logger.Info("Could not get Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) + ' Return False + ' End If + + ' If oTable.Rows.Count = 0 Then + ' LOGGER.Warn("Could not get Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) + ' MsgBox($"Definition von Email Indizes für den Objekttyp [{oTable}] fehlt." + vbNewLine + "Bitte informieren Sie Ihren Systembetreuer.", MsgBoxStyle.Critical) + ' Return False + ' End If + + ' If oTable.Rows.Count > 1 Then + ' LOGGER.Warn("Got multiple rows for Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) + ' Return False + ' End If + + ' Dim oRow As DataRow = oTable.Rows.Item(0) + + ' ' If file is an email files (eml,msg) parse it to extract email data and save for later + ' ' If file is an attachment, rely on the previously extracted value + + + + ' If pIndexAttachment = False Then + ' LOGGER.Debug("Indexing Email File: [{0}]", CURRENT_NEWFILENAME) + + ' ' This cannot use Path.Combine, otherwise the WINDREAM_BASEPATH will be swallowed... lol + ' 'Dim oMsgFilePath As String = Path.Combine(WINDREAM_BASEPATH, CURRENT_NEWFILENAME) + + ' Dim oMsgFilePath As String = CURRENT_NEWFILENAME + ' If CURRENT_NEWFILENAME.StartsWith(WINDREAM_BASEPATH) = False Then + ' oMsgFilePath = WINDREAM_BASEPATH & oMsgFilePath + ' End If + + ' Dim oMail As IMail = EMAIL.Load_Email(oMsgFilePath) + + ' Dim oMessageId As String = oMail.MessageID + ' LOGGER.Debug("MessageId: [{0}]", oMessageId) + + ' Dim oMessageFrom As String = EMAIL.Get_MessageSender(oMail) + ' Dim oMessageTo As String = EMAIL.Get_MessageReceiver(oMail) + ' LOGGER.Debug("oMessageTo: [{0}]", oMessageTo.ToString) + ' Dim oDateIn As Date = EMAIL.Get_MessageDate(oMail) + ' LOGGER.Debug("oDateIn: [{0}]", oDateIn.ToString) + ' Dim oSubject As String = oMail.Subject + ' LOGGER.Debug("oSubject: [{0}]", oSubject) + + ' CURRENT_MESSAGEID = oMessageId + ' CURRENT_MESSAGEDATE = oDateIn + + ' If oSubject IsNot Nothing Then + ' CURRENT_MESSAGESUBJECT = oSubject + ' Else + ' CURRENT_MESSAGESUBJECT = "" + ' LOGGER.Info("No subject - Default will be used!") + ' End If + + ' oIndexNames = New Dictionary(Of String, Object) From { + ' {"IDX_EMAIL_ID", oMessageId}, + ' {"IDX_EMAIL_FROM", oMessageFrom}, + ' {"IDX_EMAIL_TO", oMessageTo}, + ' {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, + ' {"IDX_EMAIL_DATE_IN", oDateIn} + ' } + ' Else + ' oIndexNames = New Dictionary(Of String, Object) From { + ' {"IDX_EMAIL_ID", CURRENT_MESSAGEID}, + ' {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, + ' {"IDX_EMAIL_DATE_IN", CURRENT_MESSAGEDATE}, + ' {"IDX_CHECK_ATTACHMENT", True} + ' } + ' End If + + + ' For Each oIndex In oIndexNames + ' Try + ' If oIndex.Value Is Nothing Then + ' LOGGER.Warn("Value for Index [{0}] was empty. Skipping.", oIndex.Key) + ' Continue For + + ' End If + + ' If TypeOf oIndex.Value Is String AndAlso oIndex.Value = String.Empty Then + ' LOGGER.Warn("Value for Index [{0}] was empty. Skipping.", oIndex.Key) + ' Continue For + + ' End If + + ' Dim oIndexingSuccessful = WriteIndex2File(oRow.Item(oIndex.Key), oIndex.Value) + + ' If oIndexingSuccessful = False Then + ' MsgBox($"Error while Indexing Email at Index [{oIndex.Key}]", MsgBoxStyle.Critical) + ' Return False + + ' End If + ' Catch ex As Exception + ' LOGGER.Warn("Error while Indexing Email at Index [{0}]", oIndex.Key) + ' LOGGER.Error(ex) + ' Return False + ' End Try + ' Next + + ' Return True + ' Catch ex As Exception + ' LOGGER.Error(ex) + ' Return False + ' End Try + 'End Function + Private Function SetEmailIndicies(pIndexAttachment As Boolean) As Boolean Try Dim oIndexNames As Dictionary(Of String, Object) @@ -1336,51 +1603,50 @@ Public Class frmIndex Dim oTable As DataTable = DATABASE_ECM.GetDatatable(oSQL) If IsNothing(oTable) Then - _Logger.Info("Could not get Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) + LOGGER.Error("Database returned NULL for Email Indicies query (OBJECTTYPE = [{0}]).", CURR_DOKART_OBJECTTYPE) Return False End If If oTable.Rows.Count = 0 Then - LOGGER.Warn("Could not get Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) - MsgBox($"Definition von Email Indizes für den Objekttyp [{oTable}] fehlt." + vbNewLine + "Bitte informieren Sie Ihren Systembetreuer.", MsgBoxStyle.Critical) + LOGGER.Warn("No Email Indicies defined for OBJECTTYPE = [{0}].", CURR_DOKART_OBJECTTYPE) + MsgBox($"Definition von Email Indizes für den Objekttyp [{CURR_DOKART_OBJECTTYPE}] fehlt." + vbNewLine + "Bitte informieren Sie Ihren Systembetreuer.", MsgBoxStyle.Critical) Return False End If If oTable.Rows.Count > 1 Then - LOGGER.Warn("Got multiple rows for Email Indicies for OBJECTTYPE = [{0}]. Exiting.", CURR_DOKART_OBJECTTYPE) + LOGGER.Warn("Multiple Email Indicies definitions found for OBJECTTYPE = [{0}]. Using none and exiting.", CURR_DOKART_OBJECTTYPE) Return False End If Dim oRow As DataRow = oTable.Rows.Item(0) - ' If file is an email files (eml,msg) parse it to extract email data and save for later - ' If file is an attachment, rely on the previously extracted value - - - If pIndexAttachment = False Then - LOGGER.Debug("Indexing Email File: [{0}]", CURRENT_NEWFILENAME) - - ' This cannot use Path.Combine, otherwise the WINDREAM_BASEPATH will be swallowed... lol - 'Dim oMsgFilePath As String = Path.Combine(WINDREAM_BASEPATH, CURRENT_NEWFILENAME) + LOGGER.Info("Indexing main Email file for OBJECTTYPE = [{0}].", CURR_DOKART_OBJECTTYPE) + LOGGER.Debug("Original filename: [{0}]", CURRENT_NEWFILENAME) Dim oMsgFilePath As String = CURRENT_NEWFILENAME If CURRENT_NEWFILENAME.StartsWith(WINDREAM_BASEPATH) = False Then oMsgFilePath = WINDREAM_BASEPATH & oMsgFilePath End If + LOGGER.Debug("Email file path: [{0}]", oMsgFilePath) + Dim oMail As IMail = EMAIL.Load_Email(oMsgFilePath) + LOGGER.Debug($"Load Email from path: {oMail}") Dim oMessageId As String = oMail.MessageID - LOGGER.Debug("MessageId: [{0}]", oMessageId) - + LOGGER.Debug($"MessageId: {oMessageId}") Dim oMessageFrom As String = EMAIL.Get_MessageSender(oMail) + LOGGER.Debug($"MessageForm: {oMessageFrom}") Dim oMessageTo As String = EMAIL.Get_MessageReceiver(oMail) - LOGGER.Debug("oMessageTo: [{0}]", oMessageTo.ToString) + LOGGER.Debug($"Receiver: {oMessageTo}") Dim oDateIn As Date = EMAIL.Get_MessageDate(oMail) - LOGGER.Debug("oDateIn: [{0}]", oDateIn.ToString) + LOGGER.Debug($"Date: {oDateIn}") Dim oSubject As String = oMail.Subject - LOGGER.Debug("oSubject: [{0}]", oSubject) + LOGGER.Debug($"Subject: {oSubject}") + + LOGGER.Debug("Extracted Email fields → ID=[{0}], From=[{1}], To=[{2}], Date=[{3}], Subject=[{4}]", + oMessageId, oMessageFrom, oMessageTo, oDateIn, oSubject) CURRENT_MESSAGEID = oMessageId CURRENT_MESSAGEDATE = oDateIn @@ -1389,61 +1655,63 @@ Public Class frmIndex CURRENT_MESSAGESUBJECT = oSubject Else CURRENT_MESSAGESUBJECT = "" - LOGGER.Info("No subject - Default will be used!") + LOGGER.Info("Email has no subject. Using default ''.") End If oIndexNames = New Dictionary(Of String, Object) From { - {"IDX_EMAIL_ID", oMessageId}, - {"IDX_EMAIL_FROM", oMessageFrom}, - {"IDX_EMAIL_TO", oMessageTo}, - {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, - {"IDX_EMAIL_DATE_IN", oDateIn} - } + {"IDX_EMAIL_ID", oMessageId}, + {"IDX_EMAIL_FROM", oMessageFrom}, + {"IDX_EMAIL_TO", oMessageTo}, + {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, + {"IDX_EMAIL_DATE_IN", oDateIn} + } Else + LOGGER.Info("Indexing Email attachment for OBJECTTYPE = [{0}].", CURR_DOKART_OBJECTTYPE) + oIndexNames = New Dictionary(Of String, Object) From { - {"IDX_EMAIL_ID", CURRENT_MESSAGEID}, - {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, - {"IDX_EMAIL_DATE_IN", CURRENT_MESSAGEDATE}, - {"IDX_CHECK_ATTACHMENT", True} - } + {"IDX_EMAIL_ID", CURRENT_MESSAGEID}, + {"IDX_EMAIL_SUBJECT", CURRENT_MESSAGESUBJECT}, + {"IDX_EMAIL_DATE_IN", CURRENT_MESSAGEDATE}, + {"IDX_CHECK_ATTACHMENT", True} + } End If - For Each oIndex In oIndexNames Try If oIndex.Value Is Nothing Then - LOGGER.Warn("Value for Index [{0}] was empty. Skipping.", oIndex.Key) + LOGGER.Warn("Skipping Index [{0}] because value was NULL.", oIndex.Key) Continue For - End If If TypeOf oIndex.Value Is String AndAlso oIndex.Value = String.Empty Then - LOGGER.Warn("Value for Index [{0}] was empty. Skipping.", oIndex.Key) + LOGGER.Warn("Skipping Index [{0}] because value was empty.", oIndex.Key) Continue For - End If Dim oIndexingSuccessful = WriteIndex2File(oRow.Item(oIndex.Key), oIndex.Value) If oIndexingSuccessful = False Then + LOGGER.Error("Indexing failed at Index [{0}] with value [{1}].", oIndex.Key, oIndex.Value) MsgBox($"Error while Indexing Email at Index [{oIndex.Key}]", MsgBoxStyle.Critical) Return False - End If + + LOGGER.Debug("Index [{0}] successfully written with value [{1}].", oIndex.Key, oIndex.Value) Catch ex As Exception - LOGGER.Warn("Error while Indexing Email at Index [{0}]", oIndex.Key) - LOGGER.Error(ex) + LOGGER.Error(ex, "Exception while indexing Email at Index [{0}].", oIndex.Key) Return False End Try Next + LOGGER.Info("Successfully indexed Email (OBJECTTYPE = [{0}]).", CURR_DOKART_OBJECTTYPE) Return True Catch ex As Exception - LOGGER.Error(ex) + LOGGER.Error(ex, "Unexpected exception in SetEmailIndicies.") Return False End Try End Function + 'Private Function SetEmailIndicesOld() ' Dim indexierung_erfolgreich As Boolean = False ' Dim _step As String = "1"