From 66599efcbfec16f794fc7f78c02181b2047d0bc1 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 3 Feb 2022 13:34:24 +0100 Subject: [PATCH] Common: First working version of watcher with confirmation --- GUIs.Common/DocumentResultList/Watcher.vb | 3 +- GUIs.Common/frmDocumentResultList.vb | 34 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/GUIs.Common/DocumentResultList/Watcher.vb b/GUIs.Common/DocumentResultList/Watcher.vb index 834ba40d..12be8da1 100644 --- a/GUIs.Common/DocumentResultList/Watcher.vb +++ b/GUIs.Common/DocumentResultList/Watcher.vb @@ -15,6 +15,7 @@ Namespace DocumentResultList ' TODO: Hashes for checking if the opened file was modified externally Private HashOriginalFile As String = Nothing Private HashOpenedFile As String = Nothing + Private Const FILE_OPEN_HANDLE_INTERVAL = 2000 ''' ''' List of opened files containing the filepath that was opened and the document id @@ -74,7 +75,7 @@ Namespace DocumentResultList If FileOpenTimer.Enabled = False Then - FileOpenTimer.Interval = 10000 + FileOpenTimer.Interval = FILE_OPEN_HANDLE_INTERVAL FileOpenTimer.Start() End If diff --git a/GUIs.Common/frmDocumentResultList.vb b/GUIs.Common/frmDocumentResultList.vb index 06ba148b..6f1c5de7 100644 --- a/GUIs.Common/frmDocumentResultList.vb +++ b/GUIs.Common/frmDocumentResultList.vb @@ -237,20 +237,42 @@ Public Class frmDocumentResultList Public Async Sub Watcher_FileChanged(sender As Object, e As DocumentResultList.Watcher.FileChangedArgs) Handles Watcher.FileChanged Try - Await _IDBClient.UpdateFileAsync(e.File.Document.Id, e.File.FilePath, New Options.UpdateFileOptions With { - .CreateNewFileVersion = False, - .Language = Environment.User.Language, - .Username = Environment.User.UserName - }) - + 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") + + ' Three possibilities: + ' + ' - Yes: Version file + ' - No: Overwrite file + ' - Cancel: Abort update + Select Case oResult + Case DialogResult.Cancel + MsgBox("Abbruch!") + 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 + }) + + 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 Catch ex As Exception Logger.Error(ex) Show_CriticalError(ex) + Finally ' Signal to the watcher that the file is no longer in use Watcher.FileSaved(e.File) + End Try End Sub