WIP: EDMI: Improve Error Handling
This commit is contained in:
@@ -301,6 +301,13 @@ Public Class EDMIService
|
||||
#End Region
|
||||
|
||||
#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
|
||||
Dim oDocumentType As String = "DummyDocumentType"
|
||||
Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName)
|
||||
@@ -350,7 +357,7 @@ Public Class EDMIService
|
||||
Dim oPath As String = MSSQL.GetScalarValue(oSQL)
|
||||
|
||||
If IsNothing(oPath) Then
|
||||
Return Nothing
|
||||
Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!")
|
||||
End If
|
||||
|
||||
Dim oFullPath = EDMIPath.GetActivePathFromRelativePath(oPath)
|
||||
@@ -358,17 +365,29 @@ Public Class EDMIService
|
||||
_logger.Debug("GetFileByObjectId: Loading file [{0}]", 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 {
|
||||
.FileName = oFileInfo.Name,
|
||||
.FileContents = oSource
|
||||
.FileContents = oDestination
|
||||
}
|
||||
|
||||
Return oMessage
|
||||
Catch ex As IOException
|
||||
_logger.Error(ex)
|
||||
Throw New FaultException($"Object [{Data.ObjectId}] could not be streamed!")
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return Nothing
|
||||
Throw New FaultException(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user