From e41ceb83e65ed8e7ab2dd98bfedf97710f44a0a5 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 23 Dec 2021 11:48:58 +0100 Subject: [PATCH] EDMIAPI: Encapsulate Zooflow and Globix methods into their own classes --- .../DocumentResultList/DocumentLoader.vb | 2 +- .../DocumentResultList/DocumentResultInfo.vb | 1 + .../frmDocumentResultList.vb | 1 + GUIs.ZooFlow/Globix/frmGlobix_Index.vb | 2 +- GUIs.ZooFlow/frmtest.vb | 6 +- Modules.EDMIAPI/Client.vb | 74 +++--------------- Modules.EDMIAPI/EDMI.API.vbproj | 3 + Modules.EDMIAPI/Modules/BaseMethod.vb | 17 ++++ Modules.EDMIAPI/Modules/Globix/ImportFile.vb | 78 +++++++++++++++++++ .../Modules/ZooFlow/GetFileObject.vb | 8 +- 10 files changed, 119 insertions(+), 73 deletions(-) create mode 100644 Modules.EDMIAPI/Modules/BaseMethod.vb create mode 100644 Modules.EDMIAPI/Modules/Globix/ImportFile.vb diff --git a/GUIs.Common/DocumentResultList/DocumentLoader.vb b/GUIs.Common/DocumentResultList/DocumentLoader.vb index 9cd761bb..03aacfde 100644 --- a/GUIs.Common/DocumentResultList/DocumentLoader.vb +++ b/GUIs.Common/DocumentResultList/DocumentLoader.vb @@ -67,7 +67,7 @@ Public Class DocumentLoader End Function Private Function Load_FromZooflow(pObjectId As Long) As DocumentResultInfo - Dim oFileObject As FileObject = Client.GetFileObject(pObjectId, pLoadFileContents:=True) + Dim oFileObject As FileObject = Client.Zooflow_GetFileObject(pObjectId, pLoadFileContents:=True) If oFileObject Is Nothing Then Return Nothing diff --git a/GUIs.Common/DocumentResultList/DocumentResultInfo.vb b/GUIs.Common/DocumentResultList/DocumentResultInfo.vb index 1a085877..bb151ea3 100644 --- a/GUIs.Common/DocumentResultList/DocumentResultInfo.vb +++ b/GUIs.Common/DocumentResultList/DocumentResultInfo.vb @@ -25,6 +25,7 @@ Public Class DocumentResultInfo ' Optional properties Public Property LastWriteTime As Date = Nothing Public Property FullPath As String = Nothing + Public Property TempPath As String = Nothing Public Sub New(pPrimaryKey As Long) Id = pPrimaryKey diff --git a/GUIs.Common/DocumentResultList/frmDocumentResultList.vb b/GUIs.Common/DocumentResultList/frmDocumentResultList.vb index b97cc6ec..283a433b 100644 --- a/GUIs.Common/DocumentResultList/frmDocumentResultList.vb +++ b/GUIs.Common/DocumentResultList/frmDocumentResultList.vb @@ -60,6 +60,7 @@ Public Class frmDocumentResultList Private _ActiveGrid As GridControl = Nothing Private _ActiveGridBand As GridBand = Nothing Private _documentloader As DocumentLoader + Private _tempDocuments As New List(Of DocumentResultList) ' TODO: Hashes for checking if the opened file was modified externally 'Private _HashOriginalFile As String = Nothing diff --git a/GUIs.ZooFlow/Globix/frmGlobix_Index.vb b/GUIs.ZooFlow/Globix/frmGlobix_Index.vb index 918a0b46..c318e40b 100644 --- a/GUIs.ZooFlow/Globix/frmGlobix_Index.vb +++ b/GUIs.ZooFlow/Globix/frmGlobix_Index.vb @@ -765,7 +765,7 @@ Public Class frmGlobix_Index Logger.Info("Running Import") - Dim oResult = Await My.Application.Service.Client.ImportFileAsync( + Dim oResult = Await My.Application.Service.Client.Globix_ImportFileAsync( oFilePath, oProfileId, oAttributes, oObjectStore, oObjectKind, oBusinessEntity, oOptions) Logger.Info("Import result: [{0}]", oResult.OK) diff --git a/GUIs.ZooFlow/frmtest.vb b/GUIs.ZooFlow/frmtest.vb index 791f8b6f..3c5e6a84 100644 --- a/GUIs.ZooFlow/frmtest.vb +++ b/GUIs.ZooFlow/frmtest.vb @@ -37,11 +37,11 @@ Public Class frmtest Private Async Sub btnImportFile_Click_(sender As Object, e As EventArgs) Handles btnImportFile.Click - Dim oResponse As ImportFileResponse = Await My.Application.Service.Client.ImportFileAsync( + Dim oResponse As ImportFileResponse = Await My.Application.Service.Client.Globix_ImportFileAsync( txtFile2Import.Text, txtProfileId.Text, - New List(Of EDMIServiceReference.UserAttributeValue) From { - New EDMIServiceReference.UserAttributeValue With { + New List(Of UserAttributeValue) From { + New UserAttributeValue With { .Name = "Attribut String1", .Values = New List(Of String) From {"SchreiberM"}.ToArray } diff --git a/Modules.EDMIAPI/Client.vb b/Modules.EDMIAPI/Client.vb index b527fd59..62e57d6e 100644 --- a/Modules.EDMIAPI/Client.vb +++ b/Modules.EDMIAPI/Client.vb @@ -8,7 +8,6 @@ Imports DigitalData.Modules.Logging Public Class Client Public Const INVALID_OBEJCT_ID As Long = 0 - Private Const KIND_TYPE_DOC = "DOC" Private ReadOnly _LogConfig As LogConfig @@ -16,10 +15,8 @@ Public Class Client Private ReadOnly _channelFactory As ChannelFactory(Of IEDMIServiceChannel) Private ReadOnly _IPAddressServer As String Private ReadOnly _PortServer As Integer - - Private _dummy_table_attributes As DataTable + Private ReadOnly _FileEx As Filesystem.File Private _channel As IEDMIServiceChannel - Private _FileEx As Filesystem.File ''' ''' Creates a new EDMI Client object @@ -184,71 +181,24 @@ Public Class Client End Try End Function - Public Async Function ImportFileAsync( - pFilePath As String, - pProfileId As Integer, - pAttributeValues As List(Of UserAttributeValue), - pObjectStoreName As String, - pObjectKind As String, - pBusinessEntity As String, - Optional pImportOptions As Options.ImportFileOptions = Nothing - ) As Task(Of ImportFileResponse) + Public Async Function Globix_ImportFileAsync( + pFilePath As String, + pProfileId As Integer, + pAttributeValues As List(Of UserAttributeValue), + pObjectStoreName As String, + pObjectKind As String, + pBusinessEntity As String, + Optional pImportOptions As Options.ImportFileOptions = Nothing) As Task(Of ImportFileResponse) Try - ' Set default options - If pImportOptions Is Nothing Then - pImportOptions = New Options.ImportFileOptions() - End If - - ' Check if file exists - If File.Exists(pFilePath) = False Then - Throw New FileNotFoundException("Path does not exist") - End If - - Dim oFileInfo As New FileInfo(pFilePath) - Dim oExtension As String = oFileInfo.Extension - - 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) - Using oMemoryStream As New MemoryStream() - oFileStream.CopyTo(oMemoryStream) - Dim oContents = oMemoryStream.ToArray() - - Dim oFileImportResponse = Await _channel.ImportFileAsync(New ImportFileRequest With { - .BusinessEntity = pBusinessEntity, - .File = New FileProperties With { - .FileName = oFileInfo.Name, - .FileCreatedAt = oFileCreatedAt, - .FileChangedAt = oFileModifiedAt, - .FileContents = oContents, - .FileImportedAt = pImportOptions.DateImported, - .FileChecksum = oFileHash, - .FileInfoRaw = oFileInfo - }, - .KindType = pObjectKind, - .StoreName = pObjectStoreName, - .User = New UserState() With { - .UserName = pImportOptions.Username, - .Language = pImportOptions.Language - }, - .ProfileId = pProfileId, - .AttributeValues = pAttributeValues.ToArray - }) - - Return oFileImportResponse - End Using - End Using + Dim oImportFile As New Modules.Globix.ImportFile(_LogConfig, _channel) + Return Await oImportFile.RunAsync(pFilePath, pProfileId, pAttributeValues, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions) Catch ex As Exception _logger.Error(ex) Return Nothing End Try End Function - Public Function GetFileObject(pObjectId As Long, pLoadFileContents As Boolean) As FileObject + Public Function Zooflow_GetFileObject(pObjectId As Long, pLoadFileContents As Boolean) As FileObject Try Dim oGetFileObject As New Modules.Zooflow.GetFileObject(_LogConfig, _channel) Dim oFileObject = oGetFileObject.Run(pObjectId, pLoadFileContents) diff --git a/Modules.EDMIAPI/EDMI.API.vbproj b/Modules.EDMIAPI/EDMI.API.vbproj index 453e7b8d..2090e205 100644 --- a/Modules.EDMIAPI/EDMI.API.vbproj +++ b/Modules.EDMIAPI/EDMI.API.vbproj @@ -76,6 +76,8 @@ + + True @@ -245,5 +247,6 @@ Reference.vb + \ No newline at end of file diff --git a/Modules.EDMIAPI/Modules/BaseMethod.vb b/Modules.EDMIAPI/Modules/BaseMethod.vb new file mode 100644 index 00000000..24c01c5d --- /dev/null +++ b/Modules.EDMIAPI/Modules/BaseMethod.vb @@ -0,0 +1,17 @@ +Imports DigitalData.Modules.EDMI.API.EDMIServiceReference +Imports DigitalData.Modules.Logging + +Namespace Modules + Public Class BaseMethod + Friend ReadOnly LogConfig As LogConfig + Friend ReadOnly Logger As Logger + Friend ReadOnly Channel As IEDMIServiceChannel + + Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel) + LogConfig = pLogConfig + Logger = pLogConfig.GetLogger() + Channel = pChannel + End Sub + End Class + +End Namespace \ No newline at end of file diff --git a/Modules.EDMIAPI/Modules/Globix/ImportFile.vb b/Modules.EDMIAPI/Modules/Globix/ImportFile.vb new file mode 100644 index 00000000..ca2e979b --- /dev/null +++ b/Modules.EDMIAPI/Modules/Globix/ImportFile.vb @@ -0,0 +1,78 @@ +Imports System.IO +Imports DigitalData.Modules.EDMI.API.EDMIServiceReference +Imports DigitalData.Modules.Logging + +Namespace Modules.Globix + Public Class ImportFile + Inherits BaseMethod + Private ReadOnly FileEx As Filesystem.File + + Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel) + MyBase.New(pLogConfig, pChannel) + FileEx = New Filesystem.File(pLogConfig) + End Sub + + Public Async Function RunAsync(pFilePath As String, + pProfileId As Integer, + pAttributeValues As List(Of UserAttributeValue), + pObjectStoreName As String, + pObjectKind As String, + pBusinessEntity As String, + pImportOptions As Options.ImportFileOptions) As Task(Of ImportFileResponse) + Try + ' Set default options + If pImportOptions Is Nothing Then + pImportOptions = New Options.ImportFileOptions() + End If + + ' Check if file exists + If File.Exists(pFilePath) = False Then + Throw New FileNotFoundException("Path does not exist") + End If + + Dim oFileInfo As New FileInfo(pFilePath) + Dim oExtension As String = oFileInfo.Extension + + 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) + Using oMemoryStream As New MemoryStream() + oFileStream.CopyTo(oMemoryStream) + Dim oContents = oMemoryStream.ToArray() + + Dim oFileImportResponse = Await Channel.ImportFileAsync(New ImportFileRequest With { + .BusinessEntity = pBusinessEntity, + .File = New FileProperties With { + .FileName = oFileInfo.Name, + .FileCreatedAt = oFileCreatedAt, + .FileChangedAt = oFileModifiedAt, + .FileContents = oContents, + .FileImportedAt = pImportOptions.DateImported, + .FileChecksum = oFileHash, + .FileInfoRaw = oFileInfo + }, + .KindType = pObjectKind, + .StoreName = pObjectStoreName, + .User = New UserState() With { + .UserName = pImportOptions.Username, + .Language = pImportOptions.Language + }, + .ProfileId = pProfileId, + .AttributeValues = pAttributeValues.ToArray + }) + + Return oFileImportResponse + End Using + End Using + Catch ex As Exception + Logger.Error(ex) + Return Nothing + End Try + End Function + End Class +End Namespace + diff --git a/Modules.EDMIAPI/Modules/ZooFlow/GetFileObject.vb b/Modules.EDMIAPI/Modules/ZooFlow/GetFileObject.vb index 8553377a..aa9b89cf 100644 --- a/Modules.EDMIAPI/Modules/ZooFlow/GetFileObject.vb +++ b/Modules.EDMIAPI/Modules/ZooFlow/GetFileObject.vb @@ -3,14 +3,10 @@ Imports DigitalData.Modules.Logging Namespace Modules.Zooflow Public Class GetFileObject - Private ReadOnly LogConfig As LogConfig - Private ReadOnly Logger As Logger - Private ReadOnly Channel As IEDMIServiceChannel + Inherits BaseMethod Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel) - LogConfig = pLogConfig - Logger = pLogConfig.GetLogger() - Channel = pChannel + MyBase.New(pLogConfig, pChannel) End Sub Public Async Function RunAsync(pObjectId As Long, pLoadFileContents As Boolean) As Task(Of FileObject)