8 Commits

Author SHA1 Message Date
Jonathan Jenne
533df59b1f EDMIService: First completed version of UpdateFileMethod 2022-02-07 14:10:52 +01:00
Jonathan Jenne
deef67b548 Filesystem: Version 1.3.0.0 2022-02-07 14:10:15 +01:00
Jonathan Jenne
b946f11e04 Filesystem: Add date parameter for GetDateString and GetDateTimeString and CreateDateDirectory 2022-02-07 14:09:35 +01:00
Jonathan Jenne
def5518e6c EDMIAPI: Version 1.5.0.0 2022-02-07 14:08:22 +01:00
Jonathan Jenne
1e5d8c96fd EDMIAPI: Add SetObjectState Function 2022-02-07 14:07:46 +01:00
Jonathan Jenne
41447e80c5 Base: Add more Filestore constants 2022-02-07 14:07:20 +01:00
Jonathan Jenne
a531fa9c83 Common: Version 1.9.1 2022-02-07 14:06:54 +01:00
Jonathan Jenne
9f4734f50f Common/DocumentResultList: Handle file open, Update file with respect to Doctype options 2022-02-07 14:06:25 +01:00
15 changed files with 270 additions and 244 deletions

View File

@@ -28,6 +28,7 @@ Namespace DocumentResultList
Private ReadOnly ProcessedFiles As New List(Of OpenFile) Private ReadOnly ProcessedFiles As New List(Of OpenFile)
Public Event FileChanged As EventHandler(Of FileChangedArgs) Public Event FileChanged As EventHandler(Of FileChangedArgs)
Public Event FileOpened As EventHandler(Of FileOpenedArgs)
Public Class OpenFile Public Class OpenFile
Public Document As Document Public Document As Document
@@ -40,6 +41,10 @@ Namespace DocumentResultList
Public File As OpenFile Public File As OpenFile
End Class End Class
Public Class FileOpenedArgs
Public File As OpenFile
End Class
Public Sub New(pLogConfig As LogConfig) Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
FileEx = New Modules.Filesystem.File(pLogConfig) FileEx = New Modules.Filesystem.File(pLogConfig)
@@ -67,14 +72,19 @@ Namespace DocumentResultList
Logger.Debug("File [{0}] opened with ProcessId [{1}]", oFilePath, oProcess.Id) Logger.Debug("File [{0}] opened with ProcessId [{1}]", oFilePath, oProcess.Id)
OpenFiles.Add(New OpenFile With { Dim oOpenFile = New OpenFile With {
.Document = pDocument, .Document = pDocument,
.FilePath = oFilePath, .FilePath = oFilePath,
.ProcessId = oProcess.Id .ProcessId = oProcess.Id
}) }
OpenFiles.Add(oOpenFile)
RaiseEvent FileOpened(Me, New FileOpenedArgs With {.File = oOpenFile})
If FileOpenTimer.Enabled = False Then If FileOpenTimer.Enabled = False Then
' Waiting a while before actually starting the timer to allow for
' opening the file without checking for use already.
Await Task.Delay(FILE_OPEN_HANDLE_INTERVAL)
FileOpenTimer.Interval = FILE_OPEN_HANDLE_INTERVAL FileOpenTimer.Interval = FILE_OPEN_HANDLE_INTERVAL
FileOpenTimer.Start() FileOpenTimer.Start()
End If End If

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.9.0.0")> <Assembly: AssemblyVersion("1.9.1.0")>
<Assembly: AssemblyFileVersion("1.9.0.0")> <Assembly: AssemblyFileVersion("1.9.1.0")>

View File

