EDMI: changes in newfile and updatefile method

This commit is contained in:
Jonathan Jenne 2022-02-08 16:29:43 +01:00
parent 5e44adccd7
commit 607f7e6445
8 changed files with 46 additions and 29 deletions

View File

@ -144,6 +144,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EDMIService.Tests", "EDMISe
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Base", "Modules.Base\Base\Base.vbproj", "{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}" Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Base", "Modules.Base\Base\Base.vbproj", "{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}"
EndProject EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MessageBoxEx", "MessageBoxEx\MessageBoxEx.vbproj", "{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -386,6 +388,10 @@ Global
{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Debug|Any CPU.Build.0 = Debug|Any CPU {6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Release|Any CPU.ActiveCfg = Release|Any CPU {6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Release|Any CPU.Build.0 = Release|Any CPU {6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}.Release|Any CPU.Build.0 = Release|Any CPU
{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -450,6 +456,7 @@ Global
{C9827B8D-9EF9-411A-A6BF-4807794F8C8F} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} {C9827B8D-9EF9-411A-A6BF-4807794F8C8F} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC}
{E3DA65CA-964D-4896-991A-B5426884E215} = {7AF3F9C2-C939-4A08-95C1-0453207E298A} {E3DA65CA-964D-4896-991A-B5426884E215} = {7AF3F9C2-C939-4A08-95C1-0453207E298A}
{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} {6EA0C51F-C2B1-4462-8198-3DE0B32B74F8} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC}
{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9} = {F98C0329-C004-417F-B2AB-7466E88D8220}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286} SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286}

View File

@ -33,7 +33,8 @@ Public Class Helpers
.FileChangedAt = oFileModifiedAt, .FileChangedAt = oFileModifiedAt,
.FileContents = oContents, .FileContents = oContents,
.FileImportedAt = pDateImportedAt, .FileImportedAt = pDateImportedAt,
.FileChecksum = oFileHash .FileChecksum = oFileHash,
.FileInfoRaw = oFileInfo
} }
End Using End Using
End Using End Using

View File

@ -14,7 +14,7 @@ Namespace Modules.IDB
Public Async Function RunAsync(pObjectId As String, pState As String, Optional pOptions As SetObjectStateOptions = Nothing) As Task(Of Boolean) Public Async Function RunAsync(pObjectId As String, pState As String, Optional pOptions As SetObjectStateOptions = Nothing) As Task(Of Boolean)
Try Try
Dim oSql As String = $"EXEC PRIDB_OBJECT_SET_STATE {pObjectId}, '{pState}', '{pOptions.Username}', '{pOptions.Language}'" Dim oSql As String = $"EXEC PRIDB_OBJECT_SET_STATE {pObjectId}, '{pState}', '{pOptions.Username}'"
Dim oResult = Await Channel.ExecuteNonQuery_MSSQL_IDBAsync(oSql) Dim oResult = Await Channel.ExecuteNonQuery_MSSQL_IDBAsync(oSql)
If oResult.OK Then If oResult.OK Then

View File

