EDMI: Update Service and Client to Use Messages for EDMI Methods

This commit is contained in:
Jonathan Jenne
2020-04-24 11:53:08 +02:00
parent d2717b9216
commit ed29e1b6a9
20 changed files with 443 additions and 642 deletions

View File

@@ -33,6 +33,8 @@ Public Class EDMIService
_username = oUsername
_logger = LogConfig.GetLogger()
_logger.Debug("New Request by User [{0}]", _username)
End Sub
Public Function StripDomainFromUsername(UserName As String)
@@ -313,16 +315,14 @@ Public Class EDMIService
''' <summary>
''' Imports a file according to ObjectStoreId
''' </summary>
''' <param name="FileName"></param>
''' <param name="Contents"></param>
''' <returns></returns>
Public Function ImportFile(FileName As String, Contents() As Byte, ObjectStoreId As Int64, DocumentType As String, Optional RetentionDays As Int64 = Nothing) As DocumentResult Implements IEDMIService.ImportFile
Public Function ImportFile(Data As Messages.DocumentImportRequest) As Messages.DocumentImportResponse Implements IEDMIService.ImportFile
Dim oObjectStore = GlobalState.ObjectStores.
Where(Function(s) s.Id = ObjectStoreId).
Where(Function(s) s.Id = Data.ObjectStoreId).
FirstOrDefault()
If oObjectStore Is Nothing Then
Return New DocumentResult($"Object Store with Id [{ObjectStoreId}] does not exist!")
Throw New FaultException($"Object Store with Id [{Data.ObjectStoreId}] does not exist!")
End If
Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path)
@@ -335,24 +335,23 @@ Public Class EDMIService
' and return ObjectStore Path from ObjectStoreId + RelativePath
' VWIDB_OBJECTSTORE
Dim oRelativePath As String = EDMIPath.GetRelativePath(DocumentType, FileName)
Dim oAbsolutePath As String = EDMIPath.GetFullPath(DocumentType, FileName)
Dim oDirectoryPath = EDMIPath.GetFullPath(DocumentType)
Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName}
Dim oRelativePath As String = EDMIPath.GetRelativePath(Data.DocumentType, Data.FileName)
Dim oAbsolutePath As String = EDMIPath.GetFullPath(Data.DocumentType, Data.FileName)
Dim oDirectoryPath = EDMIPath.GetFullPath(Data.DocumentType)
Try
Directory.CreateDirectory(oDirectoryPath)
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult(ex.Message)
Throw New FaultException(ex.Message)
End Try
Try
Dim oVersionedFileName As String = Filesystem.GetVersionedFilename(oAbsolutePath)
_logger.Info("ImportFile: Saving file [{0}] to path [{1}]", FileName, oVersionedFileName)
_logger.Info("ImportFile: Saving file [{0}] to path [{1}]", Data.FileName, oVersionedFileName)
Using oStream = New FileStream(oVersionedFileName, FileMode.CreateNew)
oStream.Write(Contents, 0, Contents.Length)
oStream.Write(Data.Contents, 0, Data.Contents.Length)
oStream.Flush(True)
oStream.Close()
End Using
@@ -367,12 +366,10 @@ Public Class EDMIService
Dim oObjectId = MSSQL.GetScalarValue(oCommand, "@IDB_OBJ_ID")
oDocument.FileId = oObjectId
Return New DocumentResult(oDocument)
Return New Messages.DocumentImportResponse() With {.ObjectId = oObjectId}
Catch ex As Exception
_logger.Error(ex)
Return New DocumentResult(ex.Message)
Throw New FaultException(ex.Message)
End Try
End Function
@@ -427,7 +424,7 @@ Public Class EDMIService
Public Function ListFilesForUser() As Messages.DocumentListResponse Implements IEDMIService.ListFilesForUser
Try
Dim oSQL = $"SELECT * FROM VWIDB_DOC_DATA WHERE ADDED_WHO = UPPER('{_username}')"
Dim oSQL = $"SELECT * FROM VWIDB_DOC_DATA"
Dim oDatatable As DataTable = MSSQL.GetDatatable(oSQL)
oDatatable.TableName = "DocumentList"

View File

@@ -49,7 +49,8 @@ Interface IEDMIService
#Region "Document (New)"
<OperationContract>
Function ImportFile(FileName As String, Contents As Byte(), ObjectStoreId As Int64, DocumentType As String, Optional RetentionDays As Int64 = Nothing) As DocumentResult
Function ImportFile(Data As Messages.DocumentImportRequest) As Messages.DocumentImportResponse
'Function ImportFile(FileName As String, Contents As Byte(), ObjectStoreId As Int64, DocumentType As String, Optional RetentionDays As Int64 = Nothing) As Messages.DocumentImportResponse
<OperationContract>
Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse

View File

@@ -3,29 +3,30 @@ Imports System.Runtime.Serialization
Imports System.ServiceModel
Namespace Messages
<Serializable>
<DataContract>
<KnownType(GetType(DBNull))>
Public MustInherit Class BaseResponse
<DataMember>
Public Property OK As Boolean
<DataMember>
Public Property ErrorMessage As String
<MessageContract>
Public Class DocumentImportRequest
<MessageBodyMember>
Public Contents() As Byte
<MessageBodyMember>
Public ObjectStoreId As Long
<MessageBodyMember>
Public FileName As String
<MessageBodyMember>
Public DocumentType As String
<MessageBodyMember>
Public RetentionDays As Long = 0
End Class
Public Sub New()
OK = True
End Sub
Public Sub New(ErrorMessage As String)
OK = False
Me.ErrorMessage = ErrorMessage
End Sub
<MessageContract>
Public Class DocumentImportResponse
<MessageBodyMember>
Public ObjectId As Long
End Class
<MessageContract>
Public Class DocumentStreamRequest
<MessageBodyMember>
Public ObjectId As Int64
Public ObjectId As Long
End Class
<MessageContract>
@@ -37,9 +38,10 @@ Namespace Messages
Public FileContents As Stream
End Class
<MessageContract>
<KnownType(GetType(DBNull))>
Public Class DocumentListResponse
Inherits BaseResponse
<MessageBodyMember>
Public Datatable As DataTable
End Class