EDMIAPI: Encapsulate Zooflow and Globix methods into their own classes
This commit is contained in:
@@ -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
|
||||
|
||||
''' <summary>
|
||||
''' 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)
|
||||
|
||||
@@ -76,6 +76,8 @@
|
||||
<Compile Include="Client\Options.vb" />
|
||||
<Compile Include="Client\Rights.vb" />
|
||||
<Compile Include="Client\Channel.vb" />
|
||||
<Compile Include="Modules\BaseMethod.vb" />
|
||||
<Compile Include="Modules\Globix\ImportFile.vb" />
|
||||
<Compile Include="Modules\ZooFlow\GetFileObject.vb" />
|
||||
<Compile Include="Connected Services\EDMIServiceReference\Reference.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -245,5 +247,6 @@
|
||||
<LastGenOutput>Reference.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
</Project>
|
||||
17
Modules.EDMIAPI/Modules/BaseMethod.vb
Normal file
17
Modules.EDMIAPI/Modules/BaseMethod.vb
Normal file
@@ -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
|
||||
78
Modules.EDMIAPI/Modules/Globix/ImportFile.vb
Normal file
78
Modules.EDMIAPI/Modules/Globix/ImportFile.vb
Normal file
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user