EDMI: UpdateFile WIP

This commit is contained in:
Jonathan Jenne
2022-01-25 16:29:20 +01:00
parent 0fa654bda0
commit 884c9d4546
18 changed files with 460 additions and 338 deletions

View File

@@ -9,7 +9,7 @@ Imports DigitalData.Modules.Logging
Public Class Client
' Constants
Private Const UPDATE_INTERVAL_IN_MINUTES As Integer = 1
Public Const INVALID_OBEJCT_ID As Long = 0
Private Const KIND_TYPE_DOC = "DOC"
' Helper Classes
@@ -188,58 +188,11 @@ Public Class Client
''' <returns>The ObjectId of the newly generated filesystem object</returns>
Public Async Function NewFileAsync(pFilePath As String, pObjectStoreName As String, pObjectKind As String, pBusinessEntity As String, Optional pImportOptions As Options.NewFileOptions = Nothing) As Task(Of Long)
Try
' Set default options
If pImportOptions Is Nothing Then
pImportOptions = New Options.NewFileOptions()
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.NewFileAsync(New NewFileRequest With {
.BusinessEntity = pBusinessEntity,
.File = New FileProperties With {
.FileName = oFileInfo.Name,
.FileCreatedAt = oFileCreatedAt,
.FileChangedAt = oFileModifiedAt,
.FileContents = oContents,
.FileImportedAt = pImportOptions.DateImported,
.FileChecksum = oFileHash
},
.KindType = pObjectKind,
.StoreName = pObjectStoreName,
.User = New UserState With {
.Language = pImportOptions.Language,
.UserName = pImportOptions.Username
}
})
If oFileImportResponse.OK = False Then
Throw New ApplicationException("Could not Import File Contents!")
End If
Return oFileImportResponse.ObjectId
End Using
End Using
Dim oNewFile As New Modules.IDB.NewFile(LogConfig, Channel)
Return Await oNewFile.RunAsync(pFilePath, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions)
Catch ex As Exception
Logger.Error(ex)
Return INVALID_OBEJCT_ID
Return Nothing
End Try
End Function