This commit is contained in:
Jonathan Jenne 2020-04-27 14:16:42 +02:00
parent ed29e1b6a9
commit 4cde711955
12 changed files with 38 additions and 325 deletions

View File

@ -15,7 +15,7 @@ Public Class Form1
Try
_LogConfig = New LogConfig(LogConfig.PathType.Temp, Nothing, "EDMIBenschmark")
_Logger = _LogConfig.GetLogger()
_Client = New Client(_LogConfig, "net.tcp://172.24.12.39:9000/DigitalData/Services/Main")
_Client = New Client(_LogConfig, "172.24.12.39", 9000)
_Client.Connect()
DocumentViewer1.Init(_LogConfig, "21182889975216572111813147150675976632")

View File

@ -36,6 +36,18 @@ Public Class Client
End Try
End Sub
Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer)
_logger = LogConfig.GetLogger()
Try
Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{IPAddress}:{PortNumber}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
Catch ex As Exception
End Try
End Sub
''' <summary>
''' Connect to the service
''' </summary>

View File

@ -1,3 +0,0 @@
Public Interface IDatabase
Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Int64, ReferenceId As Int64) As Int64
End Interface

View File

@ -1,20 +0,0 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Public Class MSSQL
Implements IDatabase
Private ReadOnly LogConfig As LogConfig
Private ReadOnly Database As MSSQLServer
Private ReadOnly Logger As Logger
Public Sub New(LogConfig As LogConfig, Database As MSSQLServer)
Me.LogConfig = LogConfig
Me.Database = Database
Me.Logger = LogConfig.GetLogger()
End Sub
Public Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Long, ReferenceId As Long) As Long Implements IDatabase.NewDocument
End Function
End Class

View File

@ -47,7 +47,7 @@ Public Class EDMIService
End If
End Function
#Region "Auth"
#Region "=== Authorization ==="
Private Function TestUserAuth() As Boolean
Try
'Dim oSQL As String = $"SELECT FNIDB_AUTH_USER('{_username}') FROM RDB$DATABASE;"
@ -60,12 +60,12 @@ Public Class EDMIService
End Try
End Function
#End Region
#Region "Heartbeat"
#Region "=== Heartbeat ==="
Public Function Heartbeat() As Boolean Implements IEDMIService.Heartbeat
Return True
End Function
#End Region
#Region "Request"
#Region "=== Database Request ==="
Public Sub CreateRequest(Name As String, Optional Debug As Boolean = False)
_request = New Request(Name, _username, Firebird, Debug)
_debug = Debug
@ -90,7 +90,7 @@ Public Class EDMIService
End Sub
#End Region
#Region "Database"
#Region "=== Database (Firebird) ==="
Private Sub TestRequestCreated()
If IsNothing(_request) Then
Throw New Exceptions.NoRequestException()
@ -144,174 +144,8 @@ Public Class EDMIService
Return New NonQueryResult(ex.Message)
End Try
End Function
#End Region
#Region "Document (with FileContainer)"
Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResultOld 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
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 oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;"
Dim oDocId As Int64 = Firebird.GetScalarValue(oSQL)
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)
oContainer.SetFile(Contents, FileName)
oContainer.SaveAs(GetContainerPath(oContainerId))
_logger.Debug("File saved in Container!", FileName)
Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName)
Return New DocumentResultOld(oDocument)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResultOld(ex.Message)
End Try
End Function
Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResultOld Implements IEDMIService.UpdateFile
Try
TestFileExists(DocObject.ContainerId)
' TODO: update db
Dim oFilePath = GetContainerPath(DocObject.ContainerId)
Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath)
oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName)
oFileContainer.Save()
Return New DocumentResultOld(DocObject)
Catch ex As Exception
_logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetFile(DocObject As DocumentObject) As DocumentResultOld 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
Return New DocumentResultOld(DocObject, oContents)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResultOld(ex.Message)
End Try
End Function
Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile
Try
TestFileExists(DocObject.ContainerId)
Dim oFilePath = GetContainerPath(DocObject.ContainerId)
IO.File.Delete(oFilePath)
'TODO: Delete doc from db
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 GetContainerName(ContainerId As String) As String
Return ContainerId & ".enc"
End Function
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
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 DocumentResultOld("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")
)
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
Return New DocumentResultOld(oDocument, oContents)
Catch ex As Exception
Return New DocumentResultOld(ex.Message)
End Try
End Function
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 DocumentResultOld("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")
)
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
Return New DocumentResultOld(oDocument, oContents)
Catch ex As Exception
Return New DocumentResultOld(ex.Message)
End Try
End Function
#End Region
#Region "Document"
#Region "=== Document ==="
''' <summary>
''' Imports a file according to ObjectStoreId
''' </summary>
@ -436,20 +270,5 @@ Public Class EDMIService
Throw New FaultException(ex.Message)
End Try
End Function
#End Region
#Region "Index"
Public Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult Implements IEDMIService.NewFileIndex
Try
Dim oSQL = $"SELECT FNIDB_NEW_DOC_VALUE({DocObject.DocumentId},'{Syskey}','{LanguageCode}','{Value}','{_username}') FROM RDB$DATABASE;"
Dim oIndexId As Int64 = Firebird.GetScalarValue(oSQL)
Return New IndexResult(oIndexId)
Catch ex As Exception
_logger.Error(ex)
Return New IndexResult(ex.Message)
End Try
End Function
#End Region
End Class