@ -349,10 +349,11 @@ Public Class File
''' </summary> ''' </summary>
''' <remarks> ''' <remarks>
''' https://docs.microsoft.com/en-us/dotnet/standard/io/handling-io-errors ''' https://docs.microsoft.com/en-us/dotnet/standard/io/handling-io-errors
''' https://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use
''' </remarks> ''' </remarks>
Public Function TestFileIsLocked(pFilePath As String) As Boolean Public Function TestFileIsLocked(pFilePath As String) As Boolean
Try Try
Using stream As FileStream = IO.File.Open(pFilePath, FileMode.Open, FileAccess.Read, FileShare.None) Using stream As FileStream = IO.File.Open(pFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
stream.Close() stream.Close()
End Using End Using
Catch ex As Exception When ((ex.HResult And &HFFFF) = 32) Catch ex As Exception When ((ex.HResult And &HFFFF) = 32)
@ -388,9 +389,12 @@ Public Class File
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory) Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
If IO.Directory.Exists(oFinalDirectory) = False Then If IO.Directory.Exists(oFinalDirectory) = False Then
_Logger.Debug("Path does not exist, creating: [{0}]", oFinalDirectory)
Try Try
Directory.CreateDirectory(oFinalDirectory) Directory.CreateDirectory(oFinalDirectory)
_Logger.Debug("Created folder [{0}]", oFinalDirectory)
Catch ex As Exception Catch ex As Exception
_Logger.Warn("Final path [{0}] could not be created!", oFinalDirectory)
_Logger.Error(ex) _Logger.Error(ex)
End Try End Try
End If End If

View File

@ -0,0 +1,4 @@
DevExpress.XtraEditors.CheckEdit, DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
DevExpress.XtraEditors.TextEdit, DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
DevExpress.XtraLayout.LayoutControl, DevExpress.XtraLayout.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a
DevExpress.XtraEditors.ComboBoxEdit, DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a

View File

@ -138,26 +138,12 @@ Namespace IDB
Public Function GetFileObjectPath(pStore As GlobalState.ObjectStore, pDateImported As Date) As String Public Function GetFileObjectPath(pStore As GlobalState.ObjectStore, pDateImported As Date) As String
' Get directory by DateImported or, if not supplied, by current date ' Get directory by DateImported or, if not supplied, by current date
Dim oSubDirectory As String Dim oFinalPath As String
If IsNothing(pDateImported) Then If IsNothing(pDateImported) Then
oSubDirectory = FileEx.CreateDateDirectory(Now) oFinalPath = FileEx.CreateDateDirectory(pStore.Path, Now)
Else Else
oSubDirectory = FileEx.CreateDateDirectory(pDateImported) oFinalPath = FileEx.CreateDateDirectory(pStore.Path, pDateImported)
End If End If
Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
' Check and create final path, if necessary
Dim oFinalPath = IO.Path.Combine(pStore.Path, oSubDirectory)
If Not IO.Directory.Exists(oFinalPath) Then
Try
Logger.Debug("Path does not exist, creating: [{0}]", oFinalPath)
IO.Directory.CreateDirectory(oFinalPath)
Logger.Debug("Created folder [{0}]", oFinalPath)
Catch ex As Exception
LogAndThrow(ex, $"Store Directory [{oFinalPath}] could not be created!")
End Try
End If
Logger.Debug("Final Directory is [{0}]", oFinalPath)
Return oFinalPath Return oFinalPath
End Function End Function

View File

@ -59,13 +59,15 @@ Namespace Methods.IDB.NewFile
oFilePath = IO.Path.Combine(oFinalPath, oFileName) oFilePath = IO.Path.Combine(oFinalPath, oFileName)
Dim oFileObjectInfo As IO.FileInfo = New IO.FileInfo(oFilePath) Dim oFileObjectInfo As IO.FileInfo = New IO.FileInfo(oFilePath)
Dim oFileObjectSize As Long = pData.File.FileContents.Length
Dim oFileObjectName As String = oFileObjectInfo.Name Dim oFileObjectName As String = oFileObjectInfo.Name
Dim oOriginalExtension As String = pData.File.FileInfoRaw.Extension.Substring(1)
Logger.Debug("File Information for [{0}]:", oFileObjectName) Logger.Debug("File Information for [{0}]:", oFileObjectName)
Dim oFileObjectSize As Long = pData.File.FileContents.Length
Logger.Debug("Size: [{0}]", oFileObjectSize) Logger.Debug("Size: [{0}]", oFileObjectSize)
Dim oOriginalExtension As String = pData.File.FileInfoRaw.Extension.Substring(1)
Logger.Debug("Original Extension: [{0}]", oOriginalExtension) Logger.Debug("Original Extension: [{0}]", oOriginalExtension)
Logger.Debug("Checksum: [{0}]", pData.File.FileChecksum) Logger.Debug("Checksum: [{0}]", pData.File.FileChecksum)
Try Try

View File

@ -29,6 +29,8 @@ Namespace Methods.IDB.UpdateFile
'TODO: Create a view that collects all information about an idb object 'TODO: Create a view that collects all information about an idb object
Dim oResultObjectId As Long Dim oResultObjectId As Long
Logger.Debug("Creating new Version: [{0}]", pData.CreateNewVersion)
If pData.CreateNewVersion = False Then If pData.CreateNewVersion = False Then
' ---------------------------------------------- ' ----------------------------------------------
' -- Replace the existing file-object ' -- Replace the existing file-object
@ -71,7 +73,12 @@ Namespace Methods.IDB.UpdateFile
Dim oObjectRow As DataRow = oObjectTable.Rows.Item(0) Dim oObjectRow As DataRow = oObjectTable.Rows.Item(0)
Dim oKind As String = oObjectRow.Item("KIND_NAME") Dim oKind As String = oObjectRow.Item("KIND_NAME")
Dim oBusinessEntity As String = oObjectRow.Item("BE_NAME") Dim oBusinessEntity As String = oObjectRow.Item("BE_NAME")
Dim oStore As String = oObjectRow.ItemArray("STORE_NAME") Dim oStore As String = oObjectRow.Item("STORE_NAME")
Logger.Debug("Getting information for ObjectId [{0}]", pData.ObjectId)
Logger.Debug("Kind: [{0}]", oKind)
Logger.Debug("BE: [{0}]", oBusinessEntity)
Logger.Debug("Store: [{0}]", oStore)
Dim oNewFileMethod As New NewFile.NewFileMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState) Dim oNewFileMethod As New NewFile.NewFileMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oNewFileRequest As New NewFile.NewFileRequest With { Dim oNewFileRequest As New NewFile.NewFileRequest With {
@ -82,11 +89,17 @@ Namespace Methods.IDB.UpdateFile
.User = pData.User .User = pData.User
} }
Dim oNewFileResponse = oNewFileMethod.Run(oNewFileRequest) Dim oNewFileResponse = oNewFileMethod.Run(oNewFileRequest)
Dim oNewObjectId = oNewFileResponse.ObjectId
If oNewFileResponse.OK = False Then
LogAndThrow(oNewFileResponse.ErrorMessage)
End If
Dim oNewObjectId As Long = oNewFileResponse.ObjectId
Logger.Debug("New file Version has ObjectId [{0}]", oNewObjectId)
Dim oSql As String = $"EXEC PRIDB_NEW_VERSION_OBJECT '{pData.ObjectId}', '{oNewObjectId}', '{pData.User.UserName}'" Dim oSql As String = $"EXEC PRIDB_NEW_VERSION_OBJECT '{pData.ObjectId}', '{oNewObjectId}', '{pData.User.UserName}'"
DatabaseIDB.ExecuteNonQuery(oSql) DatabaseIDB.ExecuteNonQuery(oSql)
Logger.Debug("Versioning complete from [{0}] to [{1}]", pData.ObjectId, oNewObjectId)
oResultObjectId = oNewObjectId oResultObjectId = oNewObjectId
@ -97,7 +110,7 @@ Namespace Methods.IDB.UpdateFile
Return New UpdateFileResponse(oResultObjectId) Return New UpdateFileResponse(oResultObjectId)
Catch ex As Exception Catch ex As Exception
Logger.Warn("Error occurred while creating file!") Logger.Warn("Error occurred while updating file!")
Logger.Error(ex) Logger.Error(ex)
Logger.Info("Rolling back transaction.") Logger.Info("Rolling back transaction.")