4 Commits

Author SHA1 Message Date
Jonathan Jenne
b399ced22e ZUGFeRD Service: Version 2.5.0.1 2023-07-27 10:15:58 +02:00
Jonathan Jenne
6df0d3deff ZUGFeRD Service: Clean up 2023-07-27 10:15:42 +02:00
Jonathan Jenne
a16d40169d ZUGFeRDService: Remove Firebird Database, Fix Worker Busy Error 2023-07-25 15:28:28 +02:00
Jonathan Jenne
770ddef67c ZugferdService: Version 2.4.1.0 2023-06-27 08:42:16 +02:00
6 changed files with 51 additions and 154 deletions

View File

@@ -1,9 +1,7 @@
Public Class Config Public Class Config
Public Property Firebird As New FirebirdConfig
Public Property Custom As New CustomConfig Public Property Custom As New CustomConfig
Public Property MSSQLConnectionString As String = "" Public Property MSSQLConnectionString As String = ""
Public Property MSSQLEnabled As Boolean = False
Public Property MSSQLEmailOutAccountID As String = 1 Public Property MSSQLEmailOutAccountID As String = 1
Public Property PORTAL_NAME As String = "WISAG-Portal" Public Property PORTAL_NAME As String = "WISAG-Portal"
@@ -13,6 +11,15 @@
Public Property Debug As Boolean = False 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 Public Class CustomConfig
''' <summary> ''' <summary>
''' If the file was already rejected, it is allowed to be processed again, ''' If the file was already rejected, it is allowed to be processed again,
@@ -30,22 +37,9 @@
''' </summary> ''' </summary>
Public Property MaxAttachmentSizeInMegaBytes As Integer = -1 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 AllowFacturX As Boolean = False
Public Property AllowXRechnung As Boolean = False Public Property AllowXRechnung As Boolean = False
Public Property AllowZugferd10 As Boolean = True Public Property AllowZugferd10 As Boolean = True
Public Property AllowZugferd2x As Boolean = True Public Property AllowZugferd2x As Boolean = True
End Class 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 End Class

View File

@@ -68,9 +68,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath> <HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
</Reference> </Reference>
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=7.5.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.7.5.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath> <HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("DDZUGFeRDService")> <Assembly: AssemblyProduct("DDZUGFeRDService")>
<Assembly: AssemblyCopyright("Copyright © 2023")> <Assembly: AssemblyCopyright("Copyright © 2023")>
<Assembly: AssemblyTrademark("2.4.0.0")> <Assembly: AssemblyTrademark("2.5.0.1")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.4.0.0")> <Assembly: AssemblyVersion("2.5.0.1")>
<Assembly: AssemblyFileVersion("2.4.0.0")> <Assembly: AssemblyFileVersion("2.5.0.1")>

View File

