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 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs') 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() + { + + } + } +} -- cgit v1.3.1