From ca29510e1e336c4d68aaa926cfea6eb72ce42779 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 26 Nov 2019 17:33:02 +0200 Subject: Working on backup/restore... --- .../ViewModels/BackupViewVM.cs | 6 +- .../ViewModels/RestoreViewVM.cs | 113 ++++++++++++++++++++- 2 files changed, 115 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs index dd561c5be..ab8d0248f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/BackupViewVM.cs @@ -71,14 +71,14 @@ namespace Tango.PPC.BackupRestore.ViewModels public String BackupLocation { get { return _backupLocation; } - set { _backupLocation = value; RaisePropertyChangedAuto(); } + set { _backupLocation = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } private String _backupName; public String BackupName { get { return _backupName; } - set { _backupName = value; RaisePropertyChangedAuto(); } + set { _backupName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } public RelayCommand BackupCommand { get; set; } @@ -88,7 +88,7 @@ namespace Tango.PPC.BackupRestore.ViewModels public BackupViewVM() { BrowseBackupLocationCommand = new RelayCommand(BrowseBackupLocation); - BackupCommand = new RelayCommand(StartBackup); + BackupCommand = new RelayCommand(StartBackup, () => !String.IsNullOrWhiteSpace(BackupName) && BackupLocation != null); IsBackupJobs = true; } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/RestoreViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/RestoreViewVM.cs index 904fd9e52..ec6083436 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/RestoreViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/ViewModels/RestoreViewVM.cs @@ -3,15 +3,126 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Core.DI; +using Tango.Explorer; +using Tango.PPC.BackupRestore.Views; using Tango.PPC.Common; +using Tango.PPC.Common.BackupRestore; +using Tango.PPC.Storage; namespace Tango.PPC.BackupRestore.ViewModels { public class RestoreViewVM : PPCViewModel { + private string _backupFileLocation; + + [TangoInject] + public IBackupManager BackupManager { get; set; } + + private String _backupFileName; + public String BackupFileName + { + get { return _backupFileName; } + set { _backupFileName = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + private RestoreSettings _restoreSettings; + public RestoreSettings RestoreSettings + { + get { return _restoreSettings; } + set { _restoreSettings = value; RaisePropertyChangedAuto(); } + } + + private BackupFile _backupFile; + public BackupFile BackupFile + { + get { return _backupFile; } + set { _backupFile = value; RaisePropertyChangedAuto(); } + } + + private BackupRestoreProgressEventArgs _currentRestoreProgress; + public BackupRestoreProgressEventArgs CurrentRestoreProgress + { + get { return _currentRestoreProgress; } + set { _currentRestoreProgress = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand BrowseForBackupCommand { get; set; } + + public RelayCommand RestoreCommand { get; set; } + + public RestoreViewVM() + { + RestoreSettings = new RestoreSettings(); + RestoreCommand = new RelayCommand(StartRestore, () => BackupFileName != null); + BrowseForBackupCommand = new RelayCommand(BrowseForBackup); + } + + private async void StartRestore() + { + await NavigationManager.NavigateTo(nameof(RestoreProgressView)); + + if (IsFree) + { + IsFree = false; + var result = await BackupManager.Restore(_backupFileLocation, RestoreSettings); + IsFree = true; + } + } + + private async void BrowseForBackup() + { + var result = await NavigationManager. + NavigateForResult( + new Storage.Models.StorageNavigationRequest() + { + Intent = Storage.Models.StorageNavigationIntent.LoadFile, + Filter = ExplorerFileDefinition.Backup.Extension, + Title = "Select Backup File", + }); + + if (result != null) + { + _backupFileLocation = result.Path; + + try + { + BackupFile = await BackupManager.ExtractBackupConfiguration(_backupFileLocation); + BackupFileName = System.IO.Path.GetFileName(result.Path); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error extracting backup configuration from file '{_backupFileLocation}'."); + await NotificationProvider.ShowError($"Error occurred while trying to extract the backup file information\n{ex.FlattenMessage()}"); + } + } + } + + public override void OnNavigatedFrom() + { + base.OnNavigatedFrom(); + BackupFileName = null; + BackupFile = null; + _backupFileLocation = null; + } + + public override void OnApplicationReady() + { + base.OnApplicationReady(); + BackupManager.Progress += BackupManager_Progress; + } + + private void BackupManager_Progress(object sender, BackupRestoreProgressEventArgs e) + { + CurrentRestoreProgress = e; + } + public override void OnApplicationStarted() { - + } } } -- cgit v1.3.1