EDMI.API: Update for Annette GmbH

This commit is contained in:
Jonathan Jenne
2021-11-25 15:54:48 +01:00
parent 7a1c135b1f
commit 3149b8fa35
15 changed files with 393 additions and 692 deletions

View File

@@ -17,8 +17,61 @@ Public Class Client
Private _dummy_table_attributes As DataTable
Private _channel As IEDMIServiceChannel
Private _FileEx As FileSystem.File
''' <summary>
''' Creates a new EDMI Client object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="ServiceAdress">The IP address/hostname and port, separated by semicolon or colon, ex localhost:9000</param>
Public Sub New(LogConfig As LogConfig, ServiceAdress As String)
_logger = LogConfig.GetLogger()
_FileEx = New Filesystem.File(LogConfig)
Dim oServiceAddress As String = ServiceAdress
Dim oAddressArray() As String
If oServiceAddress.Contains(";") Then
oAddressArray = oServiceAddress.Split(";")
Else
oAddressArray = oServiceAddress.Split(":")
End If
Try
_IPAddressServer = oAddressArray(0)
Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{oAddressArray(0)}:{oAddressArray(1)}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
_channelFactory = oFactory
Catch ex As Exception
_logger.Error(ex)
End Try
End Sub
''' <summary>
''' Creates a new EDMI Client object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="IPAddress">The IP address to connect to</param>
''' <param name="PortNumber">The Port number to use for the connection</param>
Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer)
_logger = LogConfig.GetLogger()
_FileEx = New Filesystem.File(LogConfig)
Try
_IPAddressServer = IPAddress
Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{IPAddress}:{PortNumber}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
_channelFactory = oFactory
Catch ex As Exception
_logger.Error(ex)
End Try
End Sub
''' <summary>
''' Parse a IPAddress:Port String into its parts
''' </summary>
@@ -40,55 +93,6 @@ Public Class Client
Return New Tuple(Of String, Integer)(oAppServerAddress, oAppServerPort)
End Function
''' <summary>
''' Creates a new EDMI Client object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="ServiceAdress">The IP address/hostname and port, separated by semicolon or colon, ex localhost:9000</param>
Public Sub New(LogConfig As LogConfig, ServiceAdress As String)
_logger = LogConfig.GetLogger()
Dim oServiceAddress As String = ServiceAdress
Dim oAddressArray() As String
If oServiceAddress.Contains(";") Then
oAddressArray = oServiceAddress.Split(";")
Else
oAddressArray = oServiceAddress.Split(":")
End If
Try
Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{oAddressArray(0)}:{oAddressArray(1)}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
_channelFactory = oFactory
Catch ex As Exception
_logger.Error(ex)
End Try
End Sub
''' <summary>
''' Creates a new EDMI Client object
''' </summary>
''' <param name="LogConfig">LogConfig object</param>
''' <param name="IPAddress">The IP address to connect to</param>
''' <param name="PortNumber">The Port number to use for the connection</param>
Public Sub New(LogConfig As LogConfig, IPAddress As String, PortNumber As Integer)
_logger = LogConfig.GetLogger()
Try
_IPAddressServer = IPAddress
Dim oBinding = Channel.GetBinding()
Dim oAddress = New EndpointAddress($"net.tcp://{IPAddress}:{PortNumber}/DigitalData/Services/Main")
Dim oFactory = New ChannelFactory(Of IEDMIServiceChannel)(oBinding, oAddress)
_channelFactory = oFactory
Catch ex As Exception
_logger.Error(ex)
End Try
End Sub
''' <summary>
''' Connect to the service
''' </summary>
@@ -109,26 +113,16 @@ Public Class Client
End Try
End Function
''' <summary>
''' TODO: Creates a new object
''' </summary>
''' <returns></returns>
Public Async Function NewObjectAsync() As Task
Throw New NotImplementedException()
End Function
''' <summary>
''' Imports a file from a filepath, creating a IDB ObjectId and Filesystem Object
''' </summary>
''' <param name="pObjectStoreType">Type of ObjectStore. Can be WORK or ARCHIVE.</param>
''' <param name="pObjectStoreName">Type of ObjectStore. Can be WORK or ARCHIVE.</param>
''' <param name="pBusinessEntity">Business entity that the new file object should belong to.</param>
''' <param name="pImportOptions">Other file import options</param>
''' <exception cref="FileNotFoundException">When local filepath was not found</exception>
''' <exception cref="ApplicationException">When there was a error in the Service</exception>
''' <returns>The ObjectId of the newly generated filesystem object</returns>
Public Async Function NewFileAsync(pFilePath As String, pObjectStoreType As String, pBusinessEntity As String, Optional pImportOptions As NewFileOptions = Nothing) As Task(Of Long)
Public Async Function NewFileAsync(pFilePath As String, pObjectStoreName As String, pObjectKind As String, pBusinessEntity As String, Optional pImportOptions As NewFileOptions = Nothing) As Task(Of Long)
Try
' Set default options
If pImportOptions Is Nothing Then
@@ -137,35 +131,16 @@ Public Class Client
' Check if file exists
If File.Exists(pFilePath) = False Then
Throw New FileNotFoundException("ImportFileAsync: Path does not exist")
Throw New FileNotFoundException("Path does not exist")
End If
Dim oFileInfo As New FileInfo(pFilePath)
Dim oExtension As String = oFileInfo.Extension
' Creating new ObjectId
Dim oObjectIdResponse = Await _channel.NewObjectIdAsync(New NewObjectIdRequest With {
.BusinessEntity = pBusinessEntity,
.KindType = KIND_TYPE_DOC,
.Who = pImportOptions.Username
})
If oObjectIdResponse.ObjectId = Nothing OrElse oObjectIdResponse.ObjectId = 0 Then
Throw New ApplicationException("ImportFileAsync: Could not get ObjectId")
End If
' Create new FileObject for ObjectId
Dim oFilePathResponse = Await _channel.NewFileObjectAsync(New NewFileObjectRequest With {
.DateImported = pImportOptions.DateImported,
.Extension = oExtension,
.KeepExtension = pImportOptions.KeepExtension,
.ObjectId = oObjectIdResponse.ObjectId,
.StoreType = pObjectStoreType
})
If oFilePathResponse.FileObjectPath = Nothing OrElse oFilePathResponse.FileObjectPath = "" Then
Throw New ApplicationException("ImportFileAsync: Could not get FileObject Path")
End If
Dim oFileName As String = oFileInfo.Name
Dim oFileCreatedAt As Date = oFileInfo?.CreationTime
Dim oFileModifiedAt As Date = oFileInfo?.LastWriteTime
Dim oFileHash As String = _FileEx.GetChecksum(oFileInfo.FullName)
' Importing the file now
Using oFileStream As New FileStream(pFilePath, FileMode.Open, FileAccess.Read)
@@ -173,21 +148,26 @@ Public Class Client
oFileStream.CopyTo(oMemoryStream)
Dim oContents = oMemoryStream.ToArray()
Dim oFileImportResponse = Await _channel.ImportFileIntoFileObjectAsync(New ImportFileIntoFileObjectRequest With {
.FilePath = oFilePathResponse.FileObjectPath,
.ObjectId = oObjectIdResponse.ObjectId,
.ObjectStoreType = pObjectStoreType,
.Who = pImportOptions.Username,
.Contents = oContents
Dim oFileImportResponse = Await _channel.NewFileAsync(New NewFileRequest With {
.BusinessEntity = pBusinessEntity,
.FileName = oFileInfo.Name,
.FileCreatedAt = oFileCreatedAt,
.FileChangedAt = oFileModifiedAt,
.FileContents = oContents,
.FileImportedAt = pImportOptions.DateImported,
.FileChecksum = oFileHash,
.KindType = pObjectKind,
.StoreName = pObjectStoreName,
.Who = pImportOptions.Username
})
If oFileImportResponse.Result = False Then
Throw New ApplicationException("ImportFileAsync: Could not Import File Contents")
If oFileImportResponse.OK = False Then
Throw New ApplicationException("Could not Import File Contents!")
End If
Return oFileImportResponse.ObjectId
End Using
End Using
Return oObjectIdResponse.ObjectId
Catch ex As Exception
_logger.Error(ex)
Return INVALID_OBEJCT_ID
@@ -650,15 +630,15 @@ Public Class Client
''' <summary>
''' Option to keep the original extension when importing. Defaults to false.
''' </summary>
Public KeepExtension As Boolean = False
Public Property KeepExtension As Boolean = False
''' <summary>
''' Windows username of the user responsible for the import. Defaults to the currently logged in user.
''' </summary>
Public Username As String = Environment.UserName
Public Property Username As String = Environment.UserName
''' <summary>
''' Date when the file was imported. Can be in the past. Defaults to now.
''' </summary>
Public DateImported As Date = Date.Now
Public Property DateImported As Date = Date.Now
End Class
Public Class NewObjectOptions