aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/BackupRestoreViewVM.cs
blob: 416ece24b79f48b4eb64482208f667773ac9079f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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<IBackupRestoreView>
    {
        private Stack<BackupRestoreView> _navigation_history;
        private BackupRestoreView _currentView;
        private bool _canNavigateBack;

        public enum BackupRestoreView
        {
            MainView,
            BackupView,
            RestoreView
        }

        [TangoInject]
        public IBackupManager BackupManager { get; set; }

        public RelayCommand<String> NavigateCommand { get; set; }

        public RelayCommand NavigateBackCommand { get; set; }

        public BackupRestoreViewVM()
        {
            NavigateCommand = new RelayCommand<string>(HandleNavigateCommand);
            NavigateBackCommand = new RelayCommand(NavigateBack, () => _canNavigateBack);

            _navigation_history = new Stack<BackupRestoreView>();
            _canNavigateBack = true;
        }

        public override void OnNavigatedTo()
        {
            base.OnNavigatedTo();

            _navigation_history = new Stack<BackupRestoreView>();
            _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()
        {

        }
    }
}