ZUGFeRD Job: add versioning of moved files
This commit is contained in:
parent
3d55483a56
commit
0ec5829275
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configSections>
|
<configSections>
|
||||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<section name="DDZUGFeRDService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
<section name="DDZUGFeRDService.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
</sectionGroup>
|
</sectionGroup>
|
||||||
</configSections>
|
</configSections>
|
||||||
@ -39,4 +39,9 @@
|
|||||||
</setting>
|
</setting>
|
||||||
</DDZUGFeRDService.My.MySettings>
|
</DDZUGFeRDService.My.MySettings>
|
||||||
</applicationSettings>
|
</applicationSettings>
|
||||||
</configuration>
|
<system.data>
|
||||||
|
<DbProviderFactories>
|
||||||
|
<remove invariant="FirebirdSql.Data.FirebirdClient" />
|
||||||
|
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
|
||||||
|
</DbProviderFactories>
|
||||||
|
</system.data></configuration>
|
||||||
@ -47,6 +47,9 @@
|
|||||||
<OptionInfer>On</OptionInfer>
|
<OptionInfer>On</OptionInfer>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="FirebirdSql.Data.FirebirdClient" version="6.4.0" targetFramework="net461" />
|
||||||
<package id="NLog" version="4.6.7" targetFramework="net461" />
|
<package id="NLog" version="4.6.7" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -96,6 +96,11 @@ Public Class File
|
|||||||
IO.File.Move(FilePath, Path.Combine(Directory, oFileInfo.Name))
|
IO.File.Move(FilePath, Path.Combine(Directory, oFileInfo.Name))
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Public Sub MoveTo(FilePath As String, NewFileName As String, Directory As String)
|
||||||
|
Dim oFileInfo As New FileInfo(FilePath)
|
||||||
|
IO.File.Move(FilePath, Path.Combine(Directory, NewFileName))
|
||||||
|
End Sub
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Tries to create a directory and returns its path.
|
''' Tries to create a directory and returns its path.
|
||||||
''' Returns a temp path if `DirectoryPath` can not be created or written to.
|
''' Returns a temp path if `DirectoryPath` can not be created or written to.
|
||||||
|
|||||||
@ -102,4 +102,9 @@
|
|||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
</configuration>
|
<system.data>
|
||||||
|
<DbProviderFactories>
|
||||||
|
<remove invariant="FirebirdSql.Data.FirebirdClient" />
|
||||||
|
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
|
||||||
|
</DbProviderFactories>
|
||||||
|
</system.data></configuration>
|
||||||
@ -47,6 +47,9 @@
|
|||||||
<OptionInfer>On</OptionInfer>
|
<OptionInfer>On</OptionInfer>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="FirebirdSql.Data.FirebirdClient" version="6.4.0" targetFramework="net461" />
|
||||||
<package id="NLog" version="4.5.11" targetFramework="net461" />
|
<package id="NLog" version="4.5.11" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -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)
|
Private Sub MoveFiles(Args As WorkerArgs, Files As List(Of FileInfo), AttachmentFiles As List(Of FileInfo), MoveDirectory As String)
|
||||||
For Each oFile In Files
|
For Each oFile In Files
|
||||||
Dim oFinalMoveDirectory As String = MoveDirectory
|
Try
|
||||||
|
Dim oFinalMoveDirectory As String = MoveDirectory
|
||||||
|
|
||||||
If AttachmentFiles.Contains(oFile) Then
|
If AttachmentFiles.Contains(oFile) Then
|
||||||
oFinalMoveDirectory = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory)
|
oFinalMoveDirectory = Path.Combine(MoveDirectory, Args.AttachmentsSubDirectory)
|
||||||
|
|
||||||
If Not Directory.Exists(oFinalMoveDirectory) Then
|
If Not Directory.Exists(oFinalMoveDirectory) Then
|
||||||
Directory.CreateDirectory(oFinalMoveDirectory)
|
Directory.CreateDirectory(oFinalMoveDirectory)
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
|
||||||
|
|
||||||
_filesystem.MoveTo(oFile.FullName, oFinalMoveDirectory)
|
Dim oVersion As Integer = 0
|
||||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
Dim oFileName As String = Path.Combine(oFinalMoveDirectory, oFile.Name)
|
||||||
_logger.Info("File moved to {0}", oFinalMoveDirectory)
|
|
||||||
|
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
|
Next
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user