MS Changes Firebird due to wisag
This commit is contained in:
591
App/DigitalData.EMLProfiler/clsWorkEmail.vb
Normal file
591
App/DigitalData.EMLProfiler/clsWorkEmail.vb
Normal file
@@ -0,0 +1,591 @@
|
||||
Imports Independentsoft.Email.Mime
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports WINDREAMLib
|
||||
Imports DigitalData.EMLProfiler.ClassCurrent
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Database
|
||||
Public Class clsWorkEmail
|
||||
Private Shared Logger As Logger
|
||||
Private _email As clsEmail
|
||||
Private _Database As clsDatabase
|
||||
Private _windream As clsWindream_allgemein
|
||||
Private _windream_index As clsWindream_Index
|
||||
Private _firebird As Firebird
|
||||
Private _worked_email As Boolean = False
|
||||
Sub New(LogConf As LogConfig, ConStr As String, FB_DATASOURCE As String, FB_DATABASE As String, FB_USER As String, FB_PW As String)
|
||||
Logger = LogConf.GetLogger
|
||||
_email = New clsEmail(LogConf)
|
||||
_Database = New clsDatabase(LogConf, ConStr)
|
||||
_windream = New clsWindream_allgemein(LogConf)
|
||||
_windream_index = New clsWindream_Index(LogConf)
|
||||
_firebird = New Firebird(LogConf, FB_DATASOURCE, FB_DATABASE, FB_USER, FB_PW)
|
||||
End Sub
|
||||
Public Function WORK_MAIL(msg As Message)
|
||||
Try
|
||||
CURRENT_MAIL_BODY = ""
|
||||
CURRENT_MAIL_BODY_Substr1 = ""
|
||||
CURRENT_MAIL_BODY_Substr2 = ""
|
||||
CURRENT_MAIL_MESSAGE = msg
|
||||
CURRENT_MAIL_SUBJECT = msg.Subject.ToUpper
|
||||
If IsNothing(CURRENT_MAIL_SUBJECT) Then
|
||||
CURRENT_MAIL_SUBJECT = ""
|
||||
End If
|
||||
SAVE2TEMP()
|
||||
|
||||
If CURRENT_MAIL_SUBJECT.Contains("[PROCESSMANAGER]") Then
|
||||
PROCESS_MANAGER_IN()
|
||||
ElseIf msg.Subject.Contains("[ADDI]") Then
|
||||
|
||||
Else
|
||||
Logger.Debug(String.Format("No relation configured for this email - Subject[{0}]", msg.Subject))
|
||||
COMMON_EMAIL_IN
|
||||
|
||||
|
||||
End If
|
||||
INSERT_HISTORY
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in WORK_MAIL: " & ex.Message & "MESSAGE_ID: " & msg.MessageID)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function PROCESS_MANAGER_IN() As Boolean
|
||||
Try
|
||||
Dim oDel_email As Boolean = False
|
||||
Logger.Info(String.Format("PM-related message found....[{0}]", CURRENT_MAIL_MESSAGE.Subject))
|
||||
Logger.Debug(String.Format("PM-related message found....[{0}]", CURRENT_MAIL_MESSAGE.Subject))
|
||||
Dim oExpression = "PROCESS_NAME = 'ProcessManager'"
|
||||
'Filter the rows using Select() method of DataTable
|
||||
Dim TEMP_PROCESS_PROFILE_DT As DataTable = DT_POLL_PROCESS
|
||||
Dim PM_ROW As DataRow() = TEMP_PROCESS_PROFILE_DT.Select(oExpression)
|
||||
For Each row As DataRow In PM_ROW
|
||||
WM_REFERENCE_INDEX = row("WM_REFERENCE_INDEX")
|
||||
WM_VECTOR_LOG = row("WM_VECTOR_LOG")
|
||||
WM_OBJEKTTYPE = row("WM_OBJEKTTYPE")
|
||||
WM_IDX_BODY_TEXT = row("WM_IDX_BODY_TEXT")
|
||||
WM_IDX_BODY_SUBSTR_LENGTH = row("WM_IDX_BODY_SUBSTR_LENGTH")
|
||||
|
||||
COPY2HDD(row("COPY_2_HDD"), row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"), False)
|
||||
EXTRACT_BODY()
|
||||
oDel_email = row("DELETE_MAIL")
|
||||
Next
|
||||
|
||||
If CURRENT_MAIL_SUBJECT.Contains("[PROCESSMANAGER][EA]") Then
|
||||
Logger.Info(String.Format("Message referencing to EASY-APPROVAL...."))
|
||||
Logger.Debug(String.Format("Message referencing to EASY-APPROVAL...."))
|
||||
CURRENT_MAIL_PROCESS_NAME = "DD EasyApproval via Mail"
|
||||
|
||||
If CURRENT_MAIL_BODY_Substr1 <> "" Then
|
||||
MessageError = False
|
||||
If GET_DOC_INFO() = True Then
|
||||
If DT_STEPS.Rows.Count > 0 Then
|
||||
WORK_POLL_STEPS()
|
||||
Else
|
||||
Logger.Info("No steps configured for this Profile ....")
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
EMAIL_DELETE(oDel_email)
|
||||
End If
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'Logger.Debug("Unexpected Error in PROCESS_MANAGER_IN: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Function COMMON_EMAIL_IN()
|
||||
Try
|
||||
Dim oDel_email As Boolean = False
|
||||
Logger.Info(String.Format("COMMON_EMAIL_IN...Subject [{0}]", CURRENT_MAIL_MESSAGE.Subject))
|
||||
Logger.Debug(String.Format("COMMON_EMAIL_IN...Subject [{0}]", CURRENT_MAIL_MESSAGE.Subject))
|
||||
Dim oExpression = "PROCESS_NAME = 'Attachment Sniffer'"
|
||||
CURRENT_MAIL_PROCESS_NAME = "Attachment Sniffer"
|
||||
'Filter the rows using Select() method of DataTable
|
||||
Dim TEMP_PROCESS_PROFILE_DT As DataTable = DT_POLL_PROCESS
|
||||
Dim PM_ROW As DataRow() = TEMP_PROCESS_PROFILE_DT.Select(oExpression)
|
||||
For Each row As DataRow In PM_ROW
|
||||
Try
|
||||
WM_REFERENCE_INDEX = row("WM_REFERENCE_INDEX")
|
||||
Catch ex As Exception
|
||||
WM_REFERENCE_INDEX = Nothing
|
||||
End Try
|
||||
Try
|
||||
WM_VECTOR_LOG = row("WM_VECTOR_LOG")
|
||||
Catch ex As Exception
|
||||
WM_VECTOR_LOG = Nothing
|
||||
End Try
|
||||
|
||||
WM_OBJEKTTYPE = row("WM_OBJEKTTYPE")
|
||||
WM_IDX_BODY_TEXT = row("WM_IDX_BODY_TEXT")
|
||||
WM_IDX_BODY_SUBSTR_LENGTH = row("WM_IDX_BODY_SUBSTR_LENGTH")
|
||||
|
||||
COPY2HDD(row("COPY_2_HDD"), row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"), True)
|
||||
EXTRACT_BODY()
|
||||
EXTRACT_ATTACHMENTS(row("PATH_EMAIL_TEMP"), row("PATH_EMAIL_ERRORS"))
|
||||
oDel_email = row("DELETE_MAIL")
|
||||
Next
|
||||
EMAIL_DELETE(oDel_email)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'Logger.Debug("Unexpected Error in PROCESS_MANAGER_IN: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function SAVE2TEMP()
|
||||
Try
|
||||
Dim oTempFilename As String = Path.Combine(Path.GetTempPath, CURRENT_MAIL_MESSAGE.GetFileName)
|
||||
|
||||
If File.Exists(oTempFilename) = True Then
|
||||
File.Delete(oTempFilename)
|
||||
End If
|
||||
CURRENT_MAIL_MESSAGE.Save(oTempFilename, True)
|
||||
CURRENT_TEMP_MAIL_PATH = oTempFilename
|
||||
'Datei in Array zum Templöschen speichern
|
||||
TEMP_FILES.Add(oTempFilename)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
CURRENT_TEMP_MAIL_PATH = Nothing
|
||||
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function COPY2HDD(copy_2_hdd As Boolean, pathemailtemp As String, pathemail_errors As String, messageid As Boolean)
|
||||
Try
|
||||
If copy_2_hdd = True Then
|
||||
Logger.Debug("COPY_2_HDD is ACTIVE!")
|
||||
PATH_TEMP = pathemailtemp
|
||||
PATH_ERROR = pathemail_errors
|
||||
If Directory.Exists(PATH_TEMP) Then
|
||||
Dim oTempFilename = PATH_TEMP
|
||||
If messageid = True Then
|
||||
oTempFilename &= "\" & CURRENT_MAIL_MESSAGE.MessageID & ".eml"
|
||||
Else
|
||||
oTempFilename &= "\" & CURRENT_MAIL_MESSAGE.GetFileName
|
||||
End If
|
||||
|
||||
Dim cleanPath As String = String.Join("", oTempFilename.Split(Path.GetInvalidPathChars()))
|
||||
If System.IO.File.Exists(cleanPath) = False Then
|
||||
CURRENT_MAIL_MESSAGE.Save(cleanPath, True)
|
||||
Else
|
||||
Logger.Info("EMail (" & CURRENT_MAIL_MESSAGE.Subject & ") already existing!", False, "RUN_THREAD.COPY_2_HDD")
|
||||
End If
|
||||
End If
|
||||
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function EXTRACT_BODY()
|
||||
Dim oDTFunctionRegex As DataTable = _Database.Return_Datatable("SELECT * FROM TBDD_FUNCTION_REGEX WHERE FUNCTION_NAME = 'EMAIL_PROFILER - BODY REMOVE NewLine'")
|
||||
If CURRENT_TEMP_MAIL_PATH <> Nothing Then
|
||||
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
|
||||
Dim msg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
|
||||
If IsNothing(msg_email.Body) Then
|
||||
Dim oAllBodyParts As New BodyPartCollection()
|
||||
oAllBodyParts.Add(msg_email.BodyParts)
|
||||
oAllBodyParts.Add(GetChildren(msg_email.BodyParts))
|
||||
|
||||
For Each bodyPart As BodyPart In oAllBodyParts
|
||||
If bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "plain" Then
|
||||
Logger.Debug(String.Format("BODY1-Text is....#{0}", bodyPart.Body))
|
||||
If CURRENT_MAIL_BODY <> bodyPart.Body Then
|
||||
CURRENT_MAIL_BODY = bodyPart.Body
|
||||
End If
|
||||
|
||||
ElseIf bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "html" Then
|
||||
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
|
||||
If CURRENT_MAIL_BODY = "" Then
|
||||
CURRENT_MAIL_BODY = bodyPart.Body
|
||||
Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
|
||||
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
CURRENT_MAIL_BODY = msg_email.Body
|
||||
End If
|
||||
Else
|
||||
Logger.Warn($"If cause 2: {CURRENT_TEMP_MAIL_PATH} not existing")
|
||||
End If
|
||||
Else
|
||||
Logger.Warn($"EXTRACT_BODY If cause 1: CURRENT_TEMP_MAIL_PATH is NOTHING")
|
||||
End If
|
||||
Try
|
||||
'Dim oAllBodyParts As New BodyPartCollection()
|
||||
'oAllBodyParts.Add(CURRENT_MAIL_MESSAGE.BodyParts)
|
||||
'oAllBodyParts.Add(GetChildren(CURRENT_MAIL_MESSAGE.BodyParts))
|
||||
|
||||
'For Each bodyPart As BodyPart In oAllBodyParts
|
||||
' If bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "plain" Then
|
||||
' Logger.Debug(String.Format("BODY1-Text is....#{0}", bodyPart.Body))
|
||||
' CURRENT_MAIL_BODY = bodyPart.Body
|
||||
' ElseIf bodyPart.ContentType IsNot Nothing AndAlso bodyPart.ContentType.Type = "text" AndAlso bodyPart.ContentType.SubType = "html" Then
|
||||
' Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
|
||||
' If CURRENT_MAIL_BODY = "" Then
|
||||
' CURRENT_MAIL_BODY = bodyPart.Body
|
||||
' Logger.Debug(String.Format("bodyhtml....#{0}", bodyPart.Body))
|
||||
|
||||
' End If
|
||||
' End If
|
||||
'Next
|
||||
CURRENT_MAIL_BODY = Trim(CURRENT_MAIL_BODY)
|
||||
If CURRENT_MAIL_BODY = String.Empty Then
|
||||
Logger.Warn("Mailbody is empty. Email can not be processed! - Please check the html-structure")
|
||||
Logger.Info("EXCEPTION - Mailbody is empty.Email can not be processed! - Please check the html-structure")
|
||||
MessageError = True
|
||||
Return False
|
||||
End If
|
||||
Dim oFirstindex = CURRENT_MAIL_BODY.IndexOf(Chr(13))
|
||||
If IsNothing(oFirstindex) Then
|
||||
oFirstindex = CURRENT_MAIL_BODY.IndexOf(Chr(10))
|
||||
End If
|
||||
Logger.Debug(String.Format("firstindex....[{0}]", oFirstindex))
|
||||
Try
|
||||
CURRENT_MAIL_BODY_Substr1 = CURRENT_MAIL_BODY.Substring(0, oFirstindex)
|
||||
CURRENT_MAIL_BODY_Substr1 = RTrim(LTrim(CURRENT_MAIL_BODY_Substr1))
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error in Substring 144: " & ex.Message)
|
||||
Logger.Warn("CURRENT_MAIL_BODY: " & CURRENT_MAIL_BODY)
|
||||
Logger.Warn("oFirstindex: " & oFirstindex)
|
||||
CURRENT_MAIL_BODY_Substr1 = ""
|
||||
End Try
|
||||
|
||||
|
||||
Logger.Debug(String.Format("MailBody-Substring:...[{0}]", CURRENT_MAIL_BODY_Substr1))
|
||||
'now trying to get the text before Masterline
|
||||
If WM_IDX_BODY_TEXT <> String.Empty And WM_IDX_BODY_SUBSTR_LENGTH <> 0 And oDTFunctionRegex.Rows.Count = 1 Then
|
||||
Dim pattern As String = oDTFunctionRegex.Rows(0).Item("REGEX")
|
||||
|
||||
' Instantiate the regular expression object.
|
||||
Dim r As Regex = New Regex(pattern, RegexOptions.Multiline)
|
||||
|
||||
' Match the regular expression pattern against a text string.
|
||||
Dim m As Match = r.Match(CURRENT_MAIL_BODY)
|
||||
If m.Success Then
|
||||
If Not IsNothing(m.Value) Then
|
||||
If m.Value.Length > WM_IDX_BODY_SUBSTR_LENGTH Then
|
||||
Try
|
||||
Logger.Info($"Getting the Substring of body - Length: {WM_IDX_BODY_SUBSTR_LENGTH}...")
|
||||
CURRENT_MAIL_BODY_Substr2 = m.Value.Substring(0, WM_IDX_BODY_SUBSTR_LENGTH)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Error in Substring 168: " & ex.Message)
|
||||
Logger.Warn("m.Value: " & m.Value)
|
||||
Logger.Warn("WM_IDX_BODY_SUBSTR_LENGTH: " & WM_IDX_BODY_SUBSTR_LENGTH.ToString)
|
||||
CURRENT_MAIL_BODY_Substr2 = ""
|
||||
End Try
|
||||
|
||||
Else
|
||||
Logger.Info($"m.Value.Length < WM_IDX_BODY_SUBSTR_LENGTH, so simply m.Value will be taken...")
|
||||
CURRENT_MAIL_BODY_Substr2 = m.Value
|
||||
End If
|
||||
|
||||
End If
|
||||
End If
|
||||
'Dim matchcount As Integer = 0
|
||||
'Do While m.Success
|
||||
' matchcount += 1
|
||||
' Console.WriteLine("Match" & (matchcount))
|
||||
' Dim i As Integer
|
||||
' For i = 1 To 2
|
||||
' Dim g As Group = m.Groups(i)
|
||||
' Console.WriteLine("Group" & i & "='" & g.ToString() & "'")
|
||||
' Dim cc As CaptureCollection = g.Captures
|
||||
' Dim j As Integer
|
||||
' For j = 0 To cc.Count - 1
|
||||
' Dim c As Capture = cc(j)
|
||||
' Console.WriteLine("Capture" & j & "='" & c.ToString() _
|
||||
' & "', Position=" & c.Index)
|
||||
' Next
|
||||
' Next
|
||||
' m = m.NextMatch()
|
||||
'Loop
|
||||
|
||||
|
||||
Logger.Info(String.Format("MailBody-Substring After RecognizeString:...[{0}]", CURRENT_MAIL_BODY_Substr2))
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
MessageError = True
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function EXTRACT_ATTACHMENTS(pathemailtemp As String, pathemail_errors As String)
|
||||
PATH_TEMP = pathemailtemp
|
||||
PATH_ERROR = pathemail_errors
|
||||
Try
|
||||
If CURRENT_TEMP_MAIL_PATH <> Nothing Then
|
||||
If File.Exists(CURRENT_TEMP_MAIL_PATH) Then
|
||||
Dim msg_email As New Independentsoft.Email.Mime.Message(CURRENT_TEMP_MAIL_PATH)
|
||||
For Each attachment As Attachment In msg_email.GetAttachments
|
||||
If Path.GetExtension(attachment.GetFileName).ToUpper.Contains("PDF") Then
|
||||
Dim sGUID = System.Guid.NewGuid.ToString()
|
||||
Dim oAttachmentFilename
|
||||
Try
|
||||
oAttachmentFilename = Path.Combine(PATH_TEMP, $"{sGUID}{Path.GetExtension(attachment.GetFileName)}")
|
||||
If System.IO.File.Exists(oAttachmentFilename) = False Then
|
||||
attachment.Save(oAttachmentFilename)
|
||||
INSERT_HISTORY_FB(sGUID, attachment.GetFileName)
|
||||
Else
|
||||
Logger.Info("Attachment (" & oAttachmentFilename & ") already existing!", False, "EXTRACT_ATTACHMENTS")
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Warn($"Error while creating and saving attachment-name: {ex.Message} - AttachmentName: {oAttachmentFilename}")
|
||||
MessageError = True
|
||||
Return False
|
||||
End Try
|
||||
End If
|
||||
|
||||
|
||||
Next
|
||||
Else
|
||||
Logger.Warn($"If cause 2 EXTRACT_ATTACHMENTS: {CURRENT_TEMP_MAIL_PATH} not existing")
|
||||
End If
|
||||
Else
|
||||
Logger.Warn($"EXTRACT_ATTACHMENTSIf cause 1: CURRENT_TEMP_MAIL_PATH is NOTHING")
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in COPY2HDD: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
MessageError = True
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function INSERT_HISTORY()
|
||||
If MessageError = False Then
|
||||
Dim ins = $"INSERT INTO TBEMLP_HISTORY (WORK_PROCESS,EMAIL_MSGID,EMAIL_SUBJECT,EMAIL_DATE,EMAIL_BODY,EMAIL_SUBSTRING1,EMAIL_SUBSTRING2) VALUES " &
|
||||
$"('{CURRENT_MAIL_PROCESS_NAME}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.MessageID.Replace("<", "").Replace(">", "")}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Subject}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
|
||||
$"'{CURRENT_MAIL_BODY}'," &
|
||||
$"'{CURRENT_MAIL_BODY_Substr1}'," &
|
||||
$"'{CURRENT_MAIL_BODY_Substr2}')"
|
||||
_Database.Execute_non_Query(ins)
|
||||
|
||||
End If
|
||||
End Function
|
||||
Private Function INSERT_HISTORY_FB(oGUID As String, ATTMT1 As String)
|
||||
If MessageError = False Then
|
||||
Dim ins = $"INSERT INTO TBEDM_EMAIL_PROFILER_HISTORY (WORK_PROCESS,EMAIL_MSGID,EMAIL_FROM,EMAIL_SUBJECT,EMAIL_DATETIME,EMAIL_BODY,EMAIL_SUBSTRING1,EMAIL_SUBSTRING2,EMAIL_ATTMT1) VALUES " &
|
||||
$"('{CURRENT_MAIL_PROCESS_NAME}'," &
|
||||
$"'{oGUID}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.From.EmailAddress}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Subject}'," &
|
||||
$"'{CURRENT_MAIL_MESSAGE.Date}'," &
|
||||
$"'{CURRENT_MAIL_BODY}'," &
|
||||
$"'{CURRENT_MAIL_BODY_Substr1}'," &
|
||||
$"'{CURRENT_MAIL_BODY_Substr2}'," &
|
||||
$"'{ATTMT1}')"
|
||||
_firebird.ExecuteNonQuery(ins)
|
||||
End If
|
||||
End Function
|
||||
Private Function GetChildren(ByVal bodyParts As BodyPartCollection) As BodyPartCollection
|
||||
|
||||
Dim children As New BodyPartCollection()
|
||||
|
||||
For i As Integer = 0 To bodyParts.Count - 1
|
||||
children.Add(GetChildren(bodyParts(i).BodyParts))
|
||||
children.Add(bodyParts(i))
|
||||
Next
|
||||
|
||||
Return children
|
||||
End Function
|
||||
Private Function EMAIL_DELETE(del As Boolean)
|
||||
If del = True And MessageError = False And _worked_email = True Then
|
||||
_email.DELETE_EMAIL(CURRENT_MAIL_MESSAGE.MessageID)
|
||||
End If
|
||||
End Function
|
||||
Private Function WORK_POLL_STEPS() As Boolean
|
||||
Try
|
||||
_worked_email = False
|
||||
For Each row As DataRow In DT_STEPS.Rows
|
||||
POLL_STEP_GUID = row.Item("GUID")
|
||||
POLL_STEP_PROCESS_ID = row.Item("PROCESS_ID")
|
||||
POLL_KEYWORDS = row.Item("KEYWORDS_BODY")
|
||||
KEYWORDS_SPLIT = POLL_KEYWORDS.Split(";")
|
||||
|
||||
For Each str As String In KEYWORDS_SPLIT
|
||||
If CURRENT_MAIL_BODY_Substr1.ToUpper = str.ToUpper Then
|
||||
_worked_email = True
|
||||
Logger.Info(String.Format("Found Keyword '{0}' in MessageBody", str))
|
||||
Dim sql As String = String.Format("SELECT * FROM TBEMLP_POLL_INDEXING_STEPS WHERE STEP_ID = {0} AND ACTIVE = 1", POLL_STEP_GUID)
|
||||
DT_INDEXING_STEPS = _Database.Return_Datatable(sql)
|
||||
If DT_INDEXING_STEPS.Rows.Count > 0 Then
|
||||
WORK_INDEXING_STEPS()
|
||||
Else
|
||||
Logger.Info("No Indexing Steps found?! - SQL: " & sql)
|
||||
End If
|
||||
|
||||
End If
|
||||
Next
|
||||
|
||||
Next
|
||||
If _worked_email = False Then
|
||||
Dim sql As String = String.Format("SELECT * FROM TBEMLP_POLL_INDEXING_STEPS WHERE STEP_ID = {0} AND ACTIVE = 1 AND USE_FOR_DIRECT_ANSWER = 1", POLL_STEP_GUID)
|
||||
DT_INDEXING_STEPS = _Database.Return_Datatable(sql)
|
||||
WORK_INDEXING_STEPS()
|
||||
_worked_email = True
|
||||
End If
|
||||
|
||||
'Now indexing the LogIndex
|
||||
If Not IsNothing(WM_VECTOR_LOG) And (Not IsDBNull(WM_VECTOR_LOG)) And (WM_VECTOR_LOG <> "") Then
|
||||
Dim msg = Now.ToString & " - " & CURRENT_MAIL_PROCESS_NAME
|
||||
IndexFile(WM_VECTOR_LOG, msg, False)
|
||||
End If
|
||||
'Now indexing the Body-Message Index
|
||||
If CURRENT_MAIL_BODY_Substr2 <> String.Empty And WM_IDX_BODY_TEXT <> String.Empty Then
|
||||
IndexFile(WM_IDX_BODY_TEXT, CURRENT_MAIL_BODY_Substr2, True)
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
MessageError = True
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in WORK_POLL_STEPS: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function WORK_INDEXING_STEPS()
|
||||
Try
|
||||
|
||||
For Each row As DataRow In DT_INDEXING_STEPS.Rows
|
||||
Dim INDEXNAME As String = row.Item("INDEXNAME")
|
||||
Dim INDEXVALUE As String = row.Item("INDEXVALUE")
|
||||
IndexFile(INDEXNAME, INDEXVALUE, False)
|
||||
Next
|
||||
|
||||
|
||||
|
||||
Catch ex As Exception
|
||||
MessageError = True
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in WORK_INDEXING_STEPS: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID, True)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Private Function IndexFile(oidxname As String, oidxvalue As String, oConcat_act_Value As Boolean)
|
||||
|
||||
Dim OArrIndex() As String
|
||||
ReDim Preserve OArrIndex(0)
|
||||
OArrIndex(0) = oidxname
|
||||
|
||||
If oConcat_act_Value = True Then
|
||||
Dim oActValue = _windream_index.GetValueforIndex_WMFile(CURRENT_WM_DOC, oidxname)
|
||||
If Not IsNothing(oActValue) Then
|
||||
If oActValue.ToString.Length > 0 Then
|
||||
If oActValue <> oidxvalue Then
|
||||
oidxvalue = oActValue & vbNewLine & oidxvalue
|
||||
End If
|
||||
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Dim oArrValue() As String
|
||||
Dim oMyArray()
|
||||
ReDim oMyArray(0)
|
||||
oMyArray(0) = oidxvalue
|
||||
|
||||
Dim oVektorArray()
|
||||
oVektorArray = _windream_index.GetVektorArray(CURRENT_WM_DOC, oidxname, oMyArray, True)
|
||||
|
||||
If oVektorArray Is Nothing = False Then
|
||||
'Zielindex ist ein Vektorindex
|
||||
ReDim oArrValue(oVektorArray.Length - 1)
|
||||
Array.Copy(oVektorArray, oArrValue, oVektorArray.Length)
|
||||
If oArrValue Is Nothing Then
|
||||
Logger.Warn($"arrValue from vektor for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
|
||||
Logger.Info($"arrValue from vektor for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
|
||||
Return False
|
||||
End If
|
||||
Else
|
||||
'Es handelt sich um einen Einfachindex
|
||||
ReDim oArrValue(0)
|
||||
oArrValue(0) = oidxvalue
|
||||
End If
|
||||
|
||||
If oArrValue Is Nothing = False Then
|
||||
Return _windream_index.RunIndexing(CURRENT_WM_DOC, OArrIndex, oArrValue, WM_OBJEKTTYPE)
|
||||
Else
|
||||
Logger.Warn($"arrValue for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
|
||||
Logger.Info($"arrValue for index {oidxname} is nothing! Value: {oidxvalue} - no indexing!")
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function GET_DOC_INFO()
|
||||
Try
|
||||
Dim DOC_ID = REGEX_CHECK_DOC_ID(CURRENT_MAIL_SUBJECT)
|
||||
If Not IsNothing(DOC_ID) Then
|
||||
Dim DT_BASE_ATTR As DataTable = _Database.Return_DatatableCS("SELECT * FROM BaseAttributes WHERE dwDocID = " & DOC_ID, WM_CON_STRING)
|
||||
If Not IsNothing(DT_BASE_ATTR) Then
|
||||
If DT_BASE_ATTR.Rows.Count = 1 Then
|
||||
CURRENT_DOC_ID = DOC_ID
|
||||
Dim sql = String.Format("Select[dbo].[FNDD_GET_WINDREAM_FILE_PATH]({0},'{1}')", CURRENT_DOC_ID, WM_DRIVE)
|
||||
CURRENT_DOC_PATH = _Database.Execute_Scalar(sql)
|
||||
Logger.Debug("CURRENT_DOC_PATH: " & CURRENT_DOC_PATH)
|
||||
CURRENT_WM_DOC = Nothing
|
||||
Dim WMDOC As WMObject
|
||||
Try
|
||||
WMDOC = _windream.oSession.GetWMObjectByPath(WMEntity.WMEntityDocument, CURRENT_DOC_PATH.Substring(2))
|
||||
CURRENT_WM_DOC = WMDOC
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Warn("error while creating WMObject in (GET_DOC_INFO): " & ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Else
|
||||
Logger.Warn("No record found for dwDocID " & DOC_ID)
|
||||
Return False
|
||||
|
||||
End If
|
||||
Else
|
||||
Logger.Warn("DT_BASE_ATTR is nothing")
|
||||
Return False
|
||||
End If
|
||||
Else
|
||||
Logger.Warn("Could not get a DOC-ID via regex!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
'clsLogger.Add("Unexpected Error in GET_DOC_INFO: " & ex.Message & "MESSAGE_ID: " & CURRENT_MAIL_MESSAGE.MessageID)
|
||||
MessageError = True
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Function REGEX_CHECK_DOC_ID(SearchString As String)
|
||||
Try
|
||||
Dim regex As Regex = New Regex("\[DID#{1}([0-9]+)]{1}")
|
||||
Logger.Debug("REGEX_String before replacing: '" & SearchString & "'")
|
||||
' Regulären Ausdruck zum Auslesen der windream-Indexe definieren
|
||||
Dim elements As MatchCollection = regex.Matches(SearchString)
|
||||
Dim result = ""
|
||||
For Each element As Match In elements
|
||||
result = element.Groups(1).Value
|
||||
Logger.Debug(String.Format("Found Regex(0) {0} in SearchString", element.Groups(0).Value))
|
||||
Logger.Debug(String.Format("Found Regex(1) {0} in SearchString", element.Groups(1).Value))
|
||||
Next
|
||||
Return result
|
||||
Catch ex As Exception
|
||||
MessageError = True
|
||||
Logger.Error(ex)
|
||||
'clsLogger.AddError("Unexpected error: " & ex.Message, "REGEX_CHECK_DOC_ID")
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user