EDMI: First version of Updating files by replacing them!
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user