Common: fix crash

This commit is contained in:
Jonathan Jenne 2022-04-05 16:36:04 +02:00
parent b6f84c4fb8
commit a5e4274659
3 changed files with 27 additions and 20 deletions

View File

@ -27,7 +27,7 @@ Namespace Base
Public Sub ShowErrorMessage(Exception As Exception, Origin As String, Message As String) Public Sub ShowErrorMessage(Exception As Exception, Origin As String, Message As String)
_Logger.Error(Exception) _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 End Sub
Public Sub ShowErrorMessage(Text As String) Public Sub ShowErrorMessage(Text As String)

View File

@ -61,8 +61,7 @@ Namespace DocumentResultList
Dim oResult As Tuple(Of Integer, String) = Nothing Dim oResult As Tuple(Of Integer, String) = Nothing
If pDocument.FullPath IsNot Nothing AndAlso pDocument.FullPath.Trim <> String.Empty Then If pDocument.FullPath IsNot Nothing AndAlso pDocument.FullPath.Trim <> String.Empty Then
' TODO: DONT put into openfiles oResult = OpenFileFromPath(pDocument)
oResult = Await OpenFileFromPath(pDocument)
ElseIf pDocument.Extension IsNot Nothing AndAlso pDocument.Contents IsNot Nothing Then ElseIf pDocument.Extension IsNot Nothing AndAlso pDocument.Contents IsNot Nothing Then
oResult = Await OpenFileFromByteArray(pDocument) oResult = Await OpenFileFromByteArray(pDocument)
@ -133,10 +132,11 @@ Namespace DocumentResultList
End Try End Try
End Function 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 Try
Dim oProcessId = DoOpenFile(pDocument.FullPath) 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 Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
@ -145,19 +145,26 @@ Namespace DocumentResultList
End Function End Function
Private Function DoOpenFile(pFilePath As String) As Integer Private Function DoOpenFile(pFilePath As String) As Integer
Try
Dim _Process = New Process Dim _Process = New Process
_Process.StartInfo.FileName = pFilePath _Process.StartInfo.FileName = pFilePath
_Process.EnableRaisingEvents = True _Process.EnableRaisingEvents = True
If EnableWatching = True Then
AddHandler _Process.Exited, AddressOf Process_Exited 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 End Function
Private Function Process_Exited(sender As Object, e As EventArgs) As Boolean 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 oProcess As Process = sender
Dim oOpenFile = OpenFiles. Dim oOpenFile = OpenFiles.
@ -175,7 +182,7 @@ Namespace DocumentResultList
' All files that are currently processe/updated on the outside, ' All files that are currently processe/updated on the outside,
' will not be checked again. ' will not be checked again.
Dim oFileIsProcessed = ProcessedFiles.Contains(oOpenFile) Dim oFileIsProcessed = ProcessedFiles.Contains(oOpenFile)
Debug.WriteLine($"File is processed: [{oFileIsProcessed}]") Logger.Debug($"File is processed: [{oFileIsProcessed}]")
If oFileIsProcessed = True Then If oFileIsProcessed = True Then
Continue For Continue For
@ -184,8 +191,8 @@ Namespace DocumentResultList
' Check if the file is currently in use, and skip if it is. ' Check if the file is currently in use, and skip if it is.
Dim oIsLocked = FileEx.TestFileIsLocked(oOpenFile.FilePath) Dim oIsLocked = FileEx.TestFileIsLocked(oOpenFile.FilePath)
Dim oIsExited = oOpenFile.Exited Dim oIsExited = oOpenFile.Exited
Debug.WriteLine($"File is locked: [{oIsLocked}]") Logger.Debug($"File is locked: [{oIsLocked}]")
Debug.WriteLine($"File is exited: [{oIsExited}]") Logger.Debug($"File is exited: [{oIsExited}]")
If oIsLocked Or oIsExited = False Then If oIsLocked Or oIsExited = False Then
Continue For Continue For
@ -194,15 +201,15 @@ Namespace DocumentResultList
' If this point is reached, we assume the file was closed again after opening it. ' 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 ' Compute the current hash of the file and compare it with the one
' in the database. ' in the database.
Dim oOldHash = oOpenFile.Document.FileHash Dim oOldHash = oOpenFile.Document.FileHash
Dim oNewHash = FileEx.GetChecksum(oOpenFile.FilePath) Dim oNewHash = FileEx.GetChecksum(oOpenFile.FilePath)
Debug.WriteLine($"Old Hash: [{oOldHash}]") Logger.Debug($"Old Hash: [{oOldHash}]")
Debug.WriteLine($"New Hash: [{oNewHash}]") Logger.Debug($"New Hash: [{oNewHash}]")
' If the the file did not change, remove it from the watch list ' If the the file did not change, remove it from the watch list
If oNewHash.Equals(oOldHash) Then If oNewHash.Equals(oOldHash) Then
@ -214,7 +221,7 @@ Namespace DocumentResultList
' If this point is reached, we assume the file changed. ' 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 ' The File changed, so mark the file as being processed/updated
' and notify any listeners of the FileChanged event ' and notify any listeners of the FileChanged event

View File

@ -198,7 +198,7 @@ Public Class frmDocumentResultList
chkGridShowTitle.Checked = LayoutManager.GetBandTitleVisible() chkGridShowTitle.Checked = LayoutManager.GetBandTitleVisible()
Catch ex As Exception Catch ex As Exception
ErrorHandler.ShowErrorMessage(ex, "Error while loading results", "Form Load") ErrorHandler.ShowErrorMessage(ex, "Form Load", "Error while loading results")
Finally Finally
IsLoading = False IsLoading = False