Common/DocumentResultList: Handle file open, Update file with respect to Doctype options
This commit is contained in:
parent
67852d4572
commit
9f4734f50f
@ -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
|
||||||
|
|||||||
@ -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,33 +256,26 @@ 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
|
|
||||||
' - Cancel: Abort update
|
|
||||||
Select Case oResult
|
|
||||||
Case DialogResult.Cancel
|
|
||||||
' MsgBox("Abbruch!")
|
|
||||||
|
|
||||||
Case Else
|
Case FILE_CHANGED_QUESTION
|
||||||
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
|
Case Else
|
||||||
MsgBox($"Beim Speichern der Datei '{oFileInfo.Name}' Fehler ist ein Fehler aufgetreten!", MsgBoxStyle.Critical, Text)
|
Await Watcher_Ask(e.File)
|
||||||
Else
|
|
||||||
MsgBox($"Die Datei '{oFileInfo.Name}' wurde erfolgreich gespeichert!", MsgBoxStyle.Information, Text)
|
End Select
|
||||||
End If
|
|
||||||
End Select
|
Else
|
||||||
|
Await Watcher_Ask(e.File)
|
||||||
|
|
||||||
|
End If
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(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()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user