EDMI: UpdateFile WIP
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -25,6 +25,15 @@
|
||||
Public Property DateImported As Date = Date.Now
|
||||
End Class
|
||||
|
||||
Public Class UpdateFileOptions
|
||||
Inherits BaseOptions
|
||||
|
||||
''' <summary>
|
||||
''' Should the changes in the file result in a new version? Otherwise the old file will be overridden.
|
||||
''' </summary>
|
||||
Public Property CreateNewFileVersion As Boolean = False
|
||||
End Class
|
||||
|
||||
Public Class ImportFileOptions
|
||||
Inherits BaseOptions
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Public Class Constants
|
||||
Public Const DEFAULT_SERVICE_PORT = 9000
|
||||
Public Const INVALID_OBEJCT_ID As Long = 0
|
||||
|
||||
Public Enum DatabaseType
|
||||
ECM
|
||||
|
||||
@@ -78,6 +78,9 @@
|
||||
<Compile Include="Client\Channel.vb" />
|
||||
<Compile Include="Modules\BaseMethod.vb" />
|
||||
<Compile Include="Modules\Globix\ImportFile.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="Modules\IDB\NewFile.vb" />
|
||||
<Compile Include="Modules\IDB\UpdateFile.vb" />
|
||||
<Compile Include="Modules\ZooFlow\GetFileObject.vb" />
|
||||
<Compile Include="Connected Services\EDMIServiceReference\Reference.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
|
||||
41
Modules.EDMIAPI/Helpers.vb
Normal file
41
Modules.EDMIAPI/Helpers.vb
Normal file
@@ -0,0 +1,41 @@
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
|
||||
Public Class Helpers
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly Logger As Logger
|
||||
Private ReadOnly FileEx As Filesystem.File
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
FileEx = New Filesystem.File(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetFileProperties(pFilePath As String, pDateImportedAt As Date) As FileProperties
|
||||
Using oFileStream As New IO.FileStream(pFilePath, IO.FileMode.Open, IO.FileAccess.Read)
|
||||
Using oMemoryStream As New IO.MemoryStream()
|
||||
oFileStream.CopyTo(oMemoryStream)
|
||||
Dim oContents = oMemoryStream.ToArray()
|
||||
|
||||
Dim oFileInfo As New IO.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)
|
||||
|
||||
Return New FileProperties With {
|
||||
.FileName = oFileInfo.Name,
|
||||
.FileCreatedAt = oFileCreatedAt,
|
||||
.FileChangedAt = oFileModifiedAt,
|
||||
.FileContents = oContents,
|
||||
.FileImportedAt = pDateImportedAt,
|
||||
.FileChecksum = oFileHash
|
||||
}
|
||||
End Using
|
||||
End Using
|
||||
End Function
|
||||
End Class
|
||||
@@ -6,11 +6,15 @@ Namespace Modules
|
||||
Friend ReadOnly LogConfig As LogConfig
|
||||
Friend ReadOnly Logger As Logger
|
||||
Friend ReadOnly Channel As IEDMIServiceChannel
|
||||
Friend ReadOnly FileEx As Filesystem.File
|
||||
Friend ReadOnly Helpers As Helpers
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
Channel = pChannel
|
||||
FileEx = New Filesystem.File(pLogConfig)
|
||||
Helpers = New Helpers(pLogConfig)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
|
||||
49
Modules.EDMIAPI/Modules/IDB/NewFile.vb
Normal file
49
Modules.EDMIAPI/Modules/IDB/NewFile.vb
Normal file
@@ -0,0 +1,49 @@
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
|
||||
Namespace Modules.IDB
|
||||
Public Class NewFile
|
||||
Inherits BaseMethod
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
|
||||
MyBase.New(pLogConfig, pChannel)
|
||||
End Sub
|
||||
|
||||
Public Async Function RunAsync(pFilePath As String, pObjectStoreName As String, pObjectKind As String, pBusinessEntity As String, Optional pOptions As Options.NewFileOptions = Nothing) As Task(Of Long)
|
||||
Try
|
||||
' Set default options
|
||||
If pOptions Is Nothing Then
|
||||
pOptions = New Options.NewFileOptions()
|
||||
End If
|
||||
|
||||
' Check if file exists
|
||||
If IO.File.Exists(pFilePath) = False Then
|
||||
Throw New IO.FileNotFoundException("Path does not exist")
|
||||
End If
|
||||
|
||||
' Importing the file now
|
||||
Dim oFileProperties = Helpers.GetFileProperties(pFilePath, pOptions.DateImported)
|
||||
Dim oFileImportResponse = Await Channel.NewFileAsync(New NewFileRequest With {
|
||||
.BusinessEntity = pBusinessEntity,
|
||||
.File = oFileProperties,
|
||||
.KindType = pObjectKind,
|
||||
.StoreName = pObjectStoreName,
|
||||
.User = New UserState With {
|
||||
.Language = pOptions.Language,
|
||||
.UserName = pOptions.Username
|
||||
}
|
||||
})
|
||||
|
||||
If oFileImportResponse.OK = False Then
|
||||
Throw New ApplicationException("Could not Import File Contents!")
|
||||
End If
|
||||
|
||||
Return oFileImportResponse.ObjectId
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Constants.INVALID_OBEJCT_ID
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
39
Modules.EDMIAPI/Modules/IDB/UpdateFile.vb
Normal file
39
Modules.EDMIAPI/Modules/IDB/UpdateFile.vb
Normal file
@@ -0,0 +1,39 @@
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.EDMI.API.Options
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace Modules.IDB
|
||||
Public Class UpdateFile
|
||||
Inherits BaseMethod
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
|
||||
MyBase.New(pLogConfig, pChannel)
|
||||
End Sub
|
||||
|
||||
Public Async Function RunAsync(pFilePath As String, pObjectId As Long, Optional pOptions As UpdateFileOptions = Nothing) As Task
|
||||
' Set default options
|
||||
If pOptions Is Nothing Then
|
||||
pOptions = New UpdateFileOptions()
|
||||
End If
|
||||
|
||||
' Check if file exists
|
||||
If IO.File.Exists(pFilePath) = False Then
|
||||
Throw New IO.FileNotFoundException("Path does not exist")
|
||||
End If
|
||||
|
||||
' Importing the file now
|
||||
Dim oFileProperties = Helpers.GetFileProperties(pFilePath, Date.Now)
|
||||
'Dim oFileImportResponse = Await Channel.(New NewFileRequest With {
|
||||
' .BusinessEntity = pBusinessEntity,
|
||||
' .File = oFileProperties,
|
||||
' .KindType = pObjectKind,
|
||||
' .StoreName = pObjectStoreName,
|
||||
' .User = New UserState With {
|
||||
' .Language = pOptions.Language,
|
||||
' .UserName = pOptions.Username
|
||||
' }
|
||||
'})
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user