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... --- .../Tango.PPC.BackupRestore.csproj | 7 + .../ViewModels/BackupViewVM.cs | 6 +- .../ViewModels/RestoreViewVM.cs | 113 +++++++++++++- .../Tango.PPC.BackupRestore/Views/BackupView.xaml | 2 +- .../Tango.PPC.BackupRestore/Views/MainView.xaml | 1 + .../Views/RestoreProgressView.xaml | 38 +++++ .../Views/RestoreProgressView.xaml.cs | 28 ++++ .../Tango.PPC.BackupRestore/Views/RestoreView.xaml | 166 +++++++++++++++++++-- .../Tango.PPC.Storage/ViewModels/MainViewVM.cs | 14 +- .../Modules/Tango.PPC.Storage/Views/MainView.xaml | 4 +- 10 files changed, 357 insertions(+), 22 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml.cs (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Tango.PPC.BackupRestore.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Tango.PPC.BackupRestore.csproj index d32415e17..5e538ec89 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Tango.PPC.BackupRestore.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Tango.PPC.BackupRestore.csproj @@ -69,6 +69,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -113,6 +117,9 @@ + + RestoreProgressView.xaml + BackupProgressView.xaml 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() { - + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/BackupView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/BackupView.xaml index 68c022766..52dd87d92 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/BackupView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/BackupView.xaml @@ -34,7 +34,7 @@ Backup your system - Select whether you would like to backup your jobs or the entire system and press 'Start Backup'. + Please specify the location and settings of your backup and press 'START'. diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/MainView.xaml index 0f7667c4e..d9c4c06a3 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/MainView.xaml @@ -25,6 +25,7 @@ + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml new file mode 100644 index 000000000..f83bb0bd5 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml @@ -0,0 +1,38 @@ + + + + + + + + Restoring your system + + + This process may take several minutes, please wait. + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml.cs new file mode 100644 index 000000000..3b8b19fa9 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreProgressView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.BackupRestore.Views +{ + /// + /// Interaction logic for BackupView.xaml + /// + public partial class RestoreProgressView : UserControl + { + public RestoreProgressView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreView.xaml index ef7dcbb58..0f91f8ae6 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.BackupRestore/Views/RestoreView.xaml @@ -9,22 +9,160 @@ xmlns:global="clr-namespace:Tango.PPC.BackupRestore" xmlns:local="clr-namespace:Tango.PPC.BackupRestore.Views" mc:Ignorable="d" - d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:RestoreViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.RestoreViewVM}"> - - - - + d:DesignHeight="700" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:RestoreViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.RestoreViewVM}"> + + + + + + + + + + + + + + Restore your system - This wizard allows you to create a complete backup of your current machine state including software, firmware, data and user settings. - - - - For creating a complete backup of your system please press 'Backup'. - - In case you want to restore your system to a previous state, please press 'Restore'. - - + Please specify the location of your backup file and other options. Press 'START' when you are ready. + + + + + + Location + + + + + Please insert a storage device and select your backup file + + BROWSE + + + + + + + + + + Information + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Options + + + + + + + + + + + + Overwrite existing jobs + (existing jobs will not change) + + + + + + + Do not remove existing jobs + (existing jobs will not be deleted) + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs index 4a756e7ea..507110942 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/ViewModels/MainViewVM.cs @@ -63,6 +63,14 @@ namespace Tango.PPC.Storage.ViewModels } } + private bool _displayItems; + public bool DisplayItems + { + get { return _displayItems; } + set { _displayItems = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand FileSelectedCommand { get; set; } public RelayCommand SaveCommand { get; set; } @@ -104,6 +112,8 @@ namespace Tango.PPC.Storage.ViewModels { View.EditFileName(); } + + DisplayItems = true; } else { @@ -116,6 +126,8 @@ namespace Tango.PPC.Storage.ViewModels public override void OnNavigatedFrom() { base.OnNavigatedFrom(); + DisplayItems = false; + Request = null; Request = new StorageNavigationRequest(); } @@ -158,7 +170,6 @@ namespace Tango.PPC.Storage.ViewModels { if (_allow_exit || CurrentPath == StorageProvider.Drive.RootDirectory.FullName) { - Request = null; return Task.FromResult(true); } else @@ -170,6 +181,7 @@ namespace Tango.PPC.Storage.ViewModels private async void OnFileSelected(ExplorerFileItem fileItem) { + _selectedItem = fileItem; _allow_exit = true; await NavigationManager.NavigateBack(); StorageProvider.SubmitFileSelection(fileItem); diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml index 74307c9ce..25538a525 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Storage/Views/MainView.xaml @@ -38,7 +38,7 @@ - + SAVE @@ -49,7 +49,7 @@ - +