MS Mail Handling und Manual Run
This commit is contained in:
parent
36e2d97b20
commit
48f9673472
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.9.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.9.0.0")>
|
||||
<Assembly: AssemblyVersion("3.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("3.0.0.0")>
|
||||
|
||||
@ -5,6 +5,7 @@ Imports Newtonsoft.Json
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Messaging
|
||||
Imports DigitalData.Modules.Messaging.Mail
|
||||
Imports DigitalData.Modules.Messaging.Mail.MailSession
|
||||
|
||||
Public Class clsProfil
|
||||
Inherits clsCURRENT
|
||||
@ -29,17 +30,17 @@ Public Class clsProfil
|
||||
_JobWork = New clsJob_Work(MyLogger, _email)
|
||||
|
||||
End Sub
|
||||
Public Function Init(PROFIL_ID As Integer)
|
||||
Public Function Init(PROFIL_ID As Integer, pManual As Boolean)
|
||||
Try
|
||||
Logger.Debug("Start Initialisierung Profil für GUID: " & PROFIL_ID.ToString)
|
||||
Dim DT As DataTable = _database.Return_Datatable("Select * from TBWMRH_PROFIL where GUID = " & PROFIL_ID)
|
||||
If DT.Rows.Count > 0 Then
|
||||
If DT.Rows.Count = 1 Then
|
||||
For Each DR As DataRow In DT.Rows
|
||||
_profGUID = PROFIL_ID
|
||||
_Profilname = CStr(DR.Item("Profilname"))
|
||||
Logger.Debug("Check Profilname '" & _Profilname & "', GUID: " & _profGUID & " geladen")
|
||||
' Überprüfen ob Profil aktiv oder inaktiv
|
||||
If CBool(DR.Item("Aktiv")) = False Then
|
||||
If CBool(DR.Item("Aktiv")) = False And pManual = False Then
|
||||
Logger.Info("## Profil '" & _Profilname & "' ist inaktiv geschaltet")
|
||||
Return False
|
||||
Else
|
||||
@ -64,23 +65,24 @@ Public Class clsProfil
|
||||
|
||||
End Function
|
||||
'Durchlauf des Profils wird aus dem Service gestartet wenn Init = True war
|
||||
Public Function Profil_Durchlauf(manually As Boolean) As Boolean
|
||||
Public Function Profil_Durchlauf(pManRun As Boolean) As Boolean
|
||||
Dim _error As Boolean = False
|
||||
Try
|
||||
Dim Run_Profile As Boolean = False
|
||||
Dim oRunProfile As Boolean = False
|
||||
If pManRun = False Then
|
||||
'Soll die Verarbeitung heute durchgeführt werden??
|
||||
Dim Dayofweek As Integer = My.Computer.Clock.LocalTime.DayOfWeek
|
||||
Dim SUBS As Integer = 0
|
||||
Dim RUNTODAY As Integer = 0
|
||||
If Dayofweek = 0 Then
|
||||
SUBS = 6
|
||||
Else
|
||||
|
||||
End If
|
||||
RUNTODAY = _profDay.Substring(Dayofweek - 1, 1)
|
||||
|
||||
|
||||
If _profDay.Substring(Dayofweek - 1, 1) = 1 Then
|
||||
oRunProfile = True
|
||||
Else
|
||||
Logger.Info("Verarbeitung für JETZT NICHT konfiguriert")
|
||||
End If
|
||||
'Verarbeitung soll heute durchgeführt werden
|
||||
Logger.Debug("Verarbeitung soll heute durchgeführt werden!")
|
||||
Logger.Debug("_RunType: " & _profRunType)
|
||||
@ -96,11 +98,11 @@ Public Class clsProfil
|
||||
Logger.Debug("_RunTime.ToShortTimeString: " & _RunTime.ToShortTimeString & " # " & "Now.ToShortTimeString: " & Now.ToShortTimeString)
|
||||
If Time_next.ToString.StartsWith("11.11.1911") Then
|
||||
Logger.Info("Manueller Durchlauf des Profils - 11.11.1911")
|
||||
Run_Profile = True
|
||||
oRunProfile = True
|
||||
Else
|
||||
'Ist die Uhrzeit in der Range
|
||||
If _RunTime.ToShortTimeString = Now.ToShortTimeString Then
|
||||
Run_Profile = True
|
||||
oRunProfile = True
|
||||
Else
|
||||
Logger.Debug("No run as " & _RunTime.ToShortTimeString & "<>" & Now.ToShortTimeString)
|
||||
End If
|
||||
@ -115,18 +117,20 @@ Public Class clsProfil
|
||||
|
||||
If DiffMin >= CInt(arr(1)) Then
|
||||
'Den Durchlauf erlauben
|
||||
Run_Profile = True
|
||||
oRunProfile = True
|
||||
Else
|
||||
Logger.Debug("No run as DiffMin (" & DiffMin & ") <= Intervall(" & arr(1) & ")")
|
||||
End If
|
||||
Case Else
|
||||
Logger.Warn("_profRunType konnte nicht ausgewertet werden - " & arr(0))
|
||||
End Select
|
||||
If Run_Profile = False And manually = True Then
|
||||
Logger.Info("This is a manual run of profile!")
|
||||
Run_Profile = True
|
||||
Else
|
||||
Logger.Info("### This is a manual run of profile! ###")
|
||||
oRunProfile = True
|
||||
End If
|
||||
If Run_Profile = True Then
|
||||
|
||||
|
||||
If oRunProfile = True Then
|
||||
Logger.Debug($"'{_Profilname}' - Run_Profile = True")
|
||||
clsCURRENT.DT_TBDD_EMAIL = _database.Return_Datatable("SELECT * FROM TBDD_EMAIL_ACCOUNT WHERE ACTIVE = 1")
|
||||
clsCURRENT.PROFILE_HandledFiles = Nothing
|
||||
@ -170,6 +174,15 @@ Public Class clsProfil
|
||||
Dim oCountDocs As Integer = 0
|
||||
Dim oEmailAttachment_path As String
|
||||
|
||||
|
||||
Dim MAILFROM As String = ""
|
||||
Dim MAILSMTP As String = ""
|
||||
Dim MAIL_USER As String = ""
|
||||
Dim MAIL_USER_PW As String = ""
|
||||
Dim MAIL_AUTH_TYPE As String = "SSL"
|
||||
Dim MAIL_PORT As String = "25"
|
||||
Dim MAILSession As SessionInfo
|
||||
|
||||
For Each WMdok As WMObject In windreamSucheErgebnisse
|
||||
|
||||
oEmailAttachment_path = String.Empty
|
||||
@ -215,14 +228,8 @@ Public Class clsProfil
|
||||
Return False
|
||||
End If
|
||||
|
||||
|
||||
Dim MAILFROM As String = ""
|
||||
Dim MAILSMTP As String = ""
|
||||
Dim MAIL_USER As String = ""
|
||||
Dim MAIL_USER_PW As String = ""
|
||||
Dim MAIL_AUTH_TYPE As String = "SSL"
|
||||
Dim MAIL_PORT As String = "25"
|
||||
|
||||
If oCountDocs = 1 Then
|
||||
Logger.Debug("##### EMAIL BASICS CONSTRUCT (oCountDocs = 1) ######")
|
||||
For Each emailrow As DataRow In clsCURRENT.DT_TBDD_EMAIL.Rows
|
||||
If emailrow.Item("GUID") = CInt(EMAIL_PROFIL) Then
|
||||
MAILFROM = emailrow.Item("EMAIL_FROM")
|
||||
@ -252,6 +259,8 @@ Public Class clsProfil
|
||||
Email_Empfänger = _dateiverarbeitung.REGEX_REPLACE(WMdok, Email_Empfänger)
|
||||
Logger.Debug("Email_Empfänger: " & Email_Empfänger)
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
oEmail_Betreff = _dateiverarbeitung.REGEX_REPLACE(WMdok, oEmail_Betreff)
|
||||
Email_Body = _dateiverarbeitung.REGEX_REPLACE(WMdok, Email_Body)
|
||||
@ -271,9 +280,10 @@ Public Class clsProfil
|
||||
clsCURRENT.TEMP_FILES.Add(oAttachment_FullFilename)
|
||||
End If
|
||||
Logger.Debug("Now _email and Messaging...")
|
||||
If Not IsNothing(_email) And _email.Connected2Server = False Then
|
||||
Dim oSession = _email.Connect(MAILSMTP, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTH_TYPE)
|
||||
If oSession.Connected = True Then
|
||||
If Not IsNothing(_email) And _email.Connected2Server = False And MAILSession.Connected = True Then
|
||||
Logger.Debug("Re/init MAILSession...")
|
||||
MAILSession = _email.Connect(MAILSMTP, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTH_TYPE)
|
||||
If MAILSession.Connected = True Then
|
||||
Logger.Info($"MAIL: Connection to {MAILSMTP} successfull!")
|
||||
Else
|
||||
Logger.Warn($"{oFileRunNo} Email_ConnectToServer was not successfull!")
|
||||
@ -285,6 +295,8 @@ Public Class clsProfil
|
||||
FileJobSuccessful = True
|
||||
Else
|
||||
FileJobSuccessful = False
|
||||
Logger.Debug("Setting MAILSession.Connected to [false]")
|
||||
MAILSession.Connected = False
|
||||
If IsNothing(_email) Then
|
||||
Logger.Info($"_email is nothing")
|
||||
Else
|
||||
@ -603,12 +615,12 @@ Public Class clsProfil
|
||||
Dim EMAIL_PROFIL = DR_PR_JB.Item("STRING4")
|
||||
Logger.Debug("EMAIL_PROFIL: " & EMAIL_PROFIL)
|
||||
If Not IsNothing(clsCURRENT.DT_TBDD_EMAIL) And clsCURRENT.DT_TBDD_EMAIL.Rows.Count >= 1 Then
|
||||
Dim MAILFROM As String = ""
|
||||
Dim MAILSMTP As String = ""
|
||||
Dim MAIL_USER As String = ""
|
||||
Dim MAIL_USER_PW As String = ""
|
||||
Dim MAIL_AUTH_TYPE As String = "SSL"
|
||||
Dim MAIL_PORT As Integer
|
||||
MAILFROM = ""
|
||||
MAILSMTP = ""
|
||||
MAIL_USER = ""
|
||||
MAIL_USER_PW = ""
|
||||
MAIL_AUTH_TYPE = "SSL"
|
||||
MAIL_PORT = 0
|
||||
|
||||
For Each emailrow As DataRow In clsCURRENT.DT_TBDD_EMAIL.Rows
|
||||
If emailrow.Item("GUID") = CInt(EMAIL_PROFIL) Then
|
||||
@ -647,18 +659,28 @@ Public Class clsProfil
|
||||
oAttMt.Add(clsCURRENT.CONCATTED_FILE)
|
||||
clsCURRENT.TEMP_FILES.Add(clsCURRENT.CONCATTED_FILE)
|
||||
End If
|
||||
If Not IsNothing(_email) And _email.Connected2Server = False And MAILSession.Connected = True Then
|
||||
Logger.Debug("Re/init MAILSession(2)...")
|
||||
MAILSession = _email.Connect(MAILSMTP, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTH_TYPE)
|
||||
If MAILSession.Connected = True Then
|
||||
Logger.Info($"MAIL: Connection to {MAILSMTP} successfull!")
|
||||
Else
|
||||
Logger.Warn($"{oFileRunNo} Email_ConnectToServer was not successfull!")
|
||||
FileJobSuccessful = False
|
||||
End If
|
||||
|
||||
Dim oSession = _email.Connect(MAILSMTP, MAIL_PORT, MAIL_USER, MAIL_USER_PW, MAIL_AUTH_TYPE)
|
||||
If oSession.Connected = True Then
|
||||
End If
|
||||
|
||||
If MAILSession.Connected = True Then
|
||||
If _email.SendMail(oSendto, MAILFROM, Email_Betreff, Email_Body, Now, oAttMt, 0) = True Then
|
||||
FileJobSuccessful = True
|
||||
Else
|
||||
Logger.Warn("Email_SendMail2 was not successfull!")
|
||||
Logger.Warn("Email_SendMail(2) was not successfull!")
|
||||
FileJobSuccessful = False
|
||||
End If
|
||||
_email.Disconnect()
|
||||
Else
|
||||
Logger.Warn($"Email_ConnectToServer2 was not successfull!")
|
||||
Logger.Warn($"Email_ConnectToServer(2) was not successfull!")
|
||||
FileJobSuccessful = False
|
||||
End If
|
||||
|
||||
@ -768,9 +790,7 @@ Public Class clsProfil
|
||||
End If
|
||||
|
||||
End If
|
||||
Else
|
||||
Logger.Info("Verarbeitung für JETZT NICHT konfiguriert")
|
||||
End If
|
||||
|
||||
'Abschluss des Profiles
|
||||
_database.Execute_non_Query("UPDATE TBWMRH_PROFIL SET Running = 0 WHERE GUID = " & _profGUID)
|
||||
Return True
|
||||
|
||||
@ -733,7 +733,7 @@ Public Class frmMain
|
||||
For Each DR As DataRow In DT.Rows
|
||||
clsCURRENT._PROFIL_ID = CInt(DR.Item("GUID"))
|
||||
'Und nun das Profil durchlaufen
|
||||
Dim initresult = _profil.Init(clsCURRENT._PROFIL_ID)
|
||||
Dim initresult = _profil.Init(clsCURRENT._PROFIL_ID, True)
|
||||
If initresult = True Then
|
||||
_profil.Profil_Durchlauf(True)
|
||||
ElseIf initresult = False Then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user