@@ -14,10 +14,12 @@ Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraPrinting Imports DevExpress.XtraPrinting
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Imports DigitalData.Modules.EDMI.API Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Language Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.ZooFlow Imports DigitalData.Modules.ZooFlow
Imports DigitalData.Modules.ZooFlow.Constants Imports DigitalData.Modules.ZooFlow.Constants
Imports DigitalData.Modules.Base.IDB.FileStore
Public Class frmDocumentResultList Public Class frmDocumentResultList
Implements IResultForm Implements IResultForm
@@ -236,10 +238,17 @@ Public Class frmDocumentResultList
End Try End Try
End Sub End Sub
Public Async Sub Watcher_FileOpened(sender As Object, e As DocumentResultList.Watcher.FileOpenedArgs) Handles Watcher.FileOpened
Await _IDBClient.SetObjectStateAsync(e.File.Document.Id, OBJECT_STATE_FILE_OPENED, New Options.SetObjectStateOptions With {
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
End Sub
Public Async Sub Watcher_FileChanged(sender As Object, e As DocumentResultList.Watcher.FileChangedArgs) Handles Watcher.FileChanged Public Async Sub Watcher_FileChanged(sender As Object, e As DocumentResultList.Watcher.FileChangedArgs) Handles Watcher.FileChanged
Try Try
Dim oDoctype = Nothing Dim oDoctype As GlobalStateDoctype = Nothing
If e.File.Document.DocumentType IsNot Nothing Then If e.File.Document.DocumentType IsNot Nothing Then
oDoctype = _IDBClient.ClientConfig.DocumentTypes. oDoctype = _IDBClient.ClientConfig.DocumentTypes.
@@ -247,34 +256,27 @@ Public Class frmDocumentResultList
FirstOrDefault() FirstOrDefault()
End If End If
Dim oFileInfo = New FileInfo(e.File.FilePath) If oDoctype IsNot Nothing Then
Dim oMessage = $"Die Datei '{oFileInfo.Name}' wurde außerhalb des Systems verändert. Wollen Sie diese Änderung als neue Version in das System übernehmen? 'Nein' überschreibt die ursprüngliche Datei." Select Case oDoctype.FileChangedAction
Dim oResult As DialogResult = MsgBox(oMessage, MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Question, "Datei verändert") Case FILE_CHANGED_OVERWRITE
Await Watcher_OverwriteFile(e.File)
' Three possibilities: Case FILE_CHANGED_VERSION
' Await Watcher_VersionFile(e.File)
' - Yes: Version file
' - No: Overwrite file Case FILE_CHANGED_QUESTION
' - Cancel: Abort update Await Watcher_Ask(e.File)
Select Case oResult
Case DialogResult.Cancel
' MsgBox("Abbruch!")
Case Else Case Else
Dim oCreateNewFileVersion = IIf(oResult = DialogResult.Yes, True, False) Await Watcher_Ask(e.File)
Dim oObjectId = Await _IDBClient.UpdateFileAsync(e.File.Document.Id, e.File.FilePath, New Options.UpdateFileOptions With {
.CreateNewFileVersion = oCreateNewFileVersion,
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
If IsNothing(oObjectId) Then
MsgBox($"Beim Speichern der Datei '{oFileInfo.Name}' Fehler ist ein Fehler aufgetreten!", MsgBoxStyle.Critical, Text)
Else
MsgBox($"Die Datei '{oFileInfo.Name}' wurde erfolgreich gespeichert!", MsgBoxStyle.Information, Text)
End If
End Select End Select
Else
Await Watcher_Ask(e.File)
End If
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Show_CriticalError(ex) Show_CriticalError(ex)
@@ -286,6 +288,56 @@ Public Class frmDocumentResultList
End Try End Try
End Sub End Sub
Private Async Function Watcher_OverwriteFile(pFile As DocumentResultList.Watcher.OpenFile) As Task
Await Watcher_UpdateFile(pFile, pCreateNewVersion:=False)
Await _IDBClient.SetObjectStateAsync(pFile.Document.Id, OBJECT_STATE_FILE_CHANGED, New Options.SetObjectStateOptions With {
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
End Function
Private Async Function Watcher_VersionFile(pFile As DocumentResultList.Watcher.OpenFile) As Task
Await Watcher_UpdateFile(pFile, pCreateNewVersion:=True)
Await _IDBClient.SetObjectStateAsync(pFile.Document.Id, OBJECT_STATE_FILE_VERSIONED, New Options.SetObjectStateOptions With {
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
End Function
Private Async Function Watcher_UpdateFile(pFile As DocumentResultList.Watcher.OpenFile, pCreateNewVersion As Boolean) As Task
Dim oFileInfo As New FileInfo(pFile.FilePath)
Dim oObjectId = Await _IDBClient.UpdateFileAsync(pFile.Document.Id, pFile.FilePath, New Options.UpdateFileOptions With {
.CreateNewFileVersion = pCreateNewVersion,
.Language = Environment.User.Language,
.Username = Environment.User.UserName
})
If IsNothing(oObjectId) Then
MsgBox($"Beim Speichern der Datei '{oFileInfo.Name}' Fehler ist ein Fehler aufgetreten!", MsgBoxStyle.Critical, Text)
Else
MsgBox($"Die Datei '{oFileInfo.Name}' wurde erfolgreich gespeichert!", MsgBoxStyle.Information, Text)
End If
End Function
Private Async Function Watcher_Ask(pFile As DocumentResultList.Watcher.OpenFile) As Task
Dim oFileInfo = New FileInfo(pFile.FilePath)
Dim oMessage = $"Die Datei '{oFileInfo.Name}' wurde außerhalb des Systems verändert. Wollen Sie diese Änderung als neue Version in das System übernehmen? 'Nein' überschreibt die ursprüngliche Datei."
Dim oResult As DialogResult = MsgBox(oMessage, MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Question, "Datei verändert")
Select Case oResult
Case DialogResult.Yes
Await Watcher_VersionFile(pFile)
Case DialogResult.No
Await Watcher_OverwriteFile(pFile)
Case Else
' Cancel, do nothing
End Select
End Function
Private Function InitAppServer() As Boolean Private Function InitAppServer() As Boolean
Dim oSplit As List(Of String) = Environment.Service.Address.Split(":").ToList() Dim oSplit As List(Of String) = Environment.Service.Address.Split(":").ToList()

View File

@@ -1,13 +1,6 @@
Namespace IDB Namespace IDB
Public Class Database Public Class Database
Public Const OBJECT_STATE_FILE_ADDED = "File added"
Public Const OBJECT_STATE_FILE_VERSIONED = "File versioned"
Public Const OBJECT_STATE_FILE_CHANGED = "File changed"
Public Const OBJECT_STATE_FILE_DELETED = "File deleted"
Public Const OBJECT_STATE_METADATA_CHANGED = "Metadata changed"
Public Const OBJECT_STATE_ATTRIBUTEVALUE_DELETED = "Attributevalue deleted"
Public Enum NamedDatabase Public Enum NamedDatabase
ECM ECM
IDB IDB

View File

@@ -1,6 +1,18 @@
Namespace IDB Namespace IDB
Public Class FileStore Public Class FileStore
Public Const FILE_STORE_INVALID_OBEJCT_ID = 0 Public Const FILE_STORE_INVALID_OBEJCT_ID = 0
Public Const FILE_CHANGED_QUESTION = "QUESTION VERSION"
Public Const FILE_CHANGED_OVERWRITE = "AUTO REPLACE"
Public Const FILE_CHANGED_VERSION = "AUTO VERSION"
Public Const OBJECT_STATE_FILE_ADDED = "File added"
Public Const OBJECT_STATE_FILE_VERSIONED = "File versioned"
Public Const OBJECT_STATE_FILE_CHANGED = "File changed"
Public Const OBJECT_STATE_FILE_OPENED = "File opened"
Public Const OBJECT_STATE_FILE_DELETED = "File deleted"
Public Const OBJECT_STATE_METADATA_CHANGED = "Metadata changed"
Public Const OBJECT_STATE_ATTRIBUTEVALUE_DELETED = "Attributevalue deleted"
End Class End Class
End Namespace End Namespace

View File

@@ -194,9 +194,11 @@ Public Class Client
Try Try
Dim oNewFile As New Modules.IDB.NewFile(LogConfig, Channel) Dim oNewFile As New Modules.IDB.NewFile(LogConfig, Channel)
Return Await oNewFile.RunAsync(pFilePath, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions) Return Await oNewFile.RunAsync(pFilePath, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return Nothing Return Nothing
End Try End Try
End Function End Function
@@ -204,9 +206,23 @@ Public Class Client
Try Try
Dim oUpdateFile As New Modules.IDB.UpdateFile(LogConfig, Channel) Dim oUpdateFile As New Modules.IDB.UpdateFile(LogConfig, Channel)
Return Await oUpdateFile.RunAsync(pFilePath, pObjectId, pImportOptions) Return Await oUpdateFile.RunAsync(pFilePath, pObjectId, pImportOptions)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return Nothing Return Nothing
End Try
End Function
Public Async Function SetObjectStateAsync(pObjectId As Long, pState As String, Optional pOptions As Options.SetObjectStateOptions = Nothing) As Task(Of Boolean)
Try
Dim oSetObjectState As New Modules.IDB.SetObjectState(LogConfig, Channel)
Return Await oSetObjectState.RunAsync(pObjectId, pState, pOptions)
Catch ex As Exception
Logger.Error(ex)
Return False
End Try End Try
End Function End Function
@@ -221,9 +237,11 @@ Public Class Client
Try Try
Dim oImportFile As New Modules.Globix.ImportFile(LogConfig, Channel) Dim oImportFile As New Modules.Globix.ImportFile(LogConfig, Channel)
Return Await oImportFile.RunAsync(pFilePath, pProfileId, pAttributeValues, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions) Return Await oImportFile.RunAsync(pFilePath, pProfileId, pAttributeValues, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions)
Catch ex As Exception Catch ex As Exception
Logger.Error(ex) Logger.Error(ex)
Return Nothing Return Nothing
End Try End Try
End Function End Function

View File

@@ -43,6 +43,16 @@
Public Property DateImported As Date = Date.Now Public Property DateImported As Date = Date.Now
End Class End Class
Public Class SetObjectStateOptions
Inherits BaseOptions
''' <summary>
''' Date when the file was imported. Can be in the past. Defaults to now.
''' </summary>
Public Property DateImported As Date = Date.Now
End Class
Public Class GetVariableValueOptions Public Class GetVariableValueOptions
Inherits BaseOptions Inherits BaseOptions
End Class End Class

View File

@@ -80,6 +80,7 @@
<Compile Include="Modules\Globix\ImportFile.vb" /> <Compile Include="Modules\Globix\ImportFile.vb" />
<Compile Include="Helpers.vb" /> <Compile Include="Helpers.vb" />
<Compile Include="Modules\IDB\NewFile.vb" /> <Compile Include="Modules\IDB\NewFile.vb" />
<Compile Include="Modules\IDB\SetObjectState.vb" />
<Compile Include="Modules\IDB\UpdateFile.vb" /> <Compile Include="Modules\IDB\UpdateFile.vb" />
<Compile Include="Modules\ZooFlow\GetFileObject.vb" /> <Compile Include="Modules\ZooFlow\GetFileObject.vb" />
<Compile Include="Connected Services\EDMIServiceReference\Reference.vb"> <Compile Include="Connected Services\EDMIServiceReference\Reference.vb">

View File

@@ -0,0 +1,34 @@
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.EDMI.API.Options
Imports DigitalData.Modules.Logging
Namespace Modules.IDB
Public Class SetObjectState
Inherits BaseMethod
Public Sub New(pLogConfig As LogConfig, pChannel As IEDMIServiceChannel)
MyBase.New(pLogConfig, pChannel)
End Sub
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 oResult = Await Channel.ExecuteNonQuery_MSSQL_IDBAsync(oSql)
If oResult.OK Then
Return True
End If
Logger.Warn("Error while setting Object State: [{0}]", oResult.ErrorMessage)
Return False
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
End Class
End Namespace

View File

@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyCompany("Digital Data")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("EDMIAPI")> <Assembly: AssemblyProduct("EDMIAPI")>
<Assembly: AssemblyCopyright("Copyright © 2022")> <Assembly: AssemblyCopyright("Copyright © 2022")>
<Assembly: AssemblyTrademark("1.4.0.0")> <Assembly: AssemblyTrademark("1.5.0.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.4.0.0")> <Assembly: AssemblyVersion("1.5.0.0")>
<Assembly: AssemblyFileVersion("1.4.0.0")> <Assembly: AssemblyFileVersion("1.5.0.0")>

View File

@@ -373,14 +373,18 @@ Public Class File
Return oIsDirectory Return oIsDirectory
End Function End Function
Public Function GetDateDirectory(pBaseDirectory As String) As String Public Function GetDateDirectory(pBaseDirectory As String, pDate As Date) As String
Dim oDateDirectory = GetDateString() Dim oDateDirectory = GetDateString(pDate)
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory) Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
Return oFinalDirectory Return oFinalDirectory
End Function End Function
Public Function CreateDateDirectory(pBaseDirectory As String) As String Public Function GetDateDirectory(pBaseDirectory As String) As String
Dim oDateDirectory = GetDateString() Return GetDateDirectory(pBaseDirectory, Now)
End Function
Public Function CreateDateDirectory(pBaseDirectory As String, pDate As Date) As String
Dim oDateDirectory = GetDateString(pDate)
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
@@ -394,14 +398,26 @@ Public Class File
Return oFinalDirectory Return oFinalDirectory
End Function End Function
Public Function CreateDateDirectory(pBaseDirectory As String) As String
Return CreateDateDirectory(pBaseDirectory, Now)
End Function
Public Function GetDateString() As String Public Function GetDateString() As String
Return $"{Now:yyyy\\MM\\dd}" Return $"{Now:yyyy\\MM\\dd}"
End Function End Function
Public Function GetDateString(pDate As Date) As String
Return $"{pDate:yyyy\\MM\\dd}"
End Function
Public Function GetDateTimeString() As String Public Function GetDateTimeString() As String
Return $"{Now:yyyy-MM-dd_hh-mm-ffff}" Return $"{Now:yyyy-MM-dd_hh-mm-ffff}"
End Function End Function
Public Function GetDateTimeString(pDate As Date) As String
Return $"{pDate:yyyy-MM-dd_hh-mm-ffff}"
End Function
Public Function GetFilenameWithSuffix(pFilePath As String, pSuffix As String) Public Function GetFilenameWithSuffix(pFilePath As String, pSuffix As String)
Dim oFileInfo = New IO.FileInfo(pFilePath) Dim oFileInfo = New IO.FileInfo(pFilePath)
Return GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pFilePath), pSuffix, oFileInfo.Extension.Substring(1)) Return GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pFilePath), pSuffix, oFileInfo.Extension.Substring(1))

View File

@@ -12,8 +12,8 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("")> <Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Digital Data")> <Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("Modules.Filesystem")> <Assembly: AssemblyProduct("Modules.Filesystem")>
<Assembly: AssemblyCopyright("Copyright © 2021")> <Assembly: AssemblyCopyright("Copyright © 2022")>
<Assembly: AssemblyTrademark("")> <Assembly: AssemblyTrademark("1.3.0.0")>
<Assembly: ComVisible(False)> <Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben: ' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")> ' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.2.1.0")> <Assembly: AssemblyVersion("1.3.0.0")>
<Assembly: AssemblyFileVersion("1.2.1.0")> <Assembly: AssemblyFileVersion("1.3.0.0")>

View File

@@ -2,12 +2,11 @@
Imports DigitalData.Modules.Database.MSSQLServer Imports DigitalData.Modules.Database.MSSQLServer
Imports DigitalData.Modules.Language Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.EDMI.API.Client
Imports System.Data.SqlClient Imports System.Data.SqlClient
Imports System.IO
Imports DigitalData.Modules.ZooFlow.State Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Modules.Patterns Imports DigitalData.Modules.Patterns
Imports DigitalData.Services.EDMIService.Methods.IDB Imports DigitalData.Services.EDMIService.Methods.IDB
Imports DigitalData.Modules.Filesystem
Namespace IDB Namespace IDB
Public Class Helpers Public Class Helpers
@@ -15,15 +14,17 @@ Namespace IDB
Private ReadOnly Patterns As Patterns2 Private ReadOnly Patterns As Patterns2
Private ReadOnly Database As MSSQLServer Private ReadOnly Database As MSSQLServer
Private ReadOnly FileEx As File
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer) Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
Patterns = New Patterns2(pLogConfig) Patterns = New Patterns2(pLogConfig)
Database = pMSSQLServer Database = pMSSQLServer
FileEx = New File(pLogConfig)
End Sub End Sub
Public Function GetPlaceholderValue(pValue As String, Public Function GetPlaceholderValue(pValue As String,
pFileInfo As FileInfo, pFileInfo As IO.FileInfo,
pUserState As UserState, pUserState As UserState,
pUserAttributes As Dictionary(Of String, List(Of String)), pUserAttributes As Dictionary(Of String, List(Of String)),
pAutoAttributes As Dictionary(Of String, List(Of String))) As String pAutoAttributes As Dictionary(Of String, List(Of String))) As String
@@ -135,6 +136,32 @@ Namespace IDB
End Try End Try
End Function End Function
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
If IsNothing(pDateImported) Then
oSubDirectory = FileEx.CreateDateDirectory(Now)
Else
oSubDirectory = FileEx.CreateDateDirectory(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
Public Function GetObject(pObjectId As Long) As IDBObject Public Function GetObject(pObjectId As Long) As IDBObject
Try Try
Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}" Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"

View File

@@ -34,37 +34,17 @@ Namespace Methods.IDB.NewFile
' Find ObjectStore by Title ' Find ObjectStore by Title
Logger.Debug("Checking for DataStore [{0}].", pData.StoreName) Logger.Debug("Checking for DataStore [{0}].", pData.StoreName)
Dim oStore = GlobalState.ObjectStores.Where(Function(store) store.Title.Equals(pData.StoreName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault() Dim oStore = GlobalState.ObjectStores.
Where(Function(store) store.Title = pData.StoreName).
SingleOrDefault()
If oStore Is Nothing Then If oStore Is Nothing Then
LogAndThrow($"DataStore [{pData.StoreName}] does not exist. Exiting.") LogAndThrow($"DataStore [{pData.StoreName}] does not exist. Exiting.")
End If End If
' Get Store base path ' Get Store base and final path
Dim oBasePath As String = oStore.Path Logger.Debug("Store BasePath is [{0}]", oStore.Path)
Logger.Debug("Store BasePath is [{0}]", oBasePath) Dim oFinalPath = Helpers.GetFileObjectPath(oStore, pData.File.FileImportedAt)
' Get directory by DateImported or, if not supplied, by current date
Dim oSubDirectory As String
If IsNothing(pData.File.FileImportedAt) Then
oSubDirectory = GetDateSubDirectory(Now)
Else
oSubDirectory = GetDateSubDirectory(pData.File.FileImportedAt)
End If
Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
' Check and create final path, if necessary
Dim oFinalPath = IO.Path.Combine(oBasePath, 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)
' Get filename ' Get filename
Dim oKeepFileName As Boolean = False Dim oKeepFileName As Boolean = False
@@ -182,10 +162,6 @@ Namespace Methods.IDB.NewFile
Return $"{IDB_OBJ_ID}.ddfo" Return $"{IDB_OBJ_ID}.ddfo"
End If End If
End Function End Function
Private Function GetDateSubDirectory(pDate As Date) As String
Return IO.Path.Combine(pDate.ToString("yyyy"), pDate.ToString("MM"), pDate.ToString("dd"))
End Function
End Class End Class
End Namespace End Namespace

View File

@@ -20,7 +20,6 @@ Namespace Methods.IDB.UpdateFile
End Sub End Sub
Public Function Run(pData As UpdateFileRequest) As UpdateFileResponse Public Function Run(pData As UpdateFileRequest) As UpdateFileResponse
Try Try
' TODO: Update file object ' TODO: Update file object
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
@@ -28,8 +27,13 @@ Namespace Methods.IDB.UpdateFile
End If 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
Dim oResultObjectId As Long
If pData.CreateNewVersion = False Then If pData.CreateNewVersion = False Then
' ----------------------------------------------
' -- Replace the existing file-object
' ----------------------------------------------
Dim oGetFileObject As New GetFileObject.GetFileObjectMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState) Dim oGetFileObject As New GetFileObject.GetFileObjectMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oArgs = New GetFileObject.GetFileObjectRequest With { Dim oArgs = New GetFileObject.GetFileObjectRequest With {
.ObjectId = pData.ObjectId, .ObjectId = pData.ObjectId,
@@ -56,178 +60,51 @@ Namespace Methods.IDB.UpdateFile
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!") LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
End Try End Try
Return New UpdateFileResponse(pData.ObjectId) oResultObjectId = pData.ObjectId
Else Else
Throw New ApplicationException("Not implemented!!") ' ----------------------------------------------
' -- Create a new object + file object
' ----------------------------------------------
Dim oObjectTable = DatabaseIDB.GetDatatable($"Select * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pData.ObjectId}")
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 oNewFileMethod As New NewFile.NewFileMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
Dim oNewFileRequest As New NewFile.NewFileRequest With {
.File = pData.File,
.BusinessEntity = oBusinessEntity,
.KindType = oKind,
.StoreName = oStore,
.User = pData.User
}
Dim oNewFileResponse = oNewFileMethod.Run(oNewFileRequest)
Dim oNewObjectId = oNewFileResponse.ObjectId
Dim oSql As String = $"EXEC PRIDB_NEW_VERSION_OBJECT '{pData.ObjectId}', '{oNewObjectId}', '{pData.User.UserName}'"
DatabaseIDB.ExecuteNonQuery(oSql)
oResultObjectId = oNewObjectId
End If End If
' Finally, commit the transaction
Transaction?.Commit()
Return New UpdateFileResponse(oResultObjectId)
Catch ex As Exception Catch ex As Exception
Logger.Warn("Error occurred while creating file!")
Logger.Error(ex)
Logger.Info("Rolling back transaction.")
Transaction?.Rollback()
Return New UpdateFileResponse(ex) Return New UpdateFileResponse(ex)
End Try End Try
'Dim oFilePath As String = Nothing
'
'Dim oExistingObjectId = TestFileChecksumExists(pData.File.FileChecksum)
'If oExistingObjectId > 0 Then
' Return New UpdateFileResponse(oExistingObjectId)
'End If
'Try
' Dim oObjectId = NewObjectId(pData.KindType, pData.BusinessEntity, pData.User.UserName)
' If oObjectId = 0 Then
' LogAndThrow("Could not create new ObjectId!")
' End If
' ' Find ObjectStore by Title
' Logger.Debug("Checking for DataStore [{0}].", pData.StoreName)
' Dim oStore = GlobalState.ObjectStores.
' Where(Function(store) store.Title.Equals(pData.StoreName, StringComparison.OrdinalIgnoreCase)).
'SingleOrDefault()
' If oStore Is Nothing Then
' LogAndThrow($"DataStore [{pData.StoreName}] does not exist. Exiting.")
' End If
' ' Get Store base path
' Dim oBasePath As String = oStore.Path
' Logger.Debug("Store BasePath is [{0}]", oBasePath)
' ' Get directory by DateImported or, if not supplied, by current date
' Dim oSubDirectory As String
' If IsNothing(pData.File.FileImportedAt) Then
' oSubDirectory = GetDateSubDirectory(Now)
' Else
' oSubDirectory = GetDateSubDirectory(pData.File.FileImportedAt)
' End If
' Logger.Debug("Subdirectory is [{0}]", oSubDirectory)
' ' Check and create final path, if necessary
' Dim oFinalPath = IO.Path.Combine(oBasePath, 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)
' ' Get filename
' Dim oKeepFileName As Boolean = False
' If oStore.IsArchive Then
' Logger.Debug("Object Store is an archive: [{0}]", oStore.IsArchive)
' oKeepFileName = True
' End If
' Dim oFileName As String = GetFileObjectFileName(oObjectId, pData.File.FileName, oKeepFileName)
' Logger.Debug("Filename is [{0}]", oFileName)
' 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)
' Logger.Debug("Size: [{0}]", oFileObjectSize)
' Logger.Debug("Original Extension: [{0}]", oOriginalExtension)
' Logger.Debug("Checksum: [{0}]", pData.File.FileChecksum)
' 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
' '---------------------------------------------------------------------------
' Logger.Info("Creating IDB FileObject for ObjectId [{0}].", oObjectId)
' ' Insert into DB
' Dim oSQL As String = $"EXEC PRIDB_NEW_IDBFO
' '{oFinalPath}',
' '{oFileObjectName}',
' '{oOriginalExtension}',
' {oFileObjectSize},
' '{pData.File.FileChecksum}' ,
' '{pData.User.UserName}',
' '{oObjectId}',
' {oStore.Id}"
' Dim oResult As Boolean = DatabaseIDB.ExecuteNonQueryWithConnectionObject(oSQL, Connection, ExternalTransaction, Transaction)
' If oResult = False Then
' LogAndThrow("IDB FileObject could not be created!")
' End If
' '---------------------------------------------------------------------------
' '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}
'}
' For Each oAttribute As KeyValuePair(Of String, Object) In oSystemAttributes
' Try
' ' Dont write empty attributes
' If oAttribute.Value Is Nothing Then
' Continue For
' End If
' Dim oSuccess = Helpers.SetAttributeValue(Connection, Transaction, oObjectId, oAttribute.Key, oAttribute.Value, pData.User.Language, pData.User.UserName)
' If oSuccess Then
' Logger.Debug("System Attribute [{0}] written with value [{1}]", oAttribute.Key, oAttribute.Value)
' Else
' Logger.Warn("System attribute value could not be written")
' End If
' Catch ex As Exception
' LogAndThrow(ex, $"System attribute [{oAttribute.Key}] could not be written!")
' End Try
' Next
' '---------------------------------------------------------------------------
' ' Finally, commit the transaction
' Transaction?.Commit()
' Return New UpdateFileResponse(oObjectId)
'Catch ex As Exception
' Logger.Warn("Error occurred while creating file!")
' Logger.Error(ex)
' Logger.Info("Cleaning up files.")
' If Not IsNothing(oFilePath) AndAlso IO.File.Exists(oFilePath) Then
' Try
' IO.File.Delete(oFilePath)
' Catch exInner As Exception
' Logger.Warn("Error while cleaning up files.")
' Logger.Error(exInner)
' End Try
' End If
' Logger.Info("Rolling back transaction.")
' Transaction?.Rollback()
' Return New UpdateFileResponse(ex)
'End Try
End Function End Function
Private Function TestFileChecksumExists(pChecksum As String) As Long Private Function TestFileChecksumExists(pChecksum As String) As Long