diff --git a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb index 6de7503e..20d7cca4 100644 --- a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -13,6 +13,7 @@ Imports DigitalData.Modules.Interfaces.Exceptions Imports DigitalData.Modules.Jobs.Exceptions Imports DigitalData.Modules.Logging Imports FirebirdSql.Data.FirebirdClient +Imports GdPicture14 Public Class ImportZUGFeRDFiles Implements IJob @@ -333,6 +334,10 @@ Public Class ImportZUGFeRDFiles _logger.Debug("Starting Job {0}", [GetType].Name) + _logger.Debug("Registering GDPicture License") + Dim oLicenseManager As New LicenseManager + oLicenseManager.RegisterKEY(oArgs.GDPictureKey) + Try For Each oPath As String In oArgs.WatchDirectories Dim oDirInfo As New DirectoryInfo(oPath) @@ -418,11 +423,14 @@ Public Class ImportZUGFeRDFiles End Select End Try + ' Extract all attachments other than the zugferd-invoice.xml Dim oAttachments = oAttachmentExtractor.Extract(oFile.FullName, AllowedExtensions) If oAttachments Is Nothing Then _logger.Warn("Attachments for file [{0}] could not be extracted", oFile.FullName) Else - oFileAttachmentFiles.AddRange(oFileGroupFiles) + 'oFileAttachmentFiles.AddRange(oFileGroupFiles) + 'oFileAttachmentFiles.AddRange(oAttachments) + oFileAttachmentFiles.AddRange(oAttachments) End If @@ -741,18 +749,27 @@ Public Class ImportZUGFeRDFiles End Sub Private Sub MoveFiles(Args As WorkerArgs, Files As List(Of FileInfo), AttachmentFiles As List(Of FileInfo), MoveDirectory As String) + Dim oFinalMoveDirectory As String = MoveDirectory + Dim oAttachmentDirectory As String = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory) + + If Not Directory.Exists(oFinalMoveDirectory) Then + Try + Directory.CreateDirectory(oFinalMoveDirectory) + Catch ex As Exception + _logger.Error(ex) + End Try + End If + + If Not Directory.Exists(oAttachmentDirectory) And AttachmentFiles.Count > 0 Then + Try + Directory.CreateDirectory(oAttachmentDirectory) + Catch ex As Exception + _logger.Error(ex) + End Try + End If + For Each oFile In Files Try - Dim oFinalMoveDirectory As String = MoveDirectory - - If AttachmentFiles.Contains(oFile) Then - oFinalMoveDirectory = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory) - - If Not Directory.Exists(oFinalMoveDirectory) Then - Directory.CreateDirectory(oFinalMoveDirectory) - End If - End If - Dim oFileName = _filesystem.GetVersionedFilename(Path.Combine(oFinalMoveDirectory, oFile.Name)) _filesystem.MoveTo(oFile.FullName, oFileName, oFinalMoveDirectory) @@ -764,6 +781,20 @@ Public Class ImportZUGFeRDFiles _logger.Error(ex) End Try Next + + For Each oFile In AttachmentFiles + Try + Dim oFileName = _filesystem.GetVersionedFilename(Path.Combine(oAttachmentDirectory, oFile.Name)) + + _filesystem.MoveTo(oFile.FullName, oFileName, oAttachmentDirectory) + + _logger.Info("Finished processing file {0}", oFile.Name) + _logger.Info("Attachment moved to {0}", oFileName) + Catch ex As Exception + _logger.Warn("Could not move attachment {0}", oFile.FullName) + _logger.Error(ex) + End Try + Next End Sub diff --git a/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb b/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb index 7c4f8919..86efe522 100644 --- a/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb +++ b/Modules.Jobs/EDMI/ZUGFeRD/PDFAttachments.vb @@ -5,11 +5,13 @@ Imports GdPicture14 Public Class PDFAttachments Private Logger As Logger + Private Filesystem As Filesystem.File Private Const ZUGFERD_XML_FILENAME = "ZUGFeRD-invoice.xml" Public Sub New(LogConfig As LogConfig, GdPictureKey As String) Logger = LogConfig.GetLogger + Filesystem = New Filesystem.File(LogConfig) End Sub Public Function Extract(FileName As String, AllowedExtensions As List(Of String)) As List(Of FileInfo) @@ -36,7 +38,8 @@ Public Class PDFAttachments Dim status As GdPictureStatus = oGDPicturePDF.ExtractEmbeddedFile(index, FileData) If status = GdPictureStatus.OK Then - Dim oTempName As String = Path.Combine(Path.GetTempPath(), oFileName) + Dim oVersionedName = Filesystem.GetVersionedFilename(oFileName) + Dim oTempName As String = Path.Combine(Path.GetTempPath(), oVersionedName) Using oFileStream As New FileStream(oTempName, FileMode.OpenOrCreate) oFileStream.Write(FileData, 0, FileData.Length) End Using diff --git a/Modules.Jobs/My Project/AssemblyInfo.vb b/Modules.Jobs/My Project/AssemblyInfo.vb index 228bfeee..8a735eeb 100644 --- a/Modules.Jobs/My Project/AssemblyInfo.vb +++ b/Modules.Jobs/My Project/AssemblyInfo.vb @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - +