ZUGFeRD Job: add versioning of moved files
This commit is contained in:
@@ -567,19 +567,42 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Private Sub MoveFiles(Args As WorkerArgs, Files As List(Of FileInfo), AttachmentFiles As List(Of FileInfo), MoveDirectory As String)
|
||||
For Each oFile In Files
|
||||
Dim oFinalMoveDirectory As String = MoveDirectory
|
||||
Try
|
||||
Dim oFinalMoveDirectory As String = MoveDirectory
|
||||
|
||||
If AttachmentFiles.Contains(oFile) Then
|
||||
oFinalMoveDirectory = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory)
|
||||
If AttachmentFiles.Contains(oFile) Then
|
||||
oFinalMoveDirectory = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory)
|
||||
|
||||
If Not Directory.Exists(oFinalMoveDirectory) Then
|
||||
Directory.CreateDirectory(oFinalMoveDirectory)
|
||||
If Not Directory.Exists(oFinalMoveDirectory) Then
|
||||
Directory.CreateDirectory(oFinalMoveDirectory)
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||
_logger.Info("File moved to {0}", oFinalMoveDirectory)
|
||||
Dim oVersion As Integer = 0
|
||||
Dim oFileName As String = Path.Combine(oFinalMoveDirectory, oFile.Name)
|
||||
|
||||
Do While File.Exists(oFileName)
|
||||
If oVersion > 29 Then
|
||||
Throw New ApplicationException("Max. Move-Retries of 30 exceeded! Move will be aborted!")
|
||||
End If
|
||||
|
||||
oVersion += 1
|
||||
|
||||
Dim oExtension = Path.GetExtension(oFileName)
|
||||
Dim oRootName = Path.GetFileNameWithoutExtension(oFile.Name)
|
||||
Dim oNewName As String = oRootName & "~" & oVersion & oExtension
|
||||
oFileName = Path.Combine(oFinalMoveDirectory, oNewName)
|
||||
Loop
|
||||
|
||||
_filesystem.MoveTo(oFile.FullName, oFileName, oFinalMoveDirectory)
|
||||
|
||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||
_logger.Info("File moved to {0}", oFileName)
|
||||
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Could not move file {0}", oFile.FullName)
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user