ZUGFeRDService: Load ExceptionEmailAddress from Config

This commit is contained in:
Jonathan Jenne
2021-05-10 14:48:10 +02:00
parent fcd21faa01
commit e53f22ce31
2 changed files with 43 additions and 34 deletions

View File

@@ -6,6 +6,7 @@
Public Property JobInterval As Integer = 10 Public Property JobInterval As Integer = 10
Public Property GDPictureKey As String = "1234567890_EXAMPLE_KEY" Public Property GDPictureKey As String = "1234567890_EXAMPLE_KEY"
Public Property ExceptionEmailAddress As String = "wisag-flow@digitaldata.works"
Public Property Debug As Boolean = False Public Property Debug As Boolean = False

View File

@@ -14,7 +14,7 @@ Public Class ThreadRunner
Private WithEvents _workerThread As BackgroundWorker Private WithEvents _workerThread As BackgroundWorker
Private WithEvents _workerTimer As Timer Private WithEvents _workerTimer As Timer
Private _config As Config Private _config As ConfigManager(Of Config)
Private _logConfig As LogConfig Private _logConfig As LogConfig
Private _logger As Logger Private _logger As Logger
Private _firebird As Firebird Private _firebird As Firebird
@@ -27,11 +27,11 @@ Public Class ThreadRunner
Private _jobArguments As WorkerArgs Private _jobArguments As WorkerArgs
Private _mssql As MSSQLServer Private _mssql As MSSQLServer
Public Sub New(LogConfig As LogConfig, Config As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing) Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
_logConfig = LogConfig _logConfig = LogConfig
_logger = _logConfig.GetLogger() _logger = _logConfig.GetLogger()
_firebird = Firebird _firebird = Firebird
_config = Config _config = ConfigManager
_mssql = MSSQL _mssql = MSSQL
Try Try
Dim directory As New IO.DirectoryInfo(_logConfig.LogDirectory) Dim directory As New IO.DirectoryInfo(_logConfig.LogDirectory)
@@ -48,39 +48,47 @@ Public Class ThreadRunner
Catch ex As Exception Catch ex As Exception
End Try End Try
Dim args As New WorkerArgs()
args = LoadFolderConfig(args) Dim oArgs As New WorkerArgs With {
args = LoadPropertyMapFor(args, "DEFAULT") .ExceptionEmailAddress = _config.Config.ExceptionEmailAddress
}
oArgs = LoadFolderConfig(oArgs)
oArgs = LoadPropertyMapFor(oArgs, "DEFAULT")
' Use MSSQL Server if available ' Use MSSQL Server if available
If Not IsNothing(_mssql) Then If Not IsNothing(_mssql) Then
_logger.Debug("Data will also be inserted into MSSQL Server.") _logger.Debug("Data will also be inserted into MSSQL Server.")
args.InsertIntoSQLServer = True oArgs.InsertIntoSQLServer = True
End If End If
_jobArguments = args _jobArguments = oArgs
_logger.Debug("Checking SuccessDirectory {0}", args.SuccessDirectory) _logger.Debug("Checking SuccessDirectory {0}", oArgs.SuccessDirectory)
If Not Directory.Exists(args.SuccessDirectory) Then If Not Directory.Exists(oArgs.SuccessDirectory) Then
_logger.Warn("SuccessDirectory {0} does not exist!", args.SuccessDirectory) _logger.Warn("SuccessDirectory {0} does not exist!", oArgs.SuccessDirectory)
End If End If
_logger.Debug("Checking ErrorDirectory {0}", args.ErrorDirectory) _logger.Debug("Checking ErrorDirectory {0}", oArgs.ErrorDirectory)
If Not Directory.Exists(args.ErrorDirectory) Then If Not Directory.Exists(oArgs.ErrorDirectory) Then
_logger.Warn("ErrorDirectory {0} does not exist!", args.ErrorDirectory) _logger.Warn("ErrorDirectory {0} does not exist!", oArgs.ErrorDirectory)
End If End If
_logger.Debug("Checking Original Email Directory {0}", args.OriginalEmailDirectory) _logger.Debug("Checking Original Email Directory {0}", oArgs.OriginalEmailDirectory)
If Not Directory.Exists(args.OriginalEmailDirectory) Then If Not Directory.Exists(oArgs.OriginalEmailDirectory) Then
_logger.Warn("OriginalEmailDirectory {0} does not exist!", args.OriginalEmailDirectory) _logger.Warn("OriginalEmailDirectory {0} does not exist!", oArgs.OriginalEmailDirectory)
End If End If
_logger.Debug("Checking Rejected Email Directory {0}", args.RejectedEmailDirectory) _logger.Debug("Checking Rejected Email Directory {0}", oArgs.RejectedEmailDirectory)
If Not Directory.Exists(args.RejectedEmailDirectory) Then If Not Directory.Exists(oArgs.RejectedEmailDirectory) Then
_logger.Warn("RejectedEmailDirectory {0} does not exist!", args.RejectedEmailDirectory) _logger.Warn("RejectedEmailDirectory {0} does not exist!", oArgs.RejectedEmailDirectory)
End If End If
For Each oDirectory In args.WatchDirectories _logger.Debug("Checking Exception Email Adress {0}", oArgs.ExceptionEmailAddress)
If oArgs.ExceptionEmailAddress = String.Empty Then
_logger.Warn("ExceptionEmailAddress {0} is not set!", oArgs.ExceptionEmailAddress)
End If
For Each oDirectory In oArgs.WatchDirectories
_logger.Debug("Checking WatchDirectory {0}", oDirectory) _logger.Debug("Checking WatchDirectory {0}", oDirectory)
If Not Directory.Exists(oDirectory) Then If Not Directory.Exists(oDirectory) Then
_logger.Warn("WatchDirectory {0} does not exist!", oDirectory) _logger.Warn("WatchDirectory {0} does not exist!", oDirectory)
@@ -140,7 +148,7 @@ Public Class ThreadRunner
Dim args As WorkerArgs = e.Argument Dim args As WorkerArgs = e.Argument
_logger.Debug("Background worker running..") _logger.Debug("Background worker running..")
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.MSSQLEmailOutAccountID, _mssql) Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.Config.MSSQLEmailOutAccountID, _mssql)
job.Start(args) job.Start(args)
Catch ex As Exception Catch ex As Exception
_logger.Warn("Background worker failed!") _logger.Warn("Background worker failed!")
@@ -152,7 +160,7 @@ Public Class ThreadRunner
_logger.Debug("Background worker completed!") _logger.Debug("Background worker completed!")
End Sub End Sub
Private Function LoadFolderConfig(args As WorkerArgs) Private Function LoadFolderConfig(pArgs As WorkerArgs) As WorkerArgs
Dim oSQL As String = "SELECT T1.FOLDER_TYPE, T.FOLDER_PATH FROM TBEDM_FOLDER T, TBEDM_FOLDER_TYPE T1 WHERE T.FOLDER_TYPE_ID = T1.GUID AND T1.""ACTIVE"" = True AND T.""ACTIVE"" = True" Dim oSQL As String = "SELECT T1.FOLDER_TYPE, T.FOLDER_PATH FROM TBEDM_FOLDER T, TBEDM_FOLDER_TYPE T1 WHERE T.FOLDER_TYPE_ID = T1.GUID AND T1.""ACTIVE"" = True AND T.""ACTIVE"" = True"
Dim oResult As DataTable = _firebird.GetDatatable(oSQL) Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
@@ -161,31 +169,31 @@ Public Class ThreadRunner
Select Case oFolderType Select Case oFolderType
Case ZUGFERD_IN Case ZUGFERD_IN
args.WatchDirectories.Add(row.Item("FOLDER_PATH")) pArgs.WatchDirectories.Add(row.Item("FOLDER_PATH"))
Case ZUGFERD_SUCCESS Case ZUGFERD_SUCCESS
args.SuccessDirectory = row.Item("FOLDER_PATH") pArgs.SuccessDirectory = row.Item("FOLDER_PATH")
Case ZUGFERD_ERROR Case ZUGFERD_ERROR
args.ErrorDirectory = row.Item("FOLDER_PATH") pArgs.ErrorDirectory = row.Item("FOLDER_PATH")
Case ZUGFERD_EML Case ZUGFERD_EML
args.OriginalEmailDirectory = row.Item("FOLDER_PATH") pArgs.OriginalEmailDirectory = row.Item("FOLDER_PATH")
Case ZUGFERD_REJECTED_EML Case ZUGFERD_REJECTED_EML
args.RejectedEmailDirectory = row.Item("FOLDER_PATH") pArgs.RejectedEmailDirectory = row.Item("FOLDER_PATH")
Case ZUGFERD_ATTACHMENTS Case ZUGFERD_ATTACHMENTS
args.AttachmentsSubDirectory = row.Item("FOLDER_PATH") pArgs.AttachmentsSubDirectory = row.Item("FOLDER_PATH")
End Select End Select
Next Next
Return args Return pArgs
End Function End Function
Private Function LoadPropertyMapFor(args As WorkerArgs, specification As String) Private Function LoadPropertyMapFor(pArgs As WorkerArgs, pSpecification As String) As WorkerArgs
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{specification}' AND ACTIVE = True ORDER BY XML_PATH" Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{pSpecification}' AND ACTIVE = True ORDER BY XML_PATH"
Dim oResult As DataTable = _firebird.GetDatatable(oSQL) Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
For Each row As DataRow In oResult.Rows For Each row As DataRow In oResult.Rows
@@ -197,7 +205,7 @@ Public Class ThreadRunner
Dim oIsGrouped = row.Item("IS_GROUPED") Dim oIsGrouped = row.Item("IS_GROUPED")
Dim oGroupScope = row.Item("GROUP_SCOPE") Dim oGroupScope = row.Item("GROUP_SCOPE")
args.PropertyMap.Add(oXmlPath, New XmlItemProperty() With { pArgs.PropertyMap.Add(oXmlPath, New XmlItemProperty() With {
.Description = oDescription, .Description = oDescription,
.TableName = oTableName, .TableName = oTableName,
.TableColumn = oTableColumn, .TableColumn = oTableColumn,
@@ -207,6 +215,6 @@ Public Class ThreadRunner
}) })
Next Next
Return args Return pArgs
End Function End Function
End Class End Class