diff --git a/GUIs.Common/Base/BaseErrorHandler.vb b/GUIs.Common/Base/BaseErrorHandler.vb index 1acb2b71..dc79a380 100644 --- a/GUIs.Common/Base/BaseErrorHandler.vb +++ b/GUIs.Common/Base/BaseErrorHandler.vb @@ -27,7 +27,7 @@ Namespace Base Public Sub ShowErrorMessage(Exception As Exception, Origin As String, Message As String) _Logger.Error(Exception) - MessageBox.Show(Message, _Form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) + MessageBox.Show(Message & vbNewLine & Exception?.Message, _Form.Text & Origin, MessageBoxButtons.OK, MessageBoxIcon.Error) End Sub Public Sub ShowErrorMessage(Text As String) diff --git a/GUIs.Common/DocumentResultList/Watcher.vb b/GUIs.Common/DocumentResultList/Watcher.vb index c529cf7d..4abf9df4 100644 --- a/GUIs.Common/DocumentResultList/Watcher.vb +++ b/GUIs.Common/DocumentResultList/Watcher.vb @@ -61,8 +61,7 @@ Namespace DocumentResultList Dim oResult As Tuple(Of Integer, String) = Nothing If pDocument.FullPath IsNot Nothing AndAlso pDocument.FullPath.Trim <> String.Empty Then - ' TODO: DONT put into openfiles - oResult = Await OpenFileFromPath(pDocument) + oResult = OpenFileFromPath(pDocument) ElseIf pDocument.Extension IsNot Nothing AndAlso pDocument.Contents IsNot Nothing Then oResult = Await OpenFileFromByteArray(pDocument) @@ -133,10 +132,11 @@ Namespace DocumentResultList End Try End Function - Private Async Function OpenFileFromPath(pDocument As Document) As Task(Of Tuple(Of Integer, String)) + Private Function OpenFileFromPath(pDocument As Document) As Tuple(Of Integer, String) Try Dim oProcessId = DoOpenFile(pDocument.FullPath) - Return New Tuple(Of Integer, String)(oProcessId, pDocument.FullPath) + Dim oResult = New Tuple(Of Integer, String)(oProcessId, pDocument.FullPath) + Return oResult Catch ex As Exception Logger.Error(ex) @@ -145,19 +145,26 @@ Namespace DocumentResultList End Function Private Function DoOpenFile(pFilePath As String) As Integer - Dim _Process = New Process - _Process.StartInfo.FileName = pFilePath - _Process.EnableRaisingEvents = True + Try + Dim _Process = New Process + _Process.StartInfo.FileName = pFilePath + _Process.EnableRaisingEvents = True - AddHandler _Process.Exited, AddressOf Process_Exited + If EnableWatching = True Then + AddHandler _Process.Exited, AddressOf Process_Exited + End If - _Process.Start() + _Process.Start() - Return _Process.Id + Return _Process.Id + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try End Function Private Function Process_Exited(sender As Object, e As EventArgs) As Boolean - Debug.WriteLine("Process is exited") + Logger.Debug("Process is exited") Dim oProcess As Process = sender Dim oOpenFile = OpenFiles. @@ -175,7 +182,7 @@ Namespace DocumentResultList ' All files that are currently processe/updated on the outside, ' will not be checked again. Dim oFileIsProcessed = ProcessedFiles.Contains(oOpenFile) - Debug.WriteLine($"File is processed: [{oFileIsProcessed}]") + Logger.Debug($"File is processed: [{oFileIsProcessed}]") If oFileIsProcessed = True Then Continue For @@ -184,8 +191,8 @@ Namespace DocumentResultList ' Check if the file is currently in use, and skip if it is. Dim oIsLocked = FileEx.TestFileIsLocked(oOpenFile.FilePath) Dim oIsExited = oOpenFile.Exited - Debug.WriteLine($"File is locked: [{oIsLocked}]") - Debug.WriteLine($"File is exited: [{oIsExited}]") + Logger.Debug($"File is locked: [{oIsLocked}]") + Logger.Debug($"File is exited: [{oIsExited}]") If oIsLocked Or oIsExited = False Then Continue For @@ -194,15 +201,15 @@ Namespace DocumentResultList ' If this point is reached, we assume the file was closed again after opening it. ' ------ - Debug.WriteLine($"File Closed") + Logger.Debug($"File Closed") ' Compute the current hash of the file and compare it with the one ' in the database. Dim oOldHash = oOpenFile.Document.FileHash Dim oNewHash = FileEx.GetChecksum(oOpenFile.FilePath) - Debug.WriteLine($"Old Hash: [{oOldHash}]") - Debug.WriteLine($"New Hash: [{oNewHash}]") + Logger.Debug($"Old Hash: [{oOldHash}]") + Logger.Debug($"New Hash: [{oNewHash}]") ' If the the file did not change, remove it from the watch list If oNewHash.Equals(oOldHash) Then @@ -214,7 +221,7 @@ Namespace DocumentResultList ' If this point is reached, we assume the file changed. ' ------ - Debug.WriteLine($"File Changed") + Logger.Debug($"File Changed") ' The File changed, so mark the file as being processed/updated ' and notify any listeners of the FileChanged event diff --git a/GUIs.Common/frmDocumentResultList.vb b/GUIs.Common/frmDocumentResultList.vb index c4869ff3..0ca3d276 100644 --- a/GUIs.Common/frmDocumentResultList.vb +++ b/GUIs.Common/frmDocumentResultList.vb @@ -198,7 +198,7 @@ Public Class frmDocumentResultList chkGridShowTitle.Checked = LayoutManager.GetBandTitleVisible() Catch ex As Exception - ErrorHandler.ShowErrorMessage(ex, "Error while loading results", "Form Load") + ErrorHandler.ShowErrorMessage(ex, "Form Load", "Error while loading results") Finally IsLoading = False