-aggiunta gestione backup all'uscita programma

- aggiunta gestione stato durante backup e restore
This commit is contained in:
Emmanuele Sassi
2023-08-21 11:38:43 +02:00
parent 638461a4e3
commit 3e84659fca
2 changed files with 78 additions and 8 deletions
@@ -164,6 +164,20 @@ Public Class ConfigurationPageVM
End Set
End Property
Private m_bBackupRunning As Boolean = False
Public ReadOnly Property bBackupRunning As Boolean
Get
Return m_bBackupRunning
End Get
End Property
Private m_bRestoreRunning As Boolean = False
Public ReadOnly Property bRestoreRunning As Boolean
Get
Return m_bRestoreRunning
End Get
End Property
Private m_bExternalBackupActive As Boolean
Public Property bExternalBackupActive As Boolean
Get
@@ -490,6 +504,7 @@ Public Class ConfigurationPageVM
End Sub
Public Sub Backup(bLoadingWindow As Boolean)
m_bBackupRunning = True
' verifico se esiste cartella backup, altrimenti la creo
Dim sBackupFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\Backup"
If Directory.Exists(sBackupFolder) Then
@@ -593,6 +608,7 @@ Public Class ConfigurationPageVM
End If
'chiudo finestra di caricamento
If bLoadingWindow Then LoadingWndHelper.CloseLoadingWnd(ActiveIds.BACKUP)
m_bBackupRunning = False
End Sub
Private Async Sub CopyForExternalBackup(sBackupFile As String, sExternalBackupFolder As String)
@@ -632,6 +648,7 @@ Public Class ConfigurationPageVM
MessageBox.Show("Please verify the machine is stoped and close the supervisor before proceding with the restore operation!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
Return
End If
m_bRestoreRunning = True
' verifico se esiste backup
Dim sBackupFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\Backup"
Dim nYear As Integer = 0
@@ -678,6 +695,7 @@ Public Class ConfigurationPageVM
bDoBackup = False
Case MessageBoxResult.Cancel
MessageBox.Show("Restore operation aborted!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
m_bRestoreRunning = False
Return
End Select
' apro finestra di caricamento
@@ -748,6 +766,7 @@ Public Class ConfigurationPageVM
Directory.Delete(sRestoreDir)
End If
LoadingWndHelper.CloseLoadingWnd(ActiveIds.RESTORE)
m_bRestoreRunning = False
End Sub
#End Region ' Restore
@@ -266,16 +266,67 @@ Public Class MainWindowVM
End If
' verifico se sono in modifica percorso libero
If Map.refFreeContourManagerVM.bIsActive Then
MessageBox.Show("Before closing software exit from path modification!")
MessageBox.Show("Exit from path modification before closing software!")
Return
End If
'If Map.refOptionPanelVM.SelItem = OptionPanelVM.Tabs.SIMUL Then
' Map.refSimulTabVM.ResetSimulation()
'End If
' Imposto contesto principale
'EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
' Gestisco eventuale file corrente modificato
Dim bOk As Boolean = True
' verifico se sto facendo backup
If Map.refConfigurationPageVM.bBackupRunning Then
MessageBox.Show("Backup running! Impossible closing the software until finish the backup process!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
End If
If Map.refConfigurationPageVM.bRestoreRunning Then
MessageBox.Show("Restore running! Impossible closing the software until finish the restore process!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
End If
If Map.refConfigurationPageVM.SelReminder.Id <> 0 Then
Dim sBackupFolder As String = Map.refMainWindowVM.MainWindowM.sDataDir & "\Backup"
Dim nYear As Integer = 0
Dim nMonth As Integer = 0
Dim nDay As Integer = 0
Dim LastBackupDate As Date = Date.MinValue
' verifico se esiste backup
If Directory.Exists(sBackupFolder) Then
' cerco ultimo backup
Dim YearDirList() As String = Directory.GetDirectories(sBackupFolder)
For YearIndex = YearDirList.Length - 1 To 0 Step -1
nYear = 0
Integer.TryParse(Path.GetFileName(YearDirList(YearIndex)), nYear)
Dim sYearDir As String = sBackupFolder & "\" & nYear
Dim MonthDirList() As String = Directory.GetDirectories(sYearDir)
For MonthIndex = MonthDirList.Length - 1 To 0 Step -1
nMonth = 0
Integer.TryParse(Path.GetFileName(MonthDirList(MonthIndex)), nMonth)
Dim sMonthDir As String = sYearDir & "\" & nMonth
Dim DayDirList() As String = Directory.GetDirectories(sMonthDir)
For DayIndex = DayDirList.Length - 1 To 0 Step -1
nDay = 0
Integer.TryParse(Path.GetFileName(DayDirList(DayIndex)), nDay)
Dim sDayDir As String = sMonthDir & "\" & nDay
Dim VersionList() As String = Directory.GetFiles(sDayDir)
If VersionList.Length > 0 Then
Dim nMaxVersion As Int64 = VersionList.Max(Function(x) Int64.Parse(Path.GetFileNameWithoutExtension(x)))
LastBackupDate = New Date(nYear, nMonth, nDay)
Exit For
End If
Next
If LastBackupDate <> Date.MinValue Then Exit For
Next
If LastBackupDate <> Date.MinValue Then Exit For
Next
End If
Dim TimeFromLastBackup As TimeSpan = DateTime.Now - LastBackupDate
If TimeFromLastBackup > TimeSpan.FromDays(Map.refConfigurationPageVM.SelReminder.Id) Then
If MessageBox.Show(Map.refConfigurationPageVM.SelReminder.Name & " have passed from last backup. Do you want to do a backup before closing the software?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.Yes Then
Map.refConfigurationPageVM.Backup(True)
End If
End If
End If
'If Map.refOptionPanelVM.SelItem = OptionPanelVM.Tabs.SIMUL Then
' Map.refSimulTabVM.ResetSimulation()
'End If
' Imposto contesto principale
'EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
' Gestisco eventuale file corrente modificato
Dim bOk As Boolean = True
Select Case Map.refMainMenuVM.SelPage
Case Pages.VIEW
bOk = ProjFileVM.VerifyProjectModification(Map.refProjManagerVM.CurrProj, ProjectType.PROJ)