EDMI: Add generic ImportFile Method
This commit is contained in:
@@ -5,11 +5,9 @@ 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,
|
||||
@@ -18,7 +16,7 @@ Namespace Modules.Globix
|
||||
pObjectStoreName As String,
|
||||
pObjectKind As String,
|
||||
pIDBDoctypeId As Long,
|
||||
pImportOptions As Options.ImportFileOptions) As Task(Of ImportFileResponse)
|
||||
pImportOptions As Options.ImportFileOptions) As Task(Of Globix_ImportFileResponse)
|
||||
Try
|
||||
' Set default options
|
||||
If pImportOptions Is Nothing Then
|
||||
@@ -44,7 +42,7 @@ Namespace Modules.Globix
|
||||
oFileStream.CopyTo(oMemoryStream)
|
||||
Dim oContents = oMemoryStream.ToArray()
|
||||
|
||||
Dim oFileImportResponse = Await Channel.ImportFileAsync(New ImportFileRequest With {
|
||||
Dim oFileImportResponse = Await Channel.Globix_ImportFileAsync(New Globix_ImportFileRequest With {
|
||||
.IDBDoctypeId = pIDBDoctypeId,
|
||||
.File = New FileProperties With {
|
||||
.FileName = oFileInfo.Name,
|
||||
|
||||
75
Modules.EDMIAPI/Modules/IDB/ImportFile.vb
Normal file
75
Modules.EDMIAPI/Modules/IDB/ImportFile.vb
Normal file
@@ -0,0 +1,75 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace Modules.IDB
|
||||
Public Class ImportFile
|
||||
Inherits BaseMethod
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
|
||||
MyBase.New(pLogConfig, pChannel)
|
||||
End Sub
|
||||
|
||||
Public Async Function RunAsync(pFilePath As String,
|
||||
pAttributeValues As List(Of UserAttributeValue),
|
||||
pObjectStoreName As String,
|
||||
pObjectKind As String,
|
||||
pIDBDoctypeId As Long,
|
||||
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 {
|
||||
.IDBDoctypeId = pIDBDoctypeId,
|
||||
.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 = -1,
|
||||
.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
|
||||
|
||||
Reference in New Issue
Block a user