Compare commits
8 Commits
67852d4572
...
533df59b1f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
533df59b1f | ||
|
|
deef67b548 | ||
|
|
b946f11e04 | ||
|
|
def5518e6c | ||
|
|
1e5d8c96fd | ||
|
|
41447e80c5 | ||
|
|
a531fa9c83 | ||
|
|
9f4734f50f |
@@ -28,6 +28,7 @@ Namespace DocumentResultList
|
||||
Private ReadOnly ProcessedFiles As New List(Of OpenFile)
|
||||
|
||||
Public Event FileChanged As EventHandler(Of FileChangedArgs)
|
||||
Public Event FileOpened As EventHandler(Of FileOpenedArgs)
|
||||
|
||||
Public Class OpenFile
|
||||
Public Document As Document
|
||||
@@ -40,6 +41,10 @@ Namespace DocumentResultList
|
||||
Public File As OpenFile
|
||||
End Class
|
||||
|
||||
Public Class FileOpenedArgs
|
||||
Public File As OpenFile
|
||||
End Class
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
FileEx = New Modules.Filesystem.File(pLogConfig)
|
||||
@@ -67,14 +72,19 @@ Namespace DocumentResultList
|
||||
|
||||
Logger.Debug("File [{0}] opened with ProcessId [{1}]", oFilePath, oProcess.Id)
|
||||
|
||||
OpenFiles.Add(New OpenFile With {
|
||||
Dim oOpenFile = New OpenFile With {
|
||||
.Document = pDocument,
|
||||
.FilePath = oFilePath,
|
||||
.ProcessId = oProcess.Id
|
||||
})
|
||||
}
|
||||
OpenFiles.Add(oOpenFile)
|
||||
|
||||
RaiseEvent FileOpened(Me, New FileOpenedArgs With {.File = oOpenFile})
|
||||
|
||||
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.Start()
|
||||
End If
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.9.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.9.0.0")>
|
||||
<Assembly: AssemblyVersion("1.9.1.0")>
|
||||
<Assembly: AssemblyFileVersion("1.9.1.0")>
|
||||
|
||||
@@ -14,10 +14,12 @@ Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
|
||||
Imports DevExpress.XtraPrinting
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.EDMI.API
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.ZooFlow
|
||||
Imports DigitalData.Modules.ZooFlow.Constants
|
||||
Imports DigitalData.Modules.Base.IDB.FileStore
|
||||
|
||||
Public Class frmDocumentResultList
|
||||
Implements IResultForm
|
||||
@@ -236,10 +238,17 @@ Public Class frmDocumentResultList
|
||||
End Try
|
||||
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
|
||||
Try
|
||||
|
||||
Dim oDoctype = Nothing
|
||||
Dim oDoctype As GlobalStateDoctype = Nothing
|
||||
|
||||
If e.File.Document.DocumentType IsNot Nothing Then
|
||||
oDoctype = _IDBClient.ClientConfig.DocumentTypes.
|
||||
@@ -247,33 +256,26 @@ Public Class frmDocumentResultList
|
||||
FirstOrDefault()
|
||||
End If
|
||||
|
||||
Dim oFileInfo = New FileInfo(e.File.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")
|
||||
If oDoctype IsNot Nothing Then
|
||||
Select Case oDoctype.FileChangedAction
|
||||
Case FILE_CHANGED_OVERWRITE
|
||||
Await Watcher_OverwriteFile(e.File)
|
||||
|
||||
' Three possibilities:
|
||||
'
|
||||
' - Yes: Version file
|
||||
' - No: Overwrite file
|
||||
' - Cancel: Abort update
|
||||
Select Case oResult
|
||||
Case DialogResult.Cancel
|
||||
' MsgBox("Abbruch!")
|
||||
Case FILE_CHANGED_VERSION
|
||||
Await Watcher_VersionFile(e.File)
|
||||
|
||||
Case Else
|
||||
Dim oCreateNewFileVersion = IIf(oResult = DialogResult.Yes, True, False)
|
||||
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
|
||||
})
|
||||
Case FILE_CHANGED_QUESTION
|
||||
Await Watcher_Ask(e.File)
|
||||
|
||||
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
|
||||
Case Else
|
||||
Await Watcher_Ask(e.File)
|
||||
|
||||
End Select
|
||||
|
||||
Else
|
||||
Await Watcher_Ask(e.File)
|
||||
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
@@ -286,6 +288,56 @@ Public Class frmDocumentResultList
|
||||
End Try
|
||||
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
|
||||
Dim oSplit As List(Of String) = Environment.Service.Address.Split(":").ToList()
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
|
||||
Namespace IDB
|
||||
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
|
||||
ECM
|
||||
IDB
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
Namespace IDB
|
||||
Public Class FileStore
|
||||
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 Namespace
|
||||
@@ -194,9 +194,11 @@ Public Class Client
|
||||
Try
|
||||
Dim oNewFile As New Modules.IDB.NewFile(LogConfig, Channel)
|
||||
Return Await oNewFile.RunAsync(pFilePath, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -204,9 +206,23 @@ Public Class Client
|
||||
Try
|
||||
Dim oUpdateFile As New Modules.IDB.UpdateFile(LogConfig, Channel)
|
||||
Return Await oUpdateFile.RunAsync(pFilePath, pObjectId, pImportOptions)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
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 Function
|
||||
|
||||
@@ -221,9 +237,11 @@ Public Class Client
|
||||
Try
|
||||
Dim oImportFile As New Modules.Globix.ImportFile(LogConfig, Channel)
|
||||
Return Await oImportFile.RunAsync(pFilePath, pProfileId, pAttributeValues, pObjectStoreName, pObjectKind, pBusinessEntity, pImportOptions)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
@@ -43,6 +43,16 @@
|
||||
Public Property DateImported As Date = Date.Now
|
||||
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
|
||||
Inherits BaseOptions
|
||||
End Class
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<Compile Include="Modules\Globix\ImportFile.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="Modules\IDB\NewFile.vb" />
|
||||
<Compile Include="Modules\IDB\SetObjectState.vb" />
|
||||
<Compile Include="Modules\IDB\UpdateFile.vb" />
|
||||
<Compile Include="Modules\ZooFlow\GetFileObject.vb" />
|
||||
<Compile Include="Connected Services\EDMIServiceReference\Reference.vb">
|
||||
|
||||
34
Modules.EDMIAPI/Modules/IDB/SetObjectState.vb
Normal file
34
Modules.EDMIAPI/Modules/IDB/SetObjectState.vb
Normal 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
|
||||
@@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("EDMIAPI")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("1.4.0.0")>
|
||||
<Assembly: AssemblyTrademark("1.5.0.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.4.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.4.0.0")>
|
||||
<Assembly: AssemblyVersion("1.5.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.5.0.0")>
|
||||
|
||||
@@ -373,14 +373,18 @@ Public Class File
|
||||
Return oIsDirectory
|
||||
End Function
|
||||
|
||||
Public Function GetDateDirectory(pBaseDirectory As String) As String
|
||||
Dim oDateDirectory = GetDateString()
|
||||
Public Function GetDateDirectory(pBaseDirectory As String, pDate As Date) As String
|
||||
Dim oDateDirectory = GetDateString(pDate)
|
||||
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
|
||||
Return oFinalDirectory
|
||||
End Function
|
||||
|
||||
Public Function CreateDateDirectory(pBaseDirectory As String) As String
|
||||
Dim oDateDirectory = GetDateString()
|
||||
Public Function GetDateDirectory(pBaseDirectory As String) As String
|
||||
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)
|
||||
|
||||
If IO.Directory.Exists(oFinalDirectory) = False Then
|
||||
@@ -394,14 +398,26 @@ Public Class File
|
||||
Return oFinalDirectory
|
||||
End Function
|
||||
|
||||
Public Function CreateDateDirectory(pBaseDirectory As String) As String
|
||||
Return CreateDateDirectory(pBaseDirectory, Now)
|
||||
End Function
|
||||
|
||||
Public Function GetDateString() As String
|
||||
Return $"{Now:yyyy\\MM\\dd}"
|
||||
End Function
|
||||
|
||||
Public Function GetDateString(pDate As Date) As String
|
||||
Return $"{pDate:yyyy\\MM\\dd}"
|
||||
End Function
|
||||
|
||||
Public Function GetDateTimeString() As String
|
||||
Return $"{Now:yyyy-MM-dd_hh-mm-ffff}"
|
||||
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)
|
||||
Dim oFileInfo = New IO.FileInfo(pFilePath)
|
||||
Return GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pFilePath), pSuffix, oFileInfo.Extension.Substring(1))
|
||||
|
||||
@@ -12,8 +12,8 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Filesystem")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2021")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("1.3.0.0")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.2.1.0")>
|
||||
<Assembly: AssemblyFileVersion("1.2.1.0")>
|
||||
<Assembly: AssemblyVersion("1.3.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.3.0.0")>
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
Imports DigitalData.Modules.Database.MSSQLServer
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.EDMI.API.Client
|
||||
Imports System.Data.SqlClient
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.ZooFlow.State
|
||||
Imports DigitalData.Modules.Patterns
|
||||
Imports DigitalData.Services.EDMIService.Methods.IDB
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
|
||||
Namespace IDB
|
||||
Public Class Helpers
|
||||
@@ -15,15 +14,17 @@ Namespace IDB
|
||||
|
||||
Private ReadOnly Patterns As Patterns2
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly FileEx As File
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQLServer As MSSQLServer)
|
||||
MyBase.New(pLogConfig)
|
||||
Patterns = New Patterns2(pLogConfig)
|
||||
Database = pMSSQLServer
|
||||
FileEx = New File(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetPlaceholderValue(pValue As String,
|
||||
pFileInfo As FileInfo,
|
||||
pFileInfo As IO.FileInfo,
|
||||
pUserState As UserState,
|
||||
pUserAttributes As Dictionary(Of String, List(Of String)),
|
||||
pAutoAttributes As Dictionary(Of String, List(Of String))) As String
|
||||
@@ -135,6 +136,32 @@ Namespace IDB
|
||||
End Try
|
||||
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
|
||||
Try
|
||||
Dim oGetObjectSQL = $"SELECT * FROM VWIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId}"
|
||||
|
||||
@@ -34,37 +34,17 @@ Namespace Methods.IDB.NewFile
|
||||
|
||||
' 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()
|
||||
Dim oStore = GlobalState.ObjectStores.
|
||||
Where(Function(store) store.Title = pData.StoreName).
|
||||
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 Store base and final path
|
||||
Logger.Debug("Store BasePath is [{0}]", oStore.Path)
|
||||
Dim oFinalPath = Helpers.GetFileObjectPath(oStore, pData.File.FileImportedAt)
|
||||
|
||||
' Get filename
|
||||
Dim oKeepFileName As Boolean = False
|
||||
@@ -182,10 +162,6 @@ Namespace Methods.IDB.NewFile
|
||||
Return $"{IDB_OBJ_ID}.ddfo"
|
||||
End If
|
||||
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 Namespace
|
||||
@@ -20,7 +20,6 @@ Namespace Methods.IDB.UpdateFile
|
||||
End Sub
|
||||
|
||||
Public Function Run(pData As UpdateFileRequest) As UpdateFileResponse
|
||||
|
||||
Try
|
||||
' TODO: Update file object
|
||||
If Helpers.TestObjectIdExists(pData.ObjectId) = False Then
|
||||
@@ -28,8 +27,13 @@ Namespace Methods.IDB.UpdateFile
|
||||
End If
|
||||
|
||||
'TODO: Create a view that collects all information about an idb object
|
||||
Dim oResultObjectId As Long
|
||||
|
||||
If pData.CreateNewVersion = False Then
|
||||
' ----------------------------------------------
|
||||
' -- Replace the existing file-object
|
||||
' ----------------------------------------------
|
||||
|
||||
Dim oGetFileObject As New GetFileObject.GetFileObjectMethod(LogConfig, DatabaseIDB, DatabaseECM, GlobalState)
|
||||
Dim oArgs = New GetFileObject.GetFileObjectRequest With {
|
||||
.ObjectId = pData.ObjectId,
|
||||
@@ -56,178 +60,51 @@ Namespace Methods.IDB.UpdateFile
|
||||
LogAndThrow(ex, $"Could not write file [{oFilePath}] to disk!")
|
||||
End Try
|
||||
|
||||
Return New UpdateFileResponse(pData.ObjectId)
|
||||
oResultObjectId = pData.ObjectId
|
||||
|
||||
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
|
||||
|
||||
' Finally, commit the transaction
|
||||
Transaction?.Commit()
|
||||
|
||||
Return New UpdateFileResponse(oResultObjectId)
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
Private Function TestFileChecksumExists(pChecksum As String) As Long
|
||||
|
||||
Reference in New Issue
Block a user