WIP: EDMI Service

This commit is contained in:
Jonathan Jenne
2020-04-15 12:09:01 +02:00
parent a20c0eb4b0
commit 62e4e409a6
17 changed files with 226 additions and 117 deletions

View File

@@ -137,7 +137,7 @@ Public Class EDMIService
#End Region
#Region "Document (with FileContainer)"
Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IEDMIService.NewFile
Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResultOld Implements IEDMIService.NewFile
Try
Dim oContainer As FileContainer
Dim oContainerId As String
@@ -169,14 +169,14 @@ Public Class EDMIService
_logger.Debug("File saved in Container!", FileName)
Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName)
Return New DocumentResult(oDocument)
Return New DocumentResultOld(oDocument)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult(ex.Message)
Return New DocumentResultOld(ex.Message)
End Try
End Function
Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResult Implements IEDMIService.UpdateFile
Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResultOld Implements IEDMIService.UpdateFile
Try
TestFileExists(DocObject.ContainerId)
@@ -189,14 +189,14 @@ Public Class EDMIService
oFileContainer.Save()
Return New DocumentResult(DocObject)
Return New DocumentResultOld(DocObject)
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetFile(DocObject As DocumentObject) As DocumentResult Implements IEDMIService.GetFile
Public Function GetFile(DocObject As DocumentObject) As DocumentResultOld Implements IEDMIService.GetFile
Try
TestFileExists(DocObject.ContainerId)
@@ -204,10 +204,10 @@ Public Class EDMIService
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
Dim oContents As Byte() = oContainer.GetFile().Contents
Return New DocumentResult(DocObject, oContents)
Return New DocumentResultOld(DocObject, oContents)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult(ex.Message)
Return New DocumentResultOld(ex.Message)
End Try
End Function
@@ -243,13 +243,13 @@ Public Class EDMIService
End If
End Sub
Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResult Implements IEDMIService.GetDocumentByDocumentId
Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResultOld Implements IEDMIService.GetDocumentByDocumentId
Try
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE GUID = {DocumentId}"
Dim oTable = Firebird.GetDatatable(oSQL)
If oTable.Rows.Count = 0 Then
Return New DocumentResult("Document not found")
Return New DocumentResultOld("Document not found")
End If
Dim oRow As DataRow = oTable.Rows.Item(0)
@@ -265,19 +265,19 @@ Public Class EDMIService
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
Dim oContents As Byte() = oContainer.GetFile().Contents
Return New DocumentResult(oDocument, oContents)
Return New DocumentResultOld(oDocument, oContents)
Catch ex As Exception
Return New DocumentResult(ex.Message)
Return New DocumentResultOld(ex.Message)
End Try
End Function
Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResult Implements IEDMIService.GetDocumentByContainerId
Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld Implements IEDMIService.GetDocumentByContainerId
Try
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE CONTAINER_ID = '{ContainerId}'"
Dim oTable = Firebird.GetDatatable(oSQL)
If oTable.Rows.Count = 0 Then
Return New DocumentResult("Document not found")
Return New DocumentResultOld("Document not found")
End If
Dim oRow As DataRow = oTable.Rows.Item(0)
@@ -293,26 +293,26 @@ Public Class EDMIService
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
Dim oContents As Byte() = oContainer.GetFile().Contents
Return New DocumentResult(oDocument, oContents)
Return New DocumentResultOld(oDocument, oContents)
Catch ex As Exception
Return New DocumentResult(ex.Message)
Return New DocumentResultOld(ex.Message)
End Try
End Function
#End Region
#Region "Document"
Public Function ImportFile(FileName As String, Contents() As Byte, AddedWho As String) As DocumentResult2 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 oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName)
Dim oAbsolutePath As String = EDMIPath.GetActivePath(oDocumentType, FileName)
Dim oDirectoryPath = EDMIPath.GetActivePath(oDocumentType)
Dim oDocument = New DocumentResult2.DocumentObject With {.FileName = FileName}
Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName}
Try
Directory.CreateDirectory(oDirectoryPath)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult2(ex.Message)
Return New DocumentResult(ex.Message)
End Try
Try
@@ -337,16 +337,16 @@ Public Class EDMIService
oDocument.FileId = oObjectId
Return New DocumentResult2(oDocument)
Return New DocumentResult(oDocument)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult2(ex.Message)
Return New DocumentResult(ex.Message)
End Try
End Function
Public Function GetFileByObjectId(ObjectId As Int64) As Stream Implements IEDMIService.GetFileByObjectId
Public Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse Implements IEDMIService.GetFileByObjectId
Try
Dim oSQL As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {ObjectId}"
Dim oSQL As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
Dim oPath As String = MSSQL.GetScalarValue(oSQL)
If IsNothing(oPath) Then
@@ -357,8 +357,15 @@ 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)
Return oSource
Dim oMessage As New Messages.DocumentStreamResponse() With {
.FileName = oFileInfo.Name,
.FileContents = oSource
}
Return oMessage
Catch ex As Exception
_logger.Error(ex)
Return Nothing