@@ -1,12 +1,10 @@
Imports System.ComponentModel Imports System.ComponentModel
Imports System.IO Imports System.IO
Imports System.Timers Imports System.Timers
Imports System.Xml.XPath
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Interfaces
Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Jobs.ImportZUGFeRDFiles
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Public Class ThreadRunner Public Class ThreadRunner
@@ -17,17 +15,12 @@ Public Class ThreadRunner
Private ReadOnly _config As ConfigManager(Of Config) Private ReadOnly _config As ConfigManager(Of Config)
Private ReadOnly _logConfig As LogConfig Private ReadOnly _logConfig As LogConfig
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
Private ReadOnly _firebird As Firebird
Private ReadOnly _jobArguments As WorkerArgs Private ReadOnly _jobArguments As WorkerArgs
Private ReadOnly _mssql As MSSQLServer Private ReadOnly _mssql As MSSQLServer
Private ReadOnly RejectedMaxDifferenceInMinutes As Integer = 60 Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), MSSQL As MSSQLServer)
Private RejectedLastRun As Date = Now.AddMinutes(-(RejectedMaxDifferenceInMinutes - 1))
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
_config = ConfigManager _config = ConfigManager
_mssql = MSSQL _mssql = MSSQL
Try Try
@@ -61,12 +54,6 @@ Public Class ThreadRunner
oArgs = LoadFolderConfig(oArgs) oArgs = LoadFolderConfig(oArgs)
oArgs = LoadPropertyMap(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("Custom Options:")
_logger.Debug("ExceptionEmailAddress: {0}", oArgs.ExceptionEmailAddress) _logger.Debug("ExceptionEmailAddress: {0}", oArgs.ExceptionEmailAddress)
_logger.Debug("IgnoreRejectionStatus: {0}", oArgs.IgnoreRejectionStatus) _logger.Debug("IgnoreRejectionStatus: {0}", oArgs.IgnoreRejectionStatus)
@@ -146,58 +133,12 @@ Public Class ThreadRunner
End If End If
End Sub 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 Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
Try 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 Dim oArgs As WorkerArgs = e.Argument
_logger.Debug("Background worker running..") _logger.Debug("Background worker running..")
Dim oJob As New ImportZUGFeRDFiles(_logConfig, _firebird, _mssql) Dim oJob As New ImportZUGFeRDFiles(_logConfig, _mssql)
oJob.Start(oArgs) oJob.Start(oArgs)
Catch ex As Exception Catch ex As Exception
_logger.Warn("Background worker failed!") _logger.Warn("Background worker failed!")
@@ -210,44 +151,20 @@ Public Class ThreadRunner
End Sub End Sub
Private Function LoadFolderConfig(pArgs As WorkerArgs) 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" pArgs.WatchDirectories.Add(_config.Config.WatchDirectory)
Dim oResult As DataTable = _firebird.GetDatatable(oSQL) pArgs.SuccessDirectory = _config.Config.SuccessDirectory
pArgs.ErrorDirectory = _config.Config.ErrorDirectory
For Each oRow As DataRow In oResult.Rows pArgs.OriginalEmailDirectory = _config.Config.OriginalEmailDirectory
Dim oFolderType = oRow.Item("FOLDER_TYPE") pArgs.RejectedEmailDirectory = _config.Config.RejectedEmailDirectory
pArgs.AttachmentsSubDirectory = _config.Config.AttachmentsSubDirectory
Select Case oFolderType pArgs.NonZugferdDirectory = _config.Config.NonZugferdDirectory
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
Return pArgs Return pArgs
End Function End Function
Private Function LoadPropertyMap(pArgs As WorkerArgs) As WorkerArgs 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 oSQL As String = $"SELECT * FROM TBDD_ZUGFERD_XML_ITEMS WHERE ACTIVE = 1 ORDER BY XML_PATH"
Dim oResult As DataTable = _firebird.GetDatatable(oSQL) Dim oResult As DataTable = _mssql.GetDatatable(oSQL)
For Each oRow As DataRow In oResult.Rows For Each oRow As DataRow In oResult.Rows
Dim oXmlPath = oRow.Item("XML_PATH") Dim oXmlPath = oRow.Item("XML_PATH")

View File

@@ -5,52 +5,42 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig Imports DigitalData.Modules.Logging.LogConfig
Public Class ZUGFeRDService Public Class ZUGFeRDService
Private _config As ConfigManager(Of Config) Private LogConfig As LogConfig
Private _logConfig As LogConfig Private Logger As Logger
Private _logger As Logger Private ThreadRunner As ThreadRunner
Private _firebird As Firebird
Private _mssql As MSSQLServer = Nothing
Private _threadRunner As ThreadRunner
Protected Overrides Sub OnStart(args() As String) Protected Overrides Sub OnStart(args() As String)
_logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService")
_config = New ConfigManager(Of Config)(_logConfig, My.Application.Info.DirectoryPath)
_logConfig.Debug = _config.Config.Debug
_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 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
End If
Try Try
_threadRunner = New ThreadRunner(_logConfig, _config, _firebird, _mssql) LogConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService")
_threadRunner.Start(oJobInterval) Dim oConfig = New ConfigManager(Of Config)(LogConfig, My.Application.Info.DirectoryPath)
LogConfig.Debug = oConfig.Config.Debug
Logger = LogConfig.GetLogger()
Logger.Info($"{Constants.SERVICE_NAME} is starting.")
If oConfig.Config.MSSQLConnectionString = String.Empty Then
Logger.Warn("MSSQL Connectionstring is empty. Exiting.")
Throw New ArgumentNullException("ConnectionString is missing!")
End If
Dim oDatabase = New MSSQLServer(LogConfig, oConfig.Config.MSSQLConnectionString)
If oDatabase.DBInitialized = False Then
Logger.Warn("MSSQL Connection failed. Exiting.")
Throw New ApplicationException("Connection failed!")
End If
ThreadRunner = New ThreadRunner(LogConfig, oConfig, oDatabase)
ThreadRunner.Start(oConfig.Config.JobInterval)
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) Logger.Warn("Starting the Service failed.")
Logger.Error(ex)
End Try End Try
End Sub End Sub
Protected Overrides Sub OnStop() Protected Overrides Sub OnStop()
_logger.Info($"{Constants.SERVICE_NAME} is stopping.") Logger.Info($"{Constants.SERVICE_NAME} is stopping.")
ThreadRunner.Stop()
_threadRunner.Stop() Logger.Info($"{Constants.SERVICE_NAME} stopped.")
End Sub End Sub
End Class End Class

View File

@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="FirebirdSql.Data.FirebirdClient" version="7.5.0" targetFramework="net461" />
<package id="NLog" version="5.0.5" targetFramework="net461" /> <package id="NLog" version="5.0.5" targetFramework="net461" />
</packages> </packages>