Jobs: Add Subfolders per Date for error/rejected zugferd invoices
This commit is contained in:
parent
c5413cf284
commit
8f3acd58f5
@ -63,14 +63,26 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Private Function MoveAndRenameEmailToRejected(Args As WorkerArgs, MessageId As String) As EmailData
|
Private Function MoveAndRenameEmailToRejected(Args As WorkerArgs, MessageId As String) As EmailData
|
||||||
Dim oEmailData = _email.GetEmailDataForMessageId(MessageId)
|
Dim oEmailData = _email.GetEmailDataForMessageId(MessageId)
|
||||||
Dim oSource = _email.GetOriginalEmailPath(Args.OriginalEmailDirectory, MessageId)
|
Dim oSource = _email.GetOriginalEmailPath(Args.OriginalEmailDirectory, MessageId)
|
||||||
|
Dim oDateSubDirectoryName As String = Now.ToString("yyyy-MM-dd")
|
||||||
Dim oDestination As String
|
Dim oDestination As String
|
||||||
|
|
||||||
|
Dim oRejectedDirectory As String = Path.Combine(Args.RejectedEmailDirectory, oDateSubDirectoryName)
|
||||||
|
|
||||||
|
' Create the destination directory if it does not exist
|
||||||
|
If Not Directory.Exists(oRejectedDirectory) Then
|
||||||
|
Try
|
||||||
|
Directory.CreateDirectory(oRejectedDirectory)
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Error(ex)
|
||||||
|
End Try
|
||||||
|
End If
|
||||||
|
|
||||||
' If oEmailData is Nothing, TBEDM_EMAIL_PROFILER_HISTORY for MessageId was not found.
|
' If oEmailData is Nothing, TBEDM_EMAIL_PROFILER_HISTORY for MessageId was not found.
|
||||||
' This only should happen when testing and db-tables are deleted frequently
|
' This only should happen when testing and db-tables are deleted frequently
|
||||||
If oEmailData Is Nothing Then
|
If oEmailData Is Nothing Then
|
||||||
oDestination = _email.GetEmailPathWithSubjectAsName(Args.RejectedEmailDirectory, MessageId)
|
oDestination = _email.GetEmailPathWithSubjectAsName(oRejectedDirectory, MessageId)
|
||||||
Else
|
Else
|
||||||
oDestination = _email.GetEmailPathWithSubjectAsName(Args.RejectedEmailDirectory, oEmailData.Subject)
|
oDestination = _email.GetEmailPathWithSubjectAsName(oRejectedDirectory, oEmailData.Subject)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
_logger.Debug("Destination for eml file is {0}", oDestination)
|
_logger.Debug("Destination for eml file is {0}", oDestination)
|
||||||
@ -151,6 +163,10 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Dim oZUGFeRDCount As Integer = 0
|
Dim oZUGFeRDCount As Integer = 0
|
||||||
' Set the default Move Directory
|
' Set the default Move Directory
|
||||||
Dim oMoveDirectory As String = oArgs.SuccessDirectory
|
Dim oMoveDirectory As String = oArgs.SuccessDirectory
|
||||||
|
' Flag to save if the whole process was a success.
|
||||||
|
' Will be set only at the end of the function if no error occurred.
|
||||||
|
Dim oIsSuccess As Boolean = False
|
||||||
|
|
||||||
' Create file lists
|
' Create file lists
|
||||||
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
||||||
Dim oEmailAttachmentFiles As New List(Of FileInfo)
|
Dim oEmailAttachmentFiles As New List(Of FileInfo)
|
||||||
@ -478,6 +494,8 @@ Public Class ImportZUGFeRDFiles
|
|||||||
End Try
|
End Try
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
oIsSuccess = True
|
||||||
|
|
||||||
Catch ex As MD5HashException
|
Catch ex As MD5HashException
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
oMoveDirectory = oArgs.ErrorDirectory
|
oMoveDirectory = oArgs.ErrorDirectory
|
||||||
@ -546,7 +564,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
' Move all files of the current group
|
' Move all files of the current group
|
||||||
Try
|
Try
|
||||||
MoveFiles(oArgs, oMessageId, oFileGroupFiles, oEmailAttachmentFiles, oEmbeddedAttachmentFiles, oMoveDirectory)
|
MoveFiles(oArgs, oMessageId, oFileGroupFiles, oEmailAttachmentFiles, oEmbeddedAttachmentFiles, oMoveDirectory, oIsSuccess)
|
||||||
_logger.Info("Finished processing file group {0}", oMessageId)
|
_logger.Info("Finished processing file group {0}", oMessageId)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Warn("Could not move files!")
|
_logger.Warn("Could not move files!")
|
||||||
@ -567,9 +585,23 @@ Public Class ImportZUGFeRDFiles
|
|||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub MoveFiles(Args As WorkerArgs, MessageId As String, Files As List(Of FileInfo), AttachmentFiles As List(Of FileInfo), EmbeddedAttachments As List(Of PDFAttachments.AttachmentResult), MoveDirectory As String)
|
Private Sub MoveFiles(
|
||||||
|
Args As WorkerArgs,
|
||||||
|
MessageId As String,
|
||||||
|
Files As List(Of FileInfo),
|
||||||
|
AttachmentFiles As List(Of FileInfo),
|
||||||
|
EmbeddedAttachments As List(Of PDFAttachments.AttachmentResult),
|
||||||
|
MoveDirectory As String,
|
||||||
|
IsSuccess As Boolean)
|
||||||
|
|
||||||
Dim oFinalMoveDirectory As String = MoveDirectory
|
Dim oFinalMoveDirectory As String = MoveDirectory
|
||||||
Dim oAttachmentDirectory As String = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory)
|
Dim oDateSubDirectoryName As String = Now.ToString("yyyy-MM-dd")
|
||||||
|
Dim oAttachmentDirectory As String = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory, oDateSubDirectoryName)
|
||||||
|
|
||||||
|
' Files will be moved to a subfolder for the current day if they are rejected
|
||||||
|
If Not IsSuccess Then
|
||||||
|
oFinalMoveDirectory = Path.Combine(oFinalMoveDirectory, oDateSubDirectoryName)
|
||||||
|
End If
|
||||||
|
|
||||||
' Create directories if they don't exist
|
' Create directories if they don't exist
|
||||||
If Not Directory.Exists(oFinalMoveDirectory) Then
|
If Not Directory.Exists(oFinalMoveDirectory) Then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user