aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
blob: ffe5c9a4fc2458b3f7fc10192b0b07246f43ef49 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.Core.DI;
using Tango.PPC.Common.Application;
using Tango.PPC.Common.Authentication;
using Tango.PPC.Common.Navigation;
using Tango.PPC.Common.Notifications;
using Tango.Settings;
using Tango.SharedUI;

namespace Tango.PPC.Common
{
    public abstract class PPCViewModel : ViewModel
    {
        public ObservablesEntitiesAdapter Adapter
        {
            get { return ObservablesEntitiesAdapter.Instance; }
        }

        [TangoInject]
        public IPPCApplicationManager ApplicationManager { get; set; }

        [TangoInject]
        public IAuthenticationProvider AuthenticationProvider { get; set; }

        [TangoInject]
        public INavigationManager NavigationManager { get; set; }

        [TangoInject]
        public INotificationProvider NotificationProvider { get; set; }

        private PPCSettings _settings;
        public PPCSettings Settings
        {
            get
            {
                if (_settings == null)
                {
                    _settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
                }

                return _settings;
            }
            private set { _settings = value; }
        }

        public PPCViewModel()
        {

        }

        public abstract void OnApplicationStarted();

        public virtual void OnApplicationShuttingDown()
        {

        }
    }

    public abstract class PPCViewModel<T> : PPCViewModel where T : IPPCView
    {
        public T View { get; private set; }

        public bool ViewAttached { get; private set; }

        public override void OnApplicationStarted()
        {
            TangoIOC.Default.GetInstanceWhenAvailable<T>((view) =>
            {
                ViewAttached = true;
                View = view;
                OnViewAttached();
            });
        }

        public abstract void OnViewAttached();
    }
}