Unterstützung für MSG/EML-Dateien hinzugefügt

Aktualisierung der `App.config` mit neuen `bindingRedirect`-Versionen und Hinzufügen von Abhängigkeiten wie `OpenMcdf` und `Microsoft.Bcl.AsyncInterfaces`.
Erweiterung von `DocumentViewer.vb` zur Unterstützung von `.MSG`- und `.EML`-Dateien, inklusive Konvertierung von `.MSG` zu HTML.
Verbesserte Fehlerbehandlung und Logging.
Einführung der Eigenschaft `SnappingEnabled` in `SnapPanel.vb` und Optimierung des Rasters.
Erweiterte Validierung und Logging in `frmDocumentResultList.vb`.
Aktualisierung der Projektdateien mit neuen Paketverweisen und Abhängigkeitsversionen.
Anpassung der Assembly-Versionen in `AssemblyInfo.vb`.
This commit is contained in:
Developer01
2026-10-26 11:23:37 +01:00
parent e1f670875a
commit 6aa691e1a0
8 changed files with 243 additions and 97 deletions

View File

@@ -7,7 +7,7 @@ Imports GdPicture14
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Messaging
Imports DigitalData.Modules.Config
Imports MsgReader
Public Class DocumentViewer
Private Enum ZoomMode
Zoom50
@@ -513,12 +513,16 @@ Public Class DocumentViewer
End Sub
Public Sub DeleteTempFiles()
For Each oFile In _TempFiles
For Each oPath In _TempFiles
Try
_logger.Debug("Deleting temp file [{0}]", oFile)
File.Delete(oFile)
_logger.Debug("Deleting temp path [{0}]", oPath)
If Directory.Exists(oPath) Then
Directory.Delete(oPath, True)
ElseIf File.Exists(oPath) Then
File.Delete(oPath)
End If
Catch ex As Exception
_logger.Warn("Could not delete temp file [{0}]", oFile)
_logger.Warn("Could not delete temp path [{0}]", oPath)
End Try
Next
End Sub
@@ -530,7 +534,7 @@ Public Class DocumentViewer
Select Case Extension.ToUpper
Case ".CSV"
_ViewerMode = ViewerMode.Excel
Case ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT"
Case ".DOC", ".DOCX", ".ODT", ".RTF", ".TXT", ".MSG", ".EML"
_ViewerMode = ViewerMode.Richtext
Case Else
_ViewerMode = ViewerMode.GDPicture
@@ -702,22 +706,109 @@ Public Class DocumentViewer
HideGdViewer()
End Sub
''' <summary>
''' Lädt eine Richtext-kompatible Datei in den RichEditControl.
''' MSG-Dateien werden vor dem Laden in HTML konvertiert.
''' </summary>
Private Function LoadRichtextFile(FilePath As String, Extension As String) As Boolean
Try
RichEditControl1.LoadDocument(FilePath, GetDocumentFormat(Extension))
' Eingabevalidierung
If String.IsNullOrEmpty(FilePath) Then
_logger.Warn("LoadRichtextFile: FilePath ist leer oder Nothing")
Return False
End If
If String.IsNullOrEmpty(Extension) Then
_logger.Warn("LoadRichtextFile: Extension ist leer oder Nothing für Datei [{0}]", FilePath)
Return False
End If
If Not IO.File.Exists(FilePath) Then
_logger.Warn("LoadRichtextFile: Datei existiert nicht [{0}]", FilePath)
ShowFileNotLoadedError(FilePath)
Return False
End If
_logger.Debug("LoadRichtextFile: Starte Laden von [{0}] mit Extension [{1}]", FilePath, Extension)
Dim oLoadPath As String = FilePath
Dim oFormat = GetDocumentFormat(Extension)
' MSG-Dateien müssen zuerst in HTML konvertiert werden
If Extension = ".MSG" Then
_logger.Info("LoadRichtextFile: MSG erkannt – starte Konvertierung zu HTML")
oLoadPath = ConvertMsgToMht(FilePath)
If String.IsNullOrEmpty(oLoadPath) Then
_logger.Warn("LoadRichtextFile: Konvertierung hat keinen Pfad zurückgegeben für [{0}]", FilePath)
ShowFileNotLoadedError(FilePath)
Return False
End If
If Not IO.File.Exists(oLoadPath) Then
_logger.Warn("LoadRichtextFile: Konvertierte HTML-Datei existiert nicht [{0}]", oLoadPath)
ShowFileNotLoadedError(FilePath)
Return False
End If
oFormat = XtraRichEdit.DocumentFormat.Html
_logger.Debug("LoadRichtextFile: MSG konvertiert zu [{0}], Format: Html", oLoadPath)
End If
_logger.Debug("LoadRichtextFile: Rufe RichEditControl1.LoadDocument auf – Pfad: [{0}], Format: [{1}]", oLoadPath, oFormat)
RichEditControl1.LoadDocument(oLoadPath, oFormat)
RichEditControl1.Visible = True
RichEditControl1.Dock = DockStyle.Fill
_ViewOverride = "Richtext"
_ViewerMode = ViewerMode.Richtext
lblInfo.Visible = True
lblInfo.Text = "This docx-file contains a generic error and will be displayed in a reduced viewer. Please try to open the file in WORD"
_ViewOverride = ""
lblInfo.Visible = False
_logger.Info("LoadRichtextFile: Erfolgreich geladen [{0}]", FilePath)
Return True
Catch ex As Exception
_logger.Error(ex)
ShowFileNotLoadedError(FilePath)
Return False
End Try
End Function
''' <summary>
''' Konvertiert eine MSG-Datei in eine temporäre MHT-Datei und gibt deren Pfad zurück.
''' </summary>
Private Function ConvertMsgToMht(MsgFilePath As String) As String
Try
_logger.Info("Converting MSG to MHT: [{0}]", MsgFilePath)
Dim oTempDir = Path.Combine(Path.GetTempPath(), "DocViewer_" & Guid.NewGuid().ToString("N"))
Directory.CreateDirectory(oTempDir)
Dim oReader As New MsgReader.Reader()
oReader.ExtractToFolder(MsgFilePath, oTempDir)
' MsgReader erzeugt eine .htm/.html Datei im Zielordner
Dim oHtmlFile = Directory.GetFiles(oTempDir, "*.htm").FirstOrDefault()
If oHtmlFile Is Nothing Then
oHtmlFile = Directory.GetFiles(oTempDir, "*.html").FirstOrDefault()
End If
If String.IsNullOrEmpty(oHtmlFile) Then
_logger.Warn("MSG conversion produced no HTML file in [{0}]", oTempDir)
Return String.Empty
End If
' Temporäres Verzeichnis für späteres Aufräumen merken
_TempFiles.Add(oTempDir)
_logger.Info("MSG converted to [{0}]", oHtmlFile)
Return oHtmlFile
Catch ex As Exception
_logger.Error(ex)
Return String.Empty
End Try
End Function
Private Function LoadSpreadsheetFile(FilePath As String, Extension As String) As Boolean
Try
_logger.Debug("Loading Spreadsheet: {0}", FilePath)
@@ -742,14 +833,22 @@ Public Class DocumentViewer
Try
_logger.Debug("Loading GdPicture: {0}", FilePath)
' Set force temporary mode for specific file types
' DWG/DXF: Spezielle GdPicture-Einstellungen für bessere CAD-Darstellung
If Extension = ".DWG" OrElse Extension = ".DXF" Then
_logger.Info("LoadGdPictureFile: CAD-Datei erkannt – setze optimierte Darstellungsoptionen")
MyGDPViewer.BackColor = Color.White
MyGDPViewer.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
MyGDPViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentMiddleCenter
Else
MyGDPViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
End If
Select Case Extension
Case ".EML", ".DOC", ".DOCX", ".XLS", ".XLSX", ".ODT", ".RTF", ".TXT"
Case ".EML", ".MSG", ".DOC", ".DOCX", ".XLS", ".XLSX", ".ODT", ".RTF", ".TXT"
MyGDPViewer.ForceTemporaryMode = True
_logger.Info("ForceTemporaryMode enabled for extension [{0}]", Extension)
End Select
MyGDPViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter
If Viewer_ForceTemporaryMode Then
MyGDPViewer.ForceTemporaryMode = True
End If
@@ -759,8 +858,6 @@ Public Class DocumentViewer
If oGDPState <> GdPictureStatus.OK Then
_logger.Warn("GdPictureStatus: {0}", oGDPState)
' Fallback to Richtext for corrupted DOCX
If Extension = ".DOCX" AndAlso oGDPState = GdPictureStatus.GenericError Then
HideGdViewer()
Return LoadRichtextFile(FilePath, Extension)
@@ -927,6 +1024,7 @@ Public Class DocumentViewer
Select Case Extension.ToUpper
Case ".EML" : oFormat = XtraRichEdit.DocumentFormat.Mht
Case ".MSG" : oFormat = XtraRichEdit.DocumentFormat.Mht
Case ".DOC" : oFormat = XtraRichEdit.DocumentFormat.Doc
Case ".DOCX" : oFormat = XtraRichEdit.DocumentFormat.OpenXml
Case ".ODT" : oFormat = XtraRichEdit.DocumentFormat.OpenDocument