Common: Add a LOG of logging for loading files from idb
This commit is contained in:
parent
27a757f8d0
commit
c470fd8f6e
@ -241,7 +241,7 @@ Public Class frmDocumentResultList
|
|||||||
Private Function LoadFile_IDB(GridRow As DataRow) As DocumentResultInfo
|
Private Function LoadFile_IDB(GridRow As DataRow) As DocumentResultInfo
|
||||||
Try
|
Try
|
||||||
Dim oObjectId = GridRow.Item(COLUMN_DOCID)
|
Dim oObjectId = GridRow.Item(COLUMN_DOCID)
|
||||||
_Logger.Debug($"Getting Information for oObjectId: {oObjectId}")
|
_Logger.Debug("Loading Information for ObjectId: [{0}]", oObjectId)
|
||||||
|
|
||||||
' This needs to be Sync bc otherwise the PopupMenuShowing event will fire before this method loaded the Document Info
|
' This needs to be Sync bc otherwise the PopupMenuShowing event will fire before this method loaded the Document Info
|
||||||
Dim oDocumentInfo As DocumentInfo = _IDBClient.GetDocumentInfo(_Environment.User.UserId, oObjectId)
|
Dim oDocumentInfo As DocumentInfo = _IDBClient.GetDocumentInfo(_Environment.User.UserId, oObjectId)
|
||||||
@ -249,34 +249,47 @@ Public Class frmDocumentResultList
|
|||||||
.AccessRight = oDocumentInfo.AccessRight,
|
.AccessRight = oDocumentInfo.AccessRight,
|
||||||
.FullPath = oDocumentInfo.FullPath
|
.FullPath = oDocumentInfo.FullPath
|
||||||
}
|
}
|
||||||
|
_Logger.Debug("Successfully loaded Information for ObjectId: [{0}]", oObjectId)
|
||||||
|
|
||||||
|
_Logger.Debug("Loading file [{0}]", oResultDocumentInfo.FullPath)
|
||||||
If File.Exists(oResultDocumentInfo.FullPath) Then
|
If File.Exists(oResultDocumentInfo.FullPath) Then
|
||||||
oResultDocumentInfo = LoadFile_AsByteArray(oResultDocumentInfo)
|
oResultDocumentInfo = LoadFile_AsByteArray(oResultDocumentInfo)
|
||||||
_OpenDocuments.Add(oResultDocumentInfo)
|
_OpenDocuments.Add(oResultDocumentInfo)
|
||||||
_CurrentDocument = oResultDocumentInfo
|
_CurrentDocument = oResultDocumentInfo
|
||||||
|
Else
|
||||||
|
_Logger.Warn("File [{0}] does not exist.", oResultDocumentInfo.FullPath)
|
||||||
End If
|
End If
|
||||||
_Logger.Debug($"Got Info for oObjectId: {oObjectId}!")
|
_Logger.Debug("Successfully loaded File [{0}]", oResultDocumentInfo.FullPath)
|
||||||
|
|
||||||
Return oResultDocumentInfo
|
Return oResultDocumentInfo
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
Return Nothing
|
Return Nothing
|
||||||
|
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function LoadFile_AsByteArray(DocumentInfo As DocumentResultInfo) As DocumentResultInfo
|
Private Function LoadFile_AsByteArray(DocumentInfo As DocumentResultInfo) As DocumentResultInfo
|
||||||
Try
|
Try
|
||||||
|
_Logger.Debug("Loading File [{0}]", DocumentInfo.FullPath)
|
||||||
Dim oFullPath As String = DocumentInfo.FullPath
|
Dim oFullPath As String = DocumentInfo.FullPath
|
||||||
Dim oPathExists = From oFile In _OpenDocuments
|
Dim oPathExists = From oFile In _OpenDocuments
|
||||||
Where oFile.FullPath = oFullPath And oFile.Contents IsNot Nothing
|
Where oFile.FullPath = oFullPath And oFile.Contents IsNot Nothing
|
||||||
Select oFile
|
Select oFile
|
||||||
|
|
||||||
Dim oExistsInCache = oPathExists.Count() > 0
|
Dim oExistsInCache = oPathExists.Count() > 0
|
||||||
Dim oSizeChanged = False
|
Dim oSizeChanged = False
|
||||||
Dim oWriteTimeChanged = False
|
Dim oWriteTimeChanged = False
|
||||||
|
|
||||||
|
_Logger.Debug("File exists in Cache: [{0}]", oExistsInCache)
|
||||||
|
|
||||||
' Get Information about the file on the filesystem
|
' Get Information about the file on the filesystem
|
||||||
Dim oFileInfo As New FileInfo(oFullPath)
|
Dim oFileInfo As New FileInfo(oFullPath)
|
||||||
|
|
||||||
If oExistsInCache Then
|
If oExistsInCache Then
|
||||||
|
_Logger.Debug("Loading file from cache.")
|
||||||
|
|
||||||
Dim oCachedItem = oPathExists.First()
|
Dim oCachedItem = oPathExists.First()
|
||||||
|
|
||||||
If oCachedItem.Contents Is Nothing Then
|
If oCachedItem.Contents Is Nothing Then
|
||||||
@ -284,37 +297,29 @@ Public Class frmDocumentResultList
|
|||||||
Else
|
Else
|
||||||
oSizeChanged = Not (oFileInfo.Length = oCachedItem.Contents.Length)
|
oSizeChanged = Not (oFileInfo.Length = oCachedItem.Contents.Length)
|
||||||
End If
|
End If
|
||||||
|
_Logger.Debug("Filesize changed: [{0}]", oSizeChanged)
|
||||||
|
|
||||||
If oCachedItem.LastWriteTime = Nothing Then
|
If oCachedItem.LastWriteTime = Nothing Then
|
||||||
oWriteTimeChanged = False
|
oWriteTimeChanged = False
|
||||||
Else
|
Else
|
||||||
oWriteTimeChanged = Not oFileInfo.LastWriteTime.Equals(oCachedItem.LastWriteTime)
|
oWriteTimeChanged = Not oFileInfo.LastWriteTime.Equals(oCachedItem.LastWriteTime)
|
||||||
End If
|
End If
|
||||||
|
_Logger.Debug("Write-time changed: [{0}]", oWriteTimeChanged)
|
||||||
|
|
||||||
If oSizeChanged Or oWriteTimeChanged Then
|
If oSizeChanged Or oWriteTimeChanged Then
|
||||||
Using oStream = File.OpenRead(DocumentInfo.FullPath)
|
_Logger.Debug("Size or Write-time changed, loading from disk.")
|
||||||
Using oMemoryStream = New MemoryStream()
|
|
||||||
oStream.CopyTo(oMemoryStream)
|
|
||||||
DocumentInfo.Contents = oMemoryStream.ToArray()
|
|
||||||
DocumentInfo.LastWriteTime = oFileInfo.LastWriteTime
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
|
|
||||||
Return DocumentInfo
|
Return LoadFile_FromDisk(DocumentInfo, oFileInfo)
|
||||||
Else
|
Else
|
||||||
|
_Logger.Debug("Loading from cache")
|
||||||
|
|
||||||
Return oCachedItem
|
Return oCachedItem
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Else
|
Else
|
||||||
Using oStream = File.OpenRead(DocumentInfo.FullPath)
|
_Logger.Debug("File exists in cache, loading from disk.")
|
||||||
Using oMemoryStream = New MemoryStream()
|
|
||||||
oStream.CopyTo(oMemoryStream)
|
|
||||||
DocumentInfo.Contents = oMemoryStream.ToArray()
|
|
||||||
DocumentInfo.LastWriteTime = oFileInfo.LastWriteTime
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
|
|
||||||
Return DocumentInfo
|
Return LoadFile_FromDisk(DocumentInfo, oFileInfo)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -323,6 +328,22 @@ Public Class frmDocumentResultList
|
|||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
Private Function LoadFile_FromDisk(pDocumentInfo As DocumentResultInfo, pFileInfo As FileInfo) As DocumentResultInfo
|
||||||
|
Using oStream = File.OpenRead(pDocumentInfo.FullPath)
|
||||||
|
_Logger.Debug("File opened.")
|
||||||
|
|
||||||
|
Using oMemoryStream = New MemoryStream()
|
||||||
|
_Logger.Debug("Copying file contents to memory stream.")
|
||||||
|
oStream.CopyTo(oMemoryStream)
|
||||||
|
pDocumentInfo.Contents = oMemoryStream.ToArray()
|
||||||
|
pDocumentInfo.LastWriteTime = pFileInfo.LastWriteTime
|
||||||
|
_Logger.Debug("Successfully copied file contents to memory stream.")
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
|
||||||
|
Return pDocumentInfo
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Function RefreshResults(pResults As IEnumerable(Of BaseResult)) As Boolean Implements IResultForm.RefreshResults
|
Public Function RefreshResults(pResults As IEnumerable(Of BaseResult)) As Boolean Implements IResultForm.RefreshResults
|
||||||
_IsLoading = True
|
_IsLoading = True
|
||||||
Try
|
Try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user