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. --- .../Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs | 91 ++++++++++++++++++++++ .../PPC/Tango.PPC.UI/ViewModels/LayoutViewVM.cs | 11 +++ 2 files changed, 102 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels') 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 -- cgit v1.3.1