ZUGFeRD Job: add versioning of moved files

This commit is contained in:
Jonathan Jenne 2019-09-18 15:40:18 +02:00
parent 3d55483a56
commit 0ec5829275
8 changed files with 59 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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" />
</sectionGroup>
</configSections>
@ -39,4 +39,9 @@
</setting>
</DDZUGFeRDService.My.MySettings>
</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>

View File

@ -47,6 +47,9 @@
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<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="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.6.7\lib\net45\NLog.dll</HintPath>

View File

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

View File

@ -96,6 +96,11 @@ Public Class File
IO.File.Move(FilePath, Path.Combine(Directory, oFileInfo.Name))
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>
''' Tries to create a directory and returns its path.
''' Returns a temp path if `DirectoryPath` can not be created or written to.

View File

@ -102,4 +102,9 @@
</dependentAssembly>
</assemblyBinding>
</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>

View File

@ -47,6 +47,9 @@
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<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="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>

View File

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

View File

@ -567,6 +567,7 @@ 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
Try
Dim oFinalMoveDirectory As String = MoveDirectory
If AttachmentFiles.Contains(oFile) Then
@ -577,9 +578,31 @@ Public Class ImportZUGFeRDFiles
End If
End If
_filesystem.MoveTo(oFile.FullName, 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}", oFinalMoveDirectory)
_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