fix result handler deleting exported files
This commit is contained in:
@@ -15,8 +15,7 @@ Public Class clsDateiverarbeitung
|
||||
Dim _database As clsDatabase
|
||||
|
||||
Public Shared pr_DTPROFIL_REGELN As DataTable
|
||||
Public Shared aktfile_Exportresult
|
||||
|
||||
Public Shared aktfile_Exportresult As String
|
||||
|
||||
Public Shared CriticalError As Boolean = False
|
||||
|
||||
@@ -134,62 +133,138 @@ Public Class clsDateiverarbeitung
|
||||
Return String.Empty
|
||||
End Try
|
||||
End Function
|
||||
Public Function Export_WMFile2HDD(oWMFile As WMObject, MyExportpath As String)
|
||||
|
||||
' Neu geschriebene version 25.03.19
|
||||
Public Function Export_WMFile2HDD(WMObject As WMObject, ExportPath As String) As Boolean
|
||||
Try
|
||||
If Not MyExportpath.EndsWith("\") Then
|
||||
MyExportpath &= "\"
|
||||
End If
|
||||
Dim oWMObject As IWMObject6 = DirectCast(WMObject, IWMObject6)
|
||||
|
||||
Dim oFilenameFull As String = oWMObject.aName
|
||||
Dim oFilenameExport As String
|
||||
Dim oSplitIndex = oFilenameFull.LastIndexOf(".")
|
||||
Dim oVersion = 1
|
||||
|
||||
Try
|
||||
Logger.Info("Working on WMFile: " & oWMFile.aName)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
|
||||
Logger.Debug("ExportFileIO created...")
|
||||
Dim oFilename = oFilenameFull.Substring(0, oSplitIndex)
|
||||
Dim oExtension = oFilenameFull.Substring(oSplitIndex)
|
||||
|
||||
Dim oWMStream = oWMFile.OpenStream("BinaryObject", 1)
|
||||
'### VERSIONIERUNG ###
|
||||
Dim version As Integer = 2
|
||||
'Dim Stammname As String = System.IO.Path.GetFileNameWithoutExtension(Quelle)
|
||||
Dim oFilename = oWMFile.aName.Substring(0, oWMFile.aName.LastIndexOf("."))
|
||||
Dim oExtension = oWMFile.aName.Substring(oWMFile.aName.LastIndexOf("."))
|
||||
Dim oTempFilename As String = MyExportpath & oFilename & oExtension
|
||||
'Überprüfen ob File existiert
|
||||
Do While IO.File.Exists(oTempFilename) = True
|
||||
oTempFilename = MyExportpath & oFilename & "_" & version & oExtension
|
||||
version = version + 1
|
||||
Logger.Debug("Preparing export of file {0}..", oFilenameFull)
|
||||
Logger.Debug("Filename: {0}", oFilename)
|
||||
Logger.Debug("Extension: {0}", oExtension)
|
||||
|
||||
' build the file path in case the exported file doesn't already exist
|
||||
oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension)
|
||||
|
||||
' Add version until we find the version that does NOT exist
|
||||
Do While File.Exists(oFilenameExport)
|
||||
oVersion += 1
|
||||
oFilenameExport = BuildExportPath(ExportPath, oFilename, oExtension, oVersion)
|
||||
Loop
|
||||
Logger.Debug("Exportfilename is: " & oTempFilename)
|
||||
' den Dateiinhalt der neuen Datei zuweisen
|
||||
ExportFileIO.bstrOriginalFileName = oTempFilename
|
||||
ExportFileIO.aWMStream = oWMStream
|
||||
|
||||
'Das eigentliche kopieren
|
||||
ExportFileIO.ExportOriginal(True)
|
||||
' close the windream file stream
|
||||
oWMStream.Close()
|
||||
If File.Exists(oTempFilename) Then
|
||||
clsCURRENT.EXPORTED_FILENAME = oTempFilename
|
||||
Logger.Info($"File Export to HDD [{clsCURRENT.EXPORTED_FILENAME}]was successfull (File.Exists = True)!")
|
||||
aktfile_Exportresult = clsCURRENT.EXPORTED_FILENAME
|
||||
clsCURRENT.TEMP_FILES.Add(clsCURRENT.EXPORTED_FILENAME)
|
||||
Logger.Debug("File will be exported to {0}", oFilenameExport)
|
||||
|
||||
Logger.Debug("Opening file stream..")
|
||||
Dim oStream As WMStream = oWMObject.OpenStream("BinaryObject", WMObjectStreamOpenMode.WMObjectStreamOpenModeRead)
|
||||
Dim oWMFileIO As New WMOTOOLLib.WMFileIO() With {
|
||||
.aWMStream = oStream,
|
||||
.bstrOriginalFileName = oFilenameExport
|
||||
}
|
||||
|
||||
Logger.Debug("Exporting file..")
|
||||
oWMFileIO.ExportOriginal(True)
|
||||
|
||||
Logger.Debug("Cleaning up..")
|
||||
oStream.Close()
|
||||
|
||||
Logger.Debug("File exported!")
|
||||
|
||||
If File.Exists(oFilenameExport) Then
|
||||
Logger.Info($"File Export to HDD [{oFilenameExport}]was successfull (File.Exists = True)!")
|
||||
aktfile_Exportresult = oFilenameExport
|
||||
clsCURRENT.EXPORTED_FILENAME = oFilenameExport
|
||||
clsCURRENT.TEMP_FILES.Add(oFilenameExport)
|
||||
Logger.Debug("FileInfo Added to variables...")
|
||||
Return True
|
||||
Else
|
||||
Logger.Warn($"Export not successfull or File.Exists = false Export: [{oTempFilename}]")
|
||||
Logger.Warn($"Export not successfull or File.Exists = false Export: [{oFilenameExport}]")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Info("Unexpected error in Export_WMFile: " & ex.Message)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function BuildExportPath(BasePath As String, FilenameWithoutExtension As String, Extension As String, Optional Version As Integer = 1)
|
||||
Dim oFilename
|
||||
|
||||
If Version = 1 Then
|
||||
oFilename = FilenameWithoutExtension & Extension
|
||||
Else
|
||||
oFilename = FilenameWithoutExtension & "_" & Version & Extension
|
||||
End If
|
||||
|
||||
Return Path.Combine(BasePath, oFilename)
|
||||
End Function
|
||||
|
||||
' Aktuelle Funktion 25.03.19
|
||||
'Public Function Export_WMFile2HDD(oWMFile As WMObject, MyExportpath As String)
|
||||
' Try
|
||||
' If Not MyExportpath.EndsWith("\") Then
|
||||
' MyExportpath &= "\"
|
||||
' End If
|
||||
|
||||
|
||||
' Try
|
||||
' Logger.Info("Working on WMFile: " & oWMFile.aName)
|
||||
' Catch ex As Exception
|
||||
' Logger.Error(ex)
|
||||
' Return False
|
||||
' End Try
|
||||
' Dim ExportFileIO = New WMOTOOLLib.WMFileIO ' CreateObject("WMOTOOLLib.WMFileIO") ' New WMOTOOLLib.WMFileIO
|
||||
' Logger.Debug("ExportFileIO created...")
|
||||
|
||||
' Dim oWMStream = oWMFile.OpenStream("BinaryObject", 1)
|
||||
' '### VERSIONIERUNG ###
|
||||
' Dim version As Integer = 2
|
||||
' 'Dim Stammname As String = System.IO.Path.GetFileNameWithoutExtension(Quelle)
|
||||
' Dim oFilename = oWMFile.aName.Substring(0, oWMFile.aName.LastIndexOf("."))
|
||||
' Dim oExtension = oWMFile.aName.Substring(oWMFile.aName.LastIndexOf("."))
|
||||
' Dim oTempFilename As String = MyExportpath & oFilename & oExtension
|
||||
' 'Überprüfen ob File existiert
|
||||
' Do While IO.File.Exists(oTempFilename) = True
|
||||
' oTempFilename = MyExportpath & oFilename & "_" & version & oExtension
|
||||
' version = version + 1
|
||||
' Loop
|
||||
' Logger.Debug("Exportfilename is: " & oTempFilename)
|
||||
' ' den Dateiinhalt der neuen Datei zuweisen
|
||||
' ExportFileIO.bstrOriginalFileName = oTempFilename
|
||||
' ExportFileIO.aWMStream = oWMStream
|
||||
|
||||
' 'Das eigentliche kopieren
|
||||
' ExportFileIO.ExportOriginal(True)
|
||||
' ' close the windream file stream
|
||||
' oWMStream.Close()
|
||||
' If File.Exists(oTempFilename) Then
|
||||
' clsCURRENT.EXPORTED_FILENAME = oTempFilename
|
||||
' Logger.Info($"File Export to HDD [{clsCURRENT.EXPORTED_FILENAME}]was successfull (File.Exists = True)!")
|
||||
' aktfile_Exportresult = clsCURRENT.EXPORTED_FILENAME
|
||||
' clsCURRENT.TEMP_FILES.Add(clsCURRENT.EXPORTED_FILENAME)
|
||||
' Logger.Debug("FileInfo Added to variables...")
|
||||
' Return True
|
||||
' Else
|
||||
' Logger.Warn($"Export not successfull or File.Exists = false Export: [{oTempFilename}]")
|
||||
' Return False
|
||||
' End If
|
||||
|
||||
' Catch ex As Exception
|
||||
' Logger.Error(ex)
|
||||
' Logger.Info("Unexpected error in Export_WMFile: " & ex.Message)
|
||||
' Return False
|
||||
' End Try
|
||||
'End Function
|
||||
|
||||
|
||||
'Kopiert die übergebene Datei in den Zielpfad
|
||||
'Public Function Export_File(oWMFile As WMObject, oZielpfad As String)
|
||||
|
||||
@@ -188,16 +188,16 @@ Public Class DDWDResultHandler
|
||||
Logger.Info("Keine aktiven Profile WMResulthandler vorhanden")
|
||||
notcompleted = True
|
||||
End If
|
||||
Try
|
||||
For Each _file In clsCURRENT.TEMP_FILES
|
||||
'Dim oFile As New FileInfo(_file)
|
||||
'If (DateTime.UtcNow - oFile.CreationTimeUtc > TimeSpan.FromDays(1)) Then
|
||||
System.IO.File.Delete(_file)
|
||||
'End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
'Try
|
||||
' For Each _file In clsCURRENT.TEMP_FILES
|
||||
' 'Dim oFile As New FileInfo(_file)
|
||||
' 'If (DateTime.UtcNow - oFile.CreationTimeUtc > TimeSpan.FromDays(1)) Then
|
||||
' System.IO.File.Delete(_file)
|
||||
' 'End If
|
||||
' Next
|
||||
'Catch ex As Exception
|
||||
|
||||
End Try
|
||||
'End Try
|
||||
|
||||
_database.Execute_non_Query("UPDATE TBWMRH_KONFIGURATION SET LAST_TICK = GETDATE() WHERE GUID = 1")
|
||||
If oFirstRun = True Then
|
||||
|
||||
Reference in New Issue
Block a user