bring EDMIService up to date
This commit is contained in:
@@ -132,167 +132,167 @@ Public Class EDMIService
|
||||
|
||||
#End Region
|
||||
#Region "Document (with FileContainer)"
|
||||
'Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IEDMIService.NewFile
|
||||
' Try
|
||||
' Dim oContainer As FileContainer
|
||||
' Dim oContainerId As String
|
||||
Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IEDMIService.NewFile
|
||||
Try
|
||||
Dim oContainer As FileContainer
|
||||
Dim oContainerId As String
|
||||
|
||||
' If Not TestUserAuth() Then
|
||||
' Throw New Exception($"User {_username} not authorized.")
|
||||
' End If
|
||||
If Not TestUserAuth() Then
|
||||
Throw New Exception($"User {_username} not authorized.")
|
||||
End If
|
||||
|
||||
' oContainer = FileContainer.Create(LogConfig, AppConfig.ContainerPassword)
|
||||
' oContainerId = oContainer.ContainerId
|
||||
' _logger.Debug("Container created with id {0}", oContainerId)
|
||||
oContainer = FileContainer.Create(LogConfig, AppConfig.ContainerPassword)
|
||||
oContainerId = oContainer.ContainerId
|
||||
_logger.Debug("Container created with id {0}", oContainerId)
|
||||
|
||||
' Dim oExtension As String = Path.GetExtension(FileName).Substring(1)
|
||||
' _logger.Debug("File extension of file {0} is {1}", FileName, oExtension)
|
||||
Dim oExtension As String = Path.GetExtension(FileName).Substring(1)
|
||||
_logger.Debug("File extension of file {0} is {1}", FileName, oExtension)
|
||||
|
||||
' Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;"
|
||||
' Dim oDocId As Int64 = Database.GetScalarValue(oSQL)
|
||||
Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;"
|
||||
Dim oDocId As Int64 = Database.GetScalarValue(oSQL)
|
||||
|
||||
' If oDocId = -1 Then
|
||||
' _logger.Warn("Database returned -1 while creating Document Entry. File was not saved!")
|
||||
' Return Nothing
|
||||
' End If
|
||||
If oDocId = -1 Then
|
||||
_logger.Warn("Database returned -1 while creating Document Entry. File was not saved!")
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
' _logger.Debug("Database Entry created with DocId {0}", oDocId)
|
||||
_logger.Debug("Database Entry created with DocId {0}", oDocId)
|
||||
|
||||
' oContainer.SetFile(Contents, FileName)
|
||||
' oContainer.SaveAs(GetContainerPath(oContainerId))
|
||||
oContainer.SetFile(Contents, FileName)
|
||||
oContainer.SaveAs(GetContainerPath(oContainerId))
|
||||
|
||||
' _logger.Debug("File saved in Container!", FileName)
|
||||
_logger.Debug("File saved in Container!", FileName)
|
||||
|
||||
' Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName)
|
||||
' Return New DocumentResult(oDocument)
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Return New DocumentResult(ex.Message)
|
||||
' End Try
|
||||
'End Function
|
||||
Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName)
|
||||
Return New DocumentResult(oDocument)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return New DocumentResult(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResult Implements IEDMIService.UpdateFile
|
||||
' Try
|
||||
' TestFileExists(DocObject.ContainerId)
|
||||
Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResult Implements IEDMIService.UpdateFile
|
||||
Try
|
||||
TestFileExists(DocObject.ContainerId)
|
||||
|
||||
' ' TODO: update db
|
||||
' TODO: update db
|
||||
|
||||
' Dim oFilePath = GetContainerPath(DocObject.ContainerId)
|
||||
' Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath)
|
||||
Dim oFilePath = GetContainerPath(DocObject.ContainerId)
|
||||
Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath)
|
||||
|
||||
' oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName)
|
||||
' oFileContainer.Save()
|
||||
oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName)
|
||||
oFileContainer.Save()
|
||||
|
||||
|
||||
' Return New DocumentResult(DocObject)
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Return Nothing
|
||||
' End Try
|
||||
'End Function
|
||||
Return New DocumentResult(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
|
||||
' Try
|
||||
' TestFileExists(DocObject.ContainerId)
|
||||
Public Function GetFile(DocObject As DocumentObject) As DocumentResult Implements IEDMIService.GetFile
|
||||
Try
|
||||
TestFileExists(DocObject.ContainerId)
|
||||
|
||||
' Dim oContainerPath = GetContainerPath(DocObject.ContainerId)
|
||||
' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
' Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
Dim oContainerPath = GetContainerPath(DocObject.ContainerId)
|
||||
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
|
||||
' Return New DocumentResult(DocObject, oContents)
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Return New DocumentResult(ex.Message)
|
||||
' End Try
|
||||
'End Function
|
||||
Return New DocumentResult(DocObject, oContents)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return New DocumentResult(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile
|
||||
' Try
|
||||
' TestFileExists(DocObject.ContainerId)
|
||||
Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile
|
||||
Try
|
||||
TestFileExists(DocObject.ContainerId)
|
||||
|
||||
' Dim oFilePath = GetContainerPath(DocObject.ContainerId)
|
||||
' IO.File.Delete(oFilePath)
|
||||
Dim oFilePath = GetContainerPath(DocObject.ContainerId)
|
||||
IO.File.Delete(oFilePath)
|
||||
|
||||
' 'TODO: Delete doc from db
|
||||
'TODO: Delete doc from db
|
||||
|
||||
' Return True
|
||||
' Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
' Return False
|
||||
' End Try
|
||||
'End Function
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Private Function GetContainerPath(ContainerId As String) As String
|
||||
' Return Path.Combine(AppConfig.ContainerPath, GetContainerName(ContainerId))
|
||||
'End Function
|
||||
Private Function GetContainerPath(ContainerId As String) As String
|
||||
Return Path.Combine(AppConfig.ContainerPath, GetContainerName(ContainerId))
|
||||
End Function
|
||||
|
||||
'Private Function GetContainerName(ContainerId As String) As String
|
||||
' Return ContainerId & ".enc"
|
||||
'End Function
|
||||
Private Function GetContainerName(ContainerId As String) As String
|
||||
Return ContainerId & ".enc"
|
||||
End Function
|
||||
|
||||
'Private Sub TestFileExists(ContainerId)
|
||||
' Dim oContainerPath = GetContainerPath(ContainerId)
|
||||
Private Sub TestFileExists(ContainerId)
|
||||
Dim oContainerPath = GetContainerPath(ContainerId)
|
||||
|
||||
' If Not IO.File.Exists(oContainerPath) Then
|
||||
' Throw New FileNotFoundException("Container existiert nicht", oContainerPath)
|
||||
' End If
|
||||
'End Sub
|
||||
If Not IO.File.Exists(oContainerPath) Then
|
||||
Throw New FileNotFoundException("Container existiert nicht", oContainerPath)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResult Implements IEDMIService.GetDocumentByDocumentId
|
||||
' Try
|
||||
' Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE GUID = {DocumentId}"
|
||||
' Dim oTable = Database.GetDatatable(oSQL)
|
||||
Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResult Implements IEDMIService.GetDocumentByDocumentId
|
||||
Try
|
||||
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE GUID = {DocumentId}"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' If oTable.Rows.Count = 0 Then
|
||||
' Return New DocumentResult("Document not found")
|
||||
' End If
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Return New DocumentResult("Document not found")
|
||||
End If
|
||||
|
||||
' Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
' Dim oDocument As New DocumentObject(
|
||||
' oRow.Item("CONTAINER_ID"),
|
||||
' oRow.Item("GUID"),
|
||||
' oRow.Item("ORIGINAL_FILENAME")
|
||||
' )
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oDocument As New DocumentObject(
|
||||
oRow.Item("CONTAINER_ID"),
|
||||
oRow.Item("GUID"),
|
||||
oRow.Item("ORIGINAL_FILENAME")
|
||||
)
|
||||
|
||||
' TestFileExists(oDocument.ContainerId)
|
||||
TestFileExists(oDocument.ContainerId)
|
||||
|
||||
' Dim oContainerPath = GetContainerPath(oDocument.ContainerId)
|
||||
' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
' Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
Dim oContainerPath = GetContainerPath(oDocument.ContainerId)
|
||||
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
|
||||
' Return New DocumentResult(oDocument, oContents)
|
||||
' Catch ex As Exception
|
||||
' Return New DocumentResult(ex.Message)
|
||||
' End Try
|
||||
'End Function
|
||||
Return New DocumentResult(oDocument, oContents)
|
||||
Catch ex As Exception
|
||||
Return New DocumentResult(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResult Implements IEDMIService.GetDocumentByContainerId
|
||||
' Try
|
||||
' Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE CONTAINER_ID = '{ContainerId}'"
|
||||
' Dim oTable = Database.GetDatatable(oSQL)
|
||||
Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResult Implements IEDMIService.GetDocumentByContainerId
|
||||
Try
|
||||
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE CONTAINER_ID = '{ContainerId}'"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
|
||||
' If oTable.Rows.Count = 0 Then
|
||||
' Return New DocumentResult("Document not found")
|
||||
' End If
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Return New DocumentResult("Document not found")
|
||||
End If
|
||||
|
||||
' Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
' Dim oDocument As New DocumentObject(
|
||||
' oRow.Item("CONTAINER_ID"),
|
||||
' oRow.Item("GUID"),
|
||||
' oRow.Item("ORIGINAL_FILENAME")
|
||||
' )
|
||||
Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
Dim oDocument As New DocumentObject(
|
||||
oRow.Item("CONTAINER_ID"),
|
||||
oRow.Item("GUID"),
|
||||
oRow.Item("ORIGINAL_FILENAME")
|
||||
)
|
||||
|
||||
' TestFileExists(oDocument.ContainerId)
|
||||
TestFileExists(oDocument.ContainerId)
|
||||
|
||||
' Dim oContainerPath = GetContainerPath(oDocument.ContainerId)
|
||||
' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
' Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
Dim oContainerPath = GetContainerPath(oDocument.ContainerId)
|
||||
Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath)
|
||||
Dim oContents As Byte() = oContainer.GetFile().Contents
|
||||
|
||||
' Return New DocumentResult(oDocument, oContents)
|
||||
' Catch ex As Exception
|
||||
' Return New DocumentResult(ex.Message)
|
||||
' End Try
|
||||
'End Function
|
||||
Return New DocumentResult(oDocument, oContents)
|
||||
Catch ex As Exception
|
||||
Return New DocumentResult(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "Document"
|
||||
|
||||
Reference in New Issue
Block a user