EDMI: First version of Updating files by replacing them!

This commit is contained in:
Jonathan Jenne
2022-01-31 16:31:13 +01:00
parent ab10268c99
commit 17bbaac7a0
30 changed files with 581 additions and 241 deletions

View File

@@ -72,35 +72,35 @@ Namespace IDB
End Try
End Function
Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
Dim oAttributes As New List(Of ObjectAttribute)
'Public Function GetAttributesForObject(pObjectId As Long, pLanguage As String) As List(Of ObjectAttribute)
' Dim oAttributes As New List(Of ObjectAttribute)
Try
Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
Return Nothing
End If
' Try
' Dim oTable As DataTable = Database.GetDatatable($"EXEC [PRIDB_GET_VALUE_DT] {pObjectId}, '{pLanguage}'")
' If oTable Is Nothing OrElse oTable.Rows.Count = 0 Then
' Return Nothing
' End If
For Each oRow As DataRow In oTable.Rows
Dim oAttribute As New ObjectAttribute With {
.Id = oRow.Item("AttributeId"),
.Title = oRow.Item("AttributeTitle"),
.Type = oRow.Item("AttributeType"),
.ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
.ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
.ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
.ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
}
' For Each oRow As DataRow In oTable.Rows
' Dim oAttribute As New ObjectAttribute With {
' .Id = oRow.Item("AttributeId"),
' .Title = oRow.Item("AttributeTitle"),
' .Type = oRow.Item("AttributeType"),
' .ValueBigInt = Utils.NotNull(oRow.Item("ValueBigInt"), Nothing),
' .ValueDate = Utils.NotNull(oRow.Item("ValueDate"), Nothing),
' .ValueDecimal = Utils.NotNull(oRow.Item("ValueDecimal"), Nothing),
' .ValueText = Utils.NotNull(oRow.Item("ValueText"), Nothing)
' }
oAttributes.Add(oAttribute)
Next
' oAttributes.Add(oAttribute)
' Next
Return oAttributes
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
' Return oAttributes
' Catch ex As Exception
' Logger.Error(ex)
' Return Nothing
' End Try
'End Function
Public Function SetAttributeValue(pConnection As SqlConnection, pTransaction As SqlTransaction, pObjectId As Long, pAttributeName As String, pValue As String, pLanguage As String, pWho As String) As Boolean
Dim oSql = $"

View File

@@ -15,6 +15,9 @@ Namespace Methods.IDB.GetFileObject
Public Property FileSize As Long
<DataMember>
Public Property FileContents As Byte()
' Internal Properties, these will not be given to the client
Public Property FilePath As String
End Class
End Namespace

View File

@@ -28,19 +28,19 @@ Namespace Methods.IDB.GetFileObject
Dim oFileHash As String = oRow.ItemEx("FILE_HASH", "")
Dim oFileSize As Long = oRow.ItemEx(Of Long)("FILE_SIZE", 0)
Dim oFileExtension As String = oRow.ItemEx(Of String)("EXTENSION")
Dim oFilePath = oRow.ItemEx("RELPATH", "")
Dim oFileName = oRow.ItemEx("Filename", "")
Dim oFullFileName = Path.Combine(oFilePath, oFileName)
Dim oFileObject As New FileObject With {
.ObjectId = pData.ObjectId,
.FileHash = oFileHash,
.FileSize = oFileSize,
.FileExtension = oFileExtension
.FileExtension = oFileExtension,
.FilePath = oFullFileName
}
If pData.LoadFileContents = True Then
Dim oFilePath = oRow.ItemEx("RELPATH", "")
Dim oFileName = oRow.ItemEx("Filename", "")
Dim oFullFileName = Path.Combine(oFilePath, oFileName)
If File.Exists(oFullFileName) = False Then
Throw New FileNotFoundException("FileObject not Found!", oFullFileName)
End If

View File

@@ -125,10 +125,10 @@ Namespace Methods.IDB.NewFile
'TODO: File dates in try catch
Dim oSystemAttributes As New Dictionary(Of String, Object) From {
{"OriginFileName", pData.File.FileName},
{"OriginCreationDatetime", pData.File.FileCreatedAt},
{"OriginChangedDatetime", pData.File.FileChangedAt}
}
{"OriginFileName", pData.File.FileName},
{"OriginCreationDatetime", pData.File.FileCreatedAt},
{"OriginChangedDatetime", pData.File.FileChangedAt}
}
For Each oAttribute As KeyValuePair(Of String, Object) In oSystemAttributes
Try

View File

@@ -21,25 +21,56 @@ Namespace Methods.IDB.UpdateFile
Public Function Run(pData As UpdateFileRequest) As UpdateFileResponse
' TODO: Update file object
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
LogAndThrow("ObjectId does not exist!")
End If
Try
' TODO: Update file object
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
LogAndThrow("ObjectId does not exist!")
End If
'TODO: Create a view that collects all information about an idb object
'TODO: Create a view that collects all information about an idb object
If pData.CreateNewVersion = False Then
If pData.CreateNewVersion = False Then
Dim oGetFileObject As New GetFileObject.GetFileObjectMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oArgs = New GetFileObject.GetFileObjectRequest With {
.ObjectId = pData.ObjectId,
.LoadFileContents = False
}
Dim oFileObjectResponse As GetFileObject.GetFileObjectResponse = oGetFileObject.Run(oArgs)
If oFileObjectResponse.OK = False Then
LogAndThrow(oFileObjectResponse.ErrorMessage)
End If
Dim oFileObjectSize As Long = pData.File.FileContents.Length
Dim oFileObject As GetFileObject.FileObject = oFileObjectResponse.FileObject
Dim oFilePath As String = oFileObject.FilePath
Try
Using oStream = New IO.FileStream(oFilePath, IO.FileMode.Create, IO.FileAccess.Write)
Logger.Info("Saving file to path [{0}]", oFilePath)
oStream.Write(pData.File.FileContents, 0, oFileObjectSize)
oStream.Flush(True)
oStream.Close()
End Using
Catch ex As Exception
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
End Try
Return New UpdateFileResponse(pData.ObjectId)
Else
Throw New ApplicationException("Not implemented!!")
Else
End If
End If
Catch ex As Exception
Return New UpdateFileResponse(ex)
End Try
Return New UpdateFileResponse(pData.ObjectId)
'Dim oFilePath As String = Nothing
'
'Dim oExistingObjectId = TestFileChecksumExists(pData.File.FileChecksum)