Common: First working version of watcher with confirmation

This commit is contained in:
Jonathan Jenne 2022-02-03 13:34:24 +01:00
parent dbe755bc94
commit 66599efcbf
2 changed files with 29 additions and 6 deletions

View File

@ -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
''' <summary>
''' 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

View File

@ -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