View File

@ -102,18 +102,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfig.vb" />
<Compile Include="Database\IDatabase.vb" />
<Compile Include="Database\MSSQL.vb" />
<Compile Include="GlobalState.vb" />
<Compile Include="Messages.vb" />
<Compile Include="Results\BaseResult.vb" />
<Compile Include="Results\ContainerResult.vb" />
<Compile Include="Results\DocumentResultOld.vb" />
<Compile Include="Exceptions.vb" />
<Compile Include="Results\DatabaseResult.vb" />
<Compile Include="EDMIService.vb" />
<Compile Include="Results\DocumentResult.vb" />
<Compile Include="Results\IndexResult.vb" />
<Compile Include="WindowsService.vb">
<SubType>Component</SubType>
</Compile>

View File

@ -1,7 +1,13 @@
Public Class Exceptions
Imports System.ServiceModel
Public Class Exceptions
Public Class BaseException
Inherits FaultException
End Class
Public Class NoRequestException
Inherits ApplicationException
Inherits BaseException
End Class
End Class

View File

@ -28,23 +28,23 @@ Interface IEDMIService
#End Region
#Region "Document (with FileContainer)"
<OperationContract>
Function NewFile(FileName As String, Contents As Byte()) As DocumentResultOld
'<OperationContract>
'Function NewFile(FileName As String, Contents As Byte()) As DocumentResultOld
<OperationContract>
Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResultOld
'<OperationContract>
'Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResultOld
<OperationContract>
Function GetFile(DocObject As DocumentObject) As DocumentResultOld
'<OperationContract>
'Function GetFile(DocObject As DocumentObject) As DocumentResultOld
<OperationContract>
Function DeleteFile(DocObject As DocumentObject) As Boolean
'<OperationContract>
'Function DeleteFile(DocObject As DocumentObject) As Boolean
<OperationContract>
Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResultOld
'<OperationContract>
'Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResultOld
<OperationContract>
Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld
'<OperationContract>
'Function GetDocumentByContainerId(ContainerId As String) As DocumentResultOld
#End Region
#Region "Document (New)"
@ -59,9 +59,4 @@ Interface IEDMIService
Function ListFilesForUser() As Messages.DocumentListResponse
#End Region
#Region "Index"
<OperationContract>
Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult
#End Region
End Interface

View File

@ -1,18 +0,0 @@
Imports DigitalData.Modules.Filesystem
<Serializable>
Public Class ContainerResult
Public ReadOnly OK As Boolean
Public ReadOnly ErrorMessage As String
Public Container As FileContainerInner
Public Sub New()
OK = True
ErrorMessage = Nothing
End Sub
Public Sub New(ErrorMessage As String)
OK = False
Me.ErrorMessage = ErrorMessage
End Sub
End Class

View File

@ -1,31 +0,0 @@
Imports System.Xml.Serialization
<Serializable>
Public Class DocumentResult
Inherits BaseResult
Public Document As DocumentObject
Public HasContents As Boolean = False
Public Contents As Byte()
Public Sub New(Document As DocumentObject)
MyBase.New()
Me.Document = Document
End Sub
Public Sub New(Document As DocumentObject, Contents As Byte())
MyBase.New()
Me.Document = Document
Me.Contents = Contents
Me.HasContents = True
End Sub
Public Sub New(ErrorMessage As String)
MyBase.New(ErrorMessage)
End Sub
Public Class DocumentObject
Public FileName As String
Public FileId As String
End Class
End Class

View File

@ -1,26 +0,0 @@
Imports DigitalData.Modules.Filesystem
<Serializable>
Public Class DocumentResultOld
Inherits BaseResult
Public Document As DocumentObject
Public HasContents As Boolean = False
Public Contents As Byte()
Public Sub New(Document As DocumentObject)
MyBase.New()
Me.Document = Document
End Sub
Public Sub New(Document As DocumentObject, Contents As Byte())
MyBase.New()
Me.Document = Document
Me.Contents = Contents
Me.HasContents = True
End Sub
Public Sub New(ErrorMessage As String)
MyBase.New(ErrorMessage)
End Sub
End Class

View File

@ -1,15 +0,0 @@
<Serializable>
Public Class IndexResult
Inherits BaseResult
Public ReadOnly IndexId As Int64
Public Sub New(IndexId As Int64)
MyBase.New()
Me.IndexId = IndexId
End Sub
Public Sub New(ErrorMessage As String)
MyBase.New(ErrorMessage)
End Sub
End Class