From fcf154eb2ae88dcf1003ea6bd14c91cab1a616e9 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 24 Nov 2019 17:31:30 +0200 Subject: Backup Manager. --- .../BackupRestore/DefaultBackupManager.cs | 31 ++++- .../PPC/Tango.PPC.UI/Images/Menu/backup.png | Bin 0 -> 1834 bytes .../PPC/Tango.PPC.UI/Images/backup-big.png | Bin 0 -> 3044 bytes .../PPC/Tango.PPC.UI/Images/backup-restore.png | Bin 0 -> 89496 bytes .../PPC/Tango.PPC.UI/Images/restore.png | Bin 0 -> 3252 bytes .../Navigation/DefaultNavigationManager.cs | 56 ++++++--- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 16 ++- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 16 ++- .../Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs | 91 +++++++++++++++ .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 11 ++ .../PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml | 128 +++++++++++++++++++++ .../Tango.PPC.UI/Views/BackupRestoreView.xaml.cs | 47 ++++++++ .../PPC/Tango.PPC.UI/Views/LayoutView.xaml | 9 ++ .../PPC/Tango.PPC.UI/Views/MainView.xaml | 1 + .../ViewsContracts/IBackupRestoreView.cs | 19 +++ 15 files changed, 408 insertions(+), 17 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/Menu/backup.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-big.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-restore.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Images/restore.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IBackupRestoreView.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs index dace90b5c..1eeb848ed 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/BackupRestore/DefaultBackupManager.cs @@ -3,10 +3,39 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.PPC.Common.Application; +using Tango.PPC.Common.BackupRestore; namespace Tango.PPC.UI.BackupRestore { - class DefaultBackupManager + public class DefaultBackupManager : IBackupManager { + public event EventHandler Progress; + + public DefaultBackupManager(IPPCApplicationManager applicationManager) + { + + } + + public Task CreateBackup(string filePath, BackupSettings settings) + { + throw new NotImplementedException(); + } + + public Task Restore(string filePath) + { + throw new NotImplementedException(); + } + + protected virtual void OnProgress(BackupRestoreStage stage, double progress = 0, double maxProgress = 100, bool isIntermediate = true) + { + Progress?.Invoke(this, new BackupRestoreEventArgs() + { + Stage = stage, + Progress = progress, + MaxProgress = maxProgress, + IsIntermediate = isIntermediate, + }); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/Menu/backup.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/Menu/backup.png new file mode 100644 index 000000000..158bab095 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/Menu/backup.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-big.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-big.png new file mode 100644 index 000000000..3a712af49 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-big.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-restore.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-restore.png new file mode 100644 index 000000000..15be3b163 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/backup-restore.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/restore.png b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/restore.png new file mode 100644 index 000000000..e60aaf425 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.UI/Images/restore.png differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs index a0338912f..77b09f638 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Navigation/DefaultNavigationManager.cs @@ -113,7 +113,27 @@ namespace Tango.PPC.UI.Navigation { LogManager.Log($"Navigating to: {view.ToString()}..."); - MainView.Instance.NavigationControl.NavigateTo(view.ToString()); + + var fromView = MainView.Instance.NavigationControl.SelectedElement; + FrameworkElement toView = null; + + toView = MainView.Instance.NavigationControl.NavigateTo(view.ToString(),() => + { + var fromVM = toView.DataContext as PPCViewModel; + + if (fromVM != null) + { + fromVM.OnNavigatedFrom(); + } + + var toVM = toView.DataContext as PPCViewModel; + + if (toVM != null) + { + toVM.OnNavigatedTo(); + } + }); + return Task.FromResult(true); } } @@ -398,24 +418,34 @@ namespace Tango.PPC.UI.Navigation _navigating_back = true; - String first = _navigationHistory.Pop(); - _preventHistory = true; - - - if (await NavigateTo(first)) + if (_navigationHistory.Count > 0) { - RaisePropertyChanged(nameof(CanNavigateBack)); - _preventHistory = false; - _navigating_back = false; - return true; + String first = _navigationHistory.Pop(); + _preventHistory = true; + + if (await NavigateTo(first)) + { + RaisePropertyChanged(nameof(CanNavigateBack)); + _preventHistory = false; + _navigating_back = false; + return true; + } + else + { + _navigationHistory.Push(first); + _preventHistory = false; + _navigating_back = false; + RaisePropertyChanged(nameof(CanNavigateBack)); + return false; + } } else { - _navigationHistory.Push(first); + await NavigateTo(NavigationView.HomeModule); + RaisePropertyChanged(nameof(CanNavigateBack)); _preventHistory = false; _navigating_back = false; - RaisePropertyChanged(nameof(CanNavigateBack)); - return false; + return true; } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index b279f1a92..fd068bd61 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -115,6 +115,7 @@ GlobalVersionInfo.cs + WiFiAuthenticationView.xaml @@ -154,6 +155,7 @@ + @@ -165,9 +167,13 @@ + + + BackupRestoreView.xaml + ExternalBridgeView.xaml @@ -253,6 +259,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -349,6 +359,10 @@ + + + + @@ -593,7 +607,7 @@ if $(ConfigurationName) == Release del *.xml - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 67b5dc19b..9fc482389 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -5,6 +5,7 @@ using Tango.Integration.ExternalBridge; using Tango.Logging; using Tango.PPC.Common.Application; using Tango.PPC.Common.Authentication; +using Tango.PPC.Common.BackupRestore; using Tango.PPC.Common.Connection; using Tango.PPC.Common.Connectivity; using Tango.PPC.Common.Diagnostics; @@ -24,6 +25,7 @@ using Tango.PPC.Common.Threading; using Tango.PPC.Common.UWF; using Tango.PPC.Common.Web; using Tango.PPC.UI.Authentication; +using Tango.PPC.UI.BackupRestore; using Tango.PPC.UI.Connectivity; using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; @@ -71,6 +73,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); TangoIOC.Default.Register(new PPCWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -93,8 +96,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); - - //TangoIOC.Default.Register(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); @@ -107,6 +109,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.GetInstance().ContentRendered += (_, __) => @@ -114,6 +117,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(LayoutView.Instance); TangoIOC.Default.Register(MachineSetupView.Instance); TangoIOC.Default.Register(MachineUpdateView.Instance); + TangoIOC.Default.Register(BackupRestoreView.Instance); }; //TangoIOC.Default.Register(); @@ -212,5 +216,13 @@ namespace Tango.PPC.UI return TangoIOC.Default.GetInstance(); } } + + public static BackupRestoreViewVM BackupRestoreViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } } } \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs new file mode 100644 index 000000000..416ece24b --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.Core.DI; +using Tango.PPC.Common; +using Tango.PPC.Common.BackupRestore; +using Tango.PPC.UI.ViewsContracts; + +namespace Tango.PPC.UI.ViewModels +{ + public class BackupRestoreViewVM : PPCViewModel + { + private Stack _navigation_history; + private BackupRestoreView _currentView; + private bool _canNavigateBack; + + public enum BackupRestoreView + { + MainView, + BackupView, + RestoreView + } + + [TangoInject] + public IBackupManager BackupManager { get; set; } + + public RelayCommand NavigateCommand { get; set; } + + public RelayCommand NavigateBackCommand { get; set; } + + public BackupRestoreViewVM() + { + NavigateCommand = new RelayCommand(HandleNavigateCommand); + NavigateBackCommand = new RelayCommand(NavigateBack, () => _canNavigateBack); + + _navigation_history = new Stack(); + _canNavigateBack = true; + } + + public override void OnNavigatedTo() + { + base.OnNavigatedTo(); + + _navigation_history = new Stack(); + _currentView = BackupRestoreView.MainView; + } + + private void HandleNavigateCommand(string view) + { + var v = (BackupRestoreView)Enum.Parse(typeof(BackupRestoreView), view); + NavigateTo(v); + } + + private Task NavigateTo(BackupRestoreView view, bool pushHistory = true) + { + if (pushHistory) + { + _navigation_history.Push(_currentView); + } + + _currentView = view; + return View.NavigateTo(view); + } + + private async void NavigateBack() + { + _canNavigateBack = false; + InvalidateRelayCommands(); + + if (_navigation_history.Count > 0) + { + await NavigateTo(_navigation_history.Pop(), false); + } + else + { + await NavigationManager.NavigateBack(); + } + + _canNavigateBack = true; + InvalidateRelayCommands(); + } + + public override void OnApplicationStarted() + { + + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs index 9e8a9fe34..0b530c278 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs @@ -111,6 +111,11 @@ namespace Tango.PPC.UI.ViewModels /// public RelayCommand UpdateCommand { get; set; } + /// + /// Gets or sets the backup restore command. + /// + public RelayCommand BackupRestoreCommand { get; set; } + /// /// Gets or sets the power command. /// @@ -146,6 +151,12 @@ namespace Tango.PPC.UI.ViewModels PowerCommand = new RelayCommand(() => IsPowerOpened = true); RestartApplicationCommand = new RelayCommand(RestartApplication); + + BackupRestoreCommand = new RelayCommand(() => + { + NavigationManager.NavigateTo(NavigationView.BackupRestoreView); + IsMenuOpened = false; + }); } #endregion diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml new file mode 100644 index 000000000..ad8a5ca18 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + Back + + + + + + + + + + Welcome to the backup/restore wizard + + + 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'. + + + + + + + + + Backup + + Create a complete backup of your system state and save it to a storage device. + + + + + + + + + + Restore + + Restore your system from a previously saved backup file. + + + + + + + + + + + Backup 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'. + + + + + + + + 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'. + + + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml.cs new file mode 100644 index 000000000..824bad9f0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/BackupRestoreView.xaml.cs @@ -0,0 +1,47 @@ +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; +using Tango.PPC.Common; +using Tango.PPC.UI.ViewModels; +using Tango.PPC.UI.ViewsContracts; + +namespace Tango.PPC.UI.Views +{ + /// + /// Interaction logic for BackupRestoreView.xaml + /// + public partial class BackupRestoreView : UserControl, IBackupRestoreView + { + public static BackupRestoreView Instance { get; internal set; } + + public BackupRestoreView() + { + InitializeComponent(); + + Instance = this; + } + + public Task NavigateTo(BackupRestoreViewVM.BackupRestoreView view) + { + TaskCompletionSource source = new TaskCompletionSource(); + + navigationControl.NavigateTo(view.ToString(), () => + { + source.SetResult(new object()); + }); + + return source.Task; + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml index 39c087c52..fa6b8de7e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml @@ -100,6 +100,15 @@ + + + + + + Backup/Restore + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml index 6d6d57526..2119aebe7 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MainView.xaml @@ -89,6 +89,7 @@ + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IBackupRestoreView.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IBackupRestoreView.cs new file mode 100644 index 000000000..ef5f43eda --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewsContracts/IBackupRestoreView.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PPC.Common; +using static Tango.PPC.UI.ViewModels.BackupRestoreViewVM; + +namespace Tango.PPC.UI.ViewsContracts +{ + public interface IBackupRestoreView : IPPCView + { + /// + /// Navigates to the specified backup/restore view. + /// + /// The view. + Task NavigateTo(BackupRestoreView view); + } +} -- cgit v1.3.1