WIP: EDMI: Improve Error Handling

This commit is contained in:
Jonathan Jenne 2020-04-15 14:44:42 +02:00
parent 62e4e409a6
commit b7a5f4d4a3
3 changed files with 32 additions and 6 deletions

View File

@ -115,6 +115,9 @@ Public Class Form1
Private Async Sub ButtonLoadFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonLoadFile.ItemClick Private Async Sub ButtonLoadFile_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonLoadFile.ItemClick
Try Try
Dim oSWTotal As New Stopwatch()
oSWTotal.Start()
If TextboxObejctId.EditValue = "" Then If TextboxObejctId.EditValue = "" Then
MsgBox("Please enter an object id!", MsgBoxStyle.Exclamation, "Uh oh!") MsgBox("Please enter an object id!", MsgBoxStyle.Exclamation, "Uh oh!")
End If End If
@ -126,9 +129,12 @@ Public Class Form1
oResponse.FileContents.CopyTo(oMemoryStream) oResponse.FileContents.CopyTo(oMemoryStream)
oMemoryStream.Position = 0 oMemoryStream.Position = 0
listboxLog.Items.Add("Stream read!")
DocumentViewer1.LoadFile(oResponse.FileName, oMemoryStream) DocumentViewer1.LoadFile(oResponse.FileName, oMemoryStream)
oSWTotal.Stop()
listboxLog.Items.Add($"File [{oResponse.FileName}] loaded: [{FormatTime(oSWTotal.ElapsedMilliseconds)}]")
Catch ex As FaultException
MsgBox(ex.Reason.ToString, MsgBoxStyle.Critical, "Error from Service")
Catch ex As Exception Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Uh oh!") MsgBox(ex.Message, MsgBoxStyle.Critical, "Uh oh!")
End Try End Try

View File

@ -301,6 +301,13 @@ Public Class EDMIService
#End Region #End Region
#Region "Document" #Region "Document"
''' <summary>
'''
''' </summary>
''' <param name="FileName"></param>
''' <param name="Contents"></param>
''' <param name="AddedWho"></param>
''' <returns></returns>
Public Function ImportFile(FileName As String, Contents() As Byte, AddedWho As String) As DocumentResult Implements IEDMIService.ImportFile Public Function ImportFile(FileName As String, Contents() As Byte, AddedWho As String) As DocumentResult Implements IEDMIService.ImportFile
Dim oDocumentType As String = "DummyDocumentType" Dim oDocumentType As String = "DummyDocumentType"
Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName) Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName)
@ -350,7 +357,7 @@ Public Class EDMIService
Dim oPath As String = MSSQL.GetScalarValue(oSQL) Dim oPath As String = MSSQL.GetScalarValue(oSQL)
If IsNothing(oPath) Then If IsNothing(oPath) Then
Return Nothing Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!")
End If End If
Dim oFullPath = EDMIPath.GetActivePathFromRelativePath(oPath) Dim oFullPath = EDMIPath.GetActivePathFromRelativePath(oPath)
@ -358,17 +365,29 @@ Public Class EDMIService
_logger.Debug("GetFileByObjectId: Loading file [{0}]", oFullPath) _logger.Debug("GetFileByObjectId: Loading file [{0}]", oFullPath)
Dim oFileInfo As New FileInfo(oFullPath) Dim oFileInfo As New FileInfo(oFullPath)
Dim oSource As FileStream = IO.File.Open(oFullPath, FileMode.Open)
If Not oFileInfo.Exists Then
Throw New FaultException($"Object [{Data.ObjectId}] does not exist on filesystem!")
End If
Dim oDestination As New MemoryStream()
Using oSource As FileStream = IO.File.OpenRead(oFullPath)
oSource.CopyTo(oDestination)
End Using
oDestination.Seek(0, SeekOrigin.Begin)
Dim oMessage As New Messages.DocumentStreamResponse() With { Dim oMessage As New Messages.DocumentStreamResponse() With {
.FileName = oFileInfo.Name, .FileName = oFileInfo.Name,
.FileContents = oSource .FileContents = oDestination
} }
Return oMessage Return oMessage
Catch ex As IOException
_logger.Error(ex)
Throw New FaultException($"Object [{Data.ObjectId}] could not be streamed!")
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
Return Nothing Throw New FaultException(ex.Message)
End Try End Try
End Function End Function

View File

@ -71,6 +71,7 @@
<HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath> <HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />