ZUGFeRDService: Remove Firebird Database, Fix Worker Busy Error
This commit is contained in:
parent
770ddef67c
commit
a16d40169d
@ -1,9 +1,7 @@
|
||||
Public Class Config
|
||||
Public Property Firebird As New FirebirdConfig
|
||||
Public Property Custom As New CustomConfig
|
||||
|
||||
Public Property MSSQLConnectionString As String = ""
|
||||
Public Property MSSQLEnabled As Boolean = False
|
||||
Public Property MSSQLEmailOutAccountID As String = 1
|
||||
|
||||
Public Property PORTAL_NAME As String = "WISAG-Portal"
|
||||
@ -13,6 +11,15 @@
|
||||
|
||||
Public Property Debug As Boolean = False
|
||||
|
||||
Public Property WatchDirectory As String = String.Empty
|
||||
Public Property SuccessDirectory As String = String.Empty
|
||||
Public Property ErrorDirectory As String = String.Empty
|
||||
Public Property OriginalEmailDirectory As String = String.Empty
|
||||
Public Property RejectedEmailDirectory As String = String.Empty
|
||||
Public Property AttachmentsSubDirectory As String = String.Empty
|
||||
Public Property NonZugferdDirectory As String = String.Empty
|
||||
|
||||
|
||||
Public Class CustomConfig
|
||||
''' <summary>
|
||||
''' If the file was already rejected, it is allowed to be processed again,
|
||||
@ -30,22 +37,9 @@
|
||||
''' </summary>
|
||||
Public Property MaxAttachmentSizeInMegaBytes As Integer = -1
|
||||
|
||||
|
||||
Public Property RejectionTransferEnabled As Boolean = True
|
||||
Public Property RejectionTransferTimeUnit As String = "HOUR"
|
||||
Public Property RejectionTransferTimeValue As Integer = 12
|
||||
|
||||
Public Property AllowFacturX As Boolean = False
|
||||
Public Property AllowXRechnung As Boolean = False
|
||||
Public Property AllowZugferd10 As Boolean = True
|
||||
Public Property AllowZugferd2x As Boolean = True
|
||||
End Class
|
||||
|
||||
Public Class FirebirdConfig
|
||||
Public Property DataSource As String = "172.24.12.41"
|
||||
Public Property Database As String = "172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB"
|
||||
Public Property User As String = "sysdba"
|
||||
Public Property Password As String = "dd"
|
||||
|
||||
End Class
|
||||
End Class
|
||||
|
||||
@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("DDZUGFeRDService")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2023")>
|
||||
<Assembly: AssemblyTrademark("2.4.1.0")>
|
||||
<Assembly: AssemblyTrademark("2.5.0.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.4.1.0")>
|
||||
<Assembly: AssemblyFileVersion("2.4.1.0")>
|
||||
<Assembly: AssemblyVersion("2.5.0.0")>
|
||||
<Assembly: AssemblyFileVersion("2.5.0.0")>
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.IO
|
||||
Imports System.Timers
|
||||
Imports System.Xml.XPath
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Jobs.ImportZUGFeRDFiles
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class ThreadRunner
|
||||
@ -17,7 +15,6 @@ Public Class ThreadRunner
|
||||
Private ReadOnly _config As ConfigManager(Of Config)
|
||||
Private ReadOnly _logConfig As LogConfig
|
||||
Private ReadOnly _logger As Logger
|
||||
Private ReadOnly _firebird As Firebird
|
||||
Private ReadOnly _jobArguments As WorkerArgs
|
||||
Private ReadOnly _mssql As MSSQLServer
|
||||
|
||||
@ -27,7 +24,6 @@ Public Class ThreadRunner
|
||||
Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
_firebird = Firebird
|
||||
_config = ConfigManager
|
||||
_mssql = MSSQL
|
||||
Try
|
||||
@ -61,12 +57,6 @@ Public Class ThreadRunner
|
||||
oArgs = LoadFolderConfig(oArgs)
|
||||
oArgs = LoadPropertyMap(oArgs)
|
||||
|
||||
' Use MSSQL Server if available
|
||||
If Not IsNothing(_mssql) Then
|
||||
_logger.Debug("Data will also be inserted into MSSQL Server.")
|
||||
oArgs.InsertIntoSQLServer = True
|
||||
End If
|
||||
|
||||
_logger.Debug("Custom Options:")
|
||||
_logger.Debug("ExceptionEmailAddress: {0}", oArgs.ExceptionEmailAddress)
|
||||
_logger.Debug("IgnoreRejectionStatus: {0}", oArgs.IgnoreRejectionStatus)
|
||||
@ -146,58 +136,12 @@ Public Class ThreadRunner
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub MaybeUpdateRejected()
|
||||
Try
|
||||
Dim oTimeUnit = _config.Config.Custom.RejectionTransferTimeUnit
|
||||
Dim oTimeValue = _config.Config.Custom.RejectionTransferTimeValue
|
||||
|
||||
Dim oDifference As TimeSpan = Now - RejectedLastRun
|
||||
If oDifference.TotalMinutes < RejectedMaxDifferenceInMinutes Then
|
||||
_logger.Debug("Updating rejected files: Waiting for next run.")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
_logger.Info("Updating rejected files in Firebird.")
|
||||
|
||||
Dim oSQL = $"
|
||||
SELECT [EMAIL_MSGID]
|
||||
FROM TBEMLP_HISTORY
|
||||
WHERE (STATUS = 'REJECTED' OR CUST_REJECTED = 1) AND FB_UPDATED = 0
|
||||
AND DATEDIFF({oTimeUnit}, CHANGED_WHEN, GETDATE()) <= {oTimeValue}
|
||||
ORDER BY GUID DESC"
|
||||
Dim oTable As DataTable = _mssql.GetDatatable(oSQL)
|
||||
If Not IsNothing(oTable) Then
|
||||
For Each oROW As DataRow In oTable.Rows
|
||||
Dim oUpdate = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET REJECTED = True WHERE MESSAGE_ID = '{oROW.Item(0)}' and REJECTED = false"
|
||||
If _firebird.ExecuteNonQuery(oUpdate) = True Then
|
||||
Dim oUpdateSQL = $"
|
||||
UPDATE TBEMLP_HISTORY
|
||||
SET FB_UPDATED = 1
|
||||
WHERE [EMAIL_MSGID] = '{oROW.Item(0)}' AND FB_UPDATED = 0"
|
||||
|
||||
_mssql.ExecuteNonQuery(oUpdateSQL)
|
||||
End If
|
||||
Next
|
||||
|
||||
RejectedLastRun = Now
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Error while Updating REJECTED State: " & ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
|
||||
Try
|
||||
If _config.Config.Custom.RejectionTransferEnabled = True Then
|
||||
MaybeUpdateRejected()
|
||||
Else
|
||||
_logger.Debug("Transferring rejection status to Firebird is disabled.")
|
||||
End If
|
||||
|
||||
Dim oArgs As WorkerArgs = e.Argument
|
||||
_logger.Debug("Background worker running..")
|
||||
|
||||
Dim oJob As New ImportZUGFeRDFiles(_logConfig, _firebird, _mssql)
|
||||
Dim oJob As New ImportZUGFeRDFiles(_logConfig, _mssql)
|
||||
oJob.Start(oArgs)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Background worker failed!")
|
||||
@ -210,44 +154,20 @@ Public Class ThreadRunner
|
||||
End Sub
|
||||
|
||||
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 oResult As DataTable = _firebird.GetDatatable(oSQL)
|
||||
|
||||
For Each oRow As DataRow In oResult.Rows
|
||||
Dim oFolderType = oRow.Item("FOLDER_TYPE")
|
||||
|
||||
Select Case oFolderType
|
||||
Case ZUGFERD_IN
|
||||
pArgs.WatchDirectories.Add(oRow.Item("FOLDER_PATH"))
|
||||
|
||||
Case ZUGFERD_SUCCESS
|
||||
pArgs.SuccessDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
Case ZUGFERD_ERROR
|
||||
pArgs.ErrorDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
Case ZUGFERD_EML
|
||||
pArgs.OriginalEmailDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
Case ZUGFERD_REJECTED_EML
|
||||
pArgs.RejectedEmailDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
Case ZUGFERD_ATTACHMENTS
|
||||
pArgs.AttachmentsSubDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
Case ZUGFERD_NO_ZUGFERD
|
||||
_logger.Info($"## {ZUGFERD_NO_ZUGFERD}-Constant has been defined! [{oRow.Item("FOLDER_PATH")}]##")
|
||||
pArgs.NonZugferdDirectory = oRow.Item("FOLDER_PATH")
|
||||
|
||||
End Select
|
||||
Next
|
||||
pArgs.WatchDirectories.Add(_config.Config.WatchDirectory)
|
||||
pArgs.SuccessDirectory = _config.Config.SuccessDirectory
|
||||
pArgs.ErrorDirectory = _config.Config.ErrorDirectory
|
||||
pArgs.OriginalEmailDirectory = _config.Config.OriginalEmailDirectory
|
||||
pArgs.RejectedEmailDirectory = _config.Config.RejectedEmailDirectory
|
||||
pArgs.AttachmentsSubDirectory = _config.Config.AttachmentsSubDirectory
|
||||
pArgs.NonZugferdDirectory = _config.Config.NonZugferdDirectory
|
||||
|
||||
Return pArgs
|
||||
End Function
|
||||
|
||||
Private Function LoadPropertyMap(pArgs As WorkerArgs) As WorkerArgs
|
||||
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE ACTIVE = True ORDER BY XML_PATH"
|
||||
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
||||
Dim oSQL As String = $"SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH"
|
||||
Dim oResult As DataTable = _mssql.GetDatatable(oSQL)
|
||||
|
||||
For Each oRow As DataRow In oResult.Rows
|
||||
Dim oXmlPath = oRow.Item("XML_PATH")
|
||||
|
||||
@ -20,23 +20,19 @@ Public Class ZUGFeRDService
|
||||
_logger = _logConfig.GetLogger()
|
||||
_logger.Info($"{Constants.SERVICE_NAME} is starting.")
|
||||
|
||||
Dim oDataSource As String = _config.Config.Firebird.DataSource
|
||||
Dim oDatabase As String = _config.Config.Firebird.Database
|
||||
Dim oUser As String = _config.Config.Firebird.User
|
||||
Dim oPassword As String = _config.Config.Firebird.Password
|
||||
Dim oJobInterval As Integer = _config.Config.JobInterval
|
||||
Dim oMSSQLConnectionString As String = _config.Config.MSSQLConnectionString
|
||||
Dim oMSSQLEnabled As Boolean = _config.Config.MSSQLEnabled
|
||||
|
||||
_firebird = New Firebird(_logConfig, oDataSource, oDatabase, oUser, oPassword)
|
||||
If oMSSQLConnectionString = String.Empty Then
|
||||
_logger.Warn("MSSQL Connectionstring is empty. Exiting.")
|
||||
Throw New ArgumentNullException("ConnectionString is missing!")
|
||||
End If
|
||||
|
||||
If oMSSQLEnabled = True Then
|
||||
_mssql = New MSSQLServer(_logConfig, oMSSQLConnectionString)
|
||||
|
||||
If _mssql.DBInitialized = False Then
|
||||
_logger.Warn("MSSQL Connection could not be initialized. Disabling MSSQL.")
|
||||
_mssql = Nothing
|
||||
End If
|
||||
_logger.Warn("MSSQL Connection failed. Exiting.")
|
||||
Throw New ApplicationException("Connection failed!")
|
||||
End If
|
||||
|
||||
Try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user