From 607f7e6445f736f2c833031ac14a89f0ae6440e0 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 8 Feb 2022 16:29:43 +0100 Subject: [PATCH] EDMI: changes in newfile and updatefile method --- DDMonorepo.sln | 7 +++++++ Modules.EDMIAPI/Helpers.vb | 7 ++++--- Modules.EDMIAPI/Modules/IDB/SetObjectState.vb | 2 +- Modules.Filesystem/File.vb | 6 +++++- SQLConfig/My Project/licenses.licx | 4 ++++ Service.EDMIService/IDB/Helpers.vb | 20 +++--------------- .../Methods/IDB/NewFile/NewFileMethod.vb | 8 ++++--- .../IDB/UpdateFile/UpdateFileMethod.vb | 21 +++++++++++++++---- 8 files changed, 46 insertions(+), 29 deletions(-) diff --git a/DDMonorepo.sln b/DDMonorepo.sln index 18eb44d7..84f3fecd 100644 --- a/DDMonorepo.sln +++ b/DDMonorepo.sln @@ -144,6 +144,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EDMIService.Tests", "EDMISe EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Base", "Modules.Base\Base\Base.vbproj", "{6EA0C51F-C2B1-4462-8198-3DE0B32B74F8}" EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MessageBoxEx", "MessageBoxEx\MessageBoxEx.vbproj", "{EF29F400-BE45-4283-9D18-CA7ACD9ACCC9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.Release|Any CPU.ActiveCfg = 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 GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -450,6 +456,7 @@ Global {C9827B8D-9EF9-411A-A6BF-4807794F8C8F} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} {E3DA65CA-964D-4896-991A-B5426884E215} = {7AF3F9C2-C939-4A08-95C1-0453207E298A} {6EA0C51F-C2B1-4462-8198-3DE0B32B74F8} = {3E2008C8-27B1-41DD-9B1A-0C4029F6AECC} + {EF29F400-BE45-4283-9D18-CA7ACD9ACCC9} = {F98C0329-C004-417F-B2AB-7466E88D8220} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C1BE4090-A0FD-48AF-86CB-39099D14B286} diff --git a/Modules.EDMIAPI/Helpers.vb b/Modules.EDMIAPI/Helpers.vb index 53872b2d..6e503014 100644 --- a/Modules.EDMIAPI/Helpers.vb +++ b/Modules.EDMIAPI/Helpers.vb @@ -27,15 +27,16 @@ Public Class Helpers Dim oFileModifiedAt As Date = oFileInfo?.LastWriteTime Dim oFileHash As String = FileEx.GetChecksum(oFileInfo.FullName) - Return New FileProperties With { + Return New FileProperties With { .FileName = oFileInfo.Name, .FileCreatedAt = oFileCreatedAt, .FileChangedAt = oFileModifiedAt, .FileContents = oContents, .FileImportedAt = pDateImportedAt, - .FileChecksum = oFileHash + .FileChecksum = oFileHash, + .FileInfoRaw = oFileInfo } - End Using + End Using End Using End Function End Class diff --git a/Modules.EDMIAPI/Modules/IDB/SetObjectState.vb b/Modules.EDMIAPI/Modules/IDB/SetObjectState.vb index 1b85f4e9..63caed95 100644 --- a/Modules.EDMIAPI/Modules/IDB/SetObjectState.vb +++ b/Modules.EDMIAPI/Modules/IDB/SetObjectState.vb @@ -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) 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) If oResult.OK Then diff --git a/Modules.Filesystem/File.vb b/Modules.Filesystem/File.vb index 25b13f23..3caca1d5 100644 --- a/Modules.Filesystem/File.vb +++ b/Modules.Filesystem/File.vb @@ -349,10 +349,11 @@ Public Class File ''' ''' ''' 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 ''' Public Function TestFileIsLocked(pFilePath As String) As Boolean 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() End Using 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) If IO.Directory.Exists(oFinalDirectory) = False Then + _Logger.Debug("Path does not exist, creating: [{0}]", oFinalDirectory) Try Directory.CreateDirectory(oFinalDirectory) + _Logger.Debug("Created folder [{0}]", oFinalDirectory) Catch ex As Exception + _Logger.Warn("Final path [{0}] could not be created!", oFinalDirectory) _Logger.Error(ex) End Try End If diff --git a/SQLConfig/My Project/licenses.licx b/SQLConfig/My Project/licenses.licx index e69de29b..4f6348a0 100644 --- a/SQLConfig/My Project/licenses.licx +++ b/SQLConfig/My Project/licenses.licx @@ -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 diff --git a/Service.EDMIService/IDB/Helpers.vb b/Service.EDMIService/IDB/Helpers.vb index 7834fbc0..97475029 100644 --- a/Service.EDMIService/IDB/Helpers.vb +++ b/Service.EDMIService/IDB/Helpers.vb @@ -138,26 +138,12 @@ Namespace IDB Public Function GetFileObjectPath(pStore As GlobalState.ObjectStore, pDateImported As Date) As String ' Get directory by DateImported or, if not supplied, by current date - Dim oSubDirectory As String + Dim oFinalPath As String If IsNothing(pDateImported) Then - oSubDirectory = FileEx.CreateDateDirectory(Now) + oFinalPath = FileEx.CreateDateDirectory(pStore.Path, Now) Else - oSubDirectory = FileEx.CreateDateDirectory(pDateImported) + oFinalPath = FileEx.CreateDateDirectory(pStore.Path, pDateImported) 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 End Function diff --git a/Service.EDMIService/Methods/IDB/NewFile/NewFileMethod.vb b/Service.EDMIService/Methods/IDB/NewFile/NewFileMethod.vb index 79cfd6b6..49251aaf 100644 --- a/Service.EDMIService/Methods/IDB/NewFile/NewFileMethod.vb +++ b/Service.EDMIService/Methods/IDB/NewFile/NewFileMethod.vb @@ -59,13 +59,15 @@ Namespace Methods.IDB.NewFile oFilePath = IO.Path.Combine(oFinalPath, oFileName) Dim oFileObjectInfo As IO.FileInfo = New IO.FileInfo(oFilePath) - Dim oFileObjectSize As Long = pData.File.FileContents.Length Dim oFileObjectName As String = oFileObjectInfo.Name - Dim oOriginalExtension As String = pData.File.FileInfoRaw.Extension.Substring(1) - Logger.Debug("File Information for [{0}]:", oFileObjectName) + + Dim oFileObjectSize As Long = pData.File.FileContents.Length Logger.Debug("Size: [{0}]", oFileObjectSize) + + Dim oOriginalExtension As String = pData.File.FileInfoRaw.Extension.Substring(1) Logger.Debug("Original Extension: [{0}]", oOriginalExtension) + Logger.Debug("Checksum: [{0}]", pData.File.FileChecksum) Try diff --git a/Service.EDMIService/Methods/IDB/UpdateFile/UpdateFileMethod.vb b/Service.EDMIService/Methods/IDB/UpdateFile/UpdateFileMethod.vb index 4fc54766..f927d80d 100644 --- a/Service.EDMIService/Methods/IDB/UpdateFile/UpdateFileMethod.vb +++ b/Service.EDMIService/Methods/IDB/UpdateFile/UpdateFileMethod.vb @@ -29,6 +29,8 @@ Namespace Methods.IDB.UpdateFile 'TODO: Create a view that collects all information about an idb object Dim oResultObjectId As Long + Logger.Debug("Creating new Version: [{0}]", pData.CreateNewVersion) + If pData.CreateNewVersion = False Then ' ---------------------------------------------- ' -- Replace the existing file-object @@ -71,7 +73,12 @@ Namespace Methods.IDB.UpdateFile Dim oObjectRow As DataRow = oObjectTable.Rows.Item(0) Dim oKind As String = oObjectRow.Item("KIND_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 oNewFileRequest As New NewFile.NewFileRequest With { @@ -82,11 +89,17 @@ Namespace Methods.IDB.UpdateFile .User = pData.User } 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}'" DatabaseIDB.ExecuteNonQuery(oSql) - + Logger.Debug("Versioning complete from [{0}] to [{1}]", pData.ObjectId, oNewObjectId) oResultObjectId = oNewObjectId @@ -97,7 +110,7 @@ Namespace Methods.IDB.UpdateFile Return New UpdateFileResponse(oResultObjectId) Catch ex As Exception - Logger.Warn("Error occurred while creating file!") + Logger.Warn("Error occurred while updating file!") Logger.Error(ex) Logger.Info("Rolling back transaction.")