aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
blob: 5e584f89104c950590999f4747f8791f4020a34f (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
generated by cgit v1.3.1 (git 2.54.0) at 2026-07-27 00:37:05 +0000
 


nnectivityProvider ConnectivityProvider { get; set; }

        /// <summary>
        /// Gets or sets the hot spot provider.
        /// </summary>
        [TangoInject]
        public IHotSpotProvider HotSpotProvider { get; set; }

        /// <summary>
        /// Gets or sets the remote assistance provider.
        /// </summary>
        [TangoInject]
        public IRemoteAssistanceProvider RemoteAssistanceProvider { get; set; }

        /// <summary>
        /// Gets or sets the storage provider.
        /// </summary>
        [TangoInject]
        public IStorageProvider StorageProvider { get; set; }

        /// <summary>
        /// Gets or sets the event logger.
        /// </summary>
        [TangoInject]
        public IEventLogger EventLogger { get; set; }

        private PPCSettings _settings;
        /// <summary>
        /// Gets the main PPC settings.
        /// </summary>
        public PPCSettings Settings
        {
            get
            {
                if (_settings == null)
                {
                    _settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
                }

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

        private bool _isVisible;
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="PPCViewModel"/> view is visible.
        /// </summary>
        public bool IsVisible
        {
            get { return _isVisible; }
            private set { _isVisible = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Called when the application has been started.
        /// </summary>
        public abstract void OnApplicationStarted();

        /// <summary>
        /// Called when the application is shutting down.
        /// </summary>
        public virtual void OnApplicationShuttingDown()
        {

        }

        /// <summary>
        /// Called when the navigation system has navigated to this VM view.
        /// </summary>
        public virtual void OnNavigatedTo()
        {
            IsVisible = true;
        }

        /// <summary>
        /// Called when the navigation system has navigated from this VM view.
        /// </summary>
        public virtual void OnNavigatedFrom()
        {
            IsVisible = false;
        }

        /// <summary>
        /// Raises the specified message using the default <see cref="TangoMessenger"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="message">The message.</param>
        protected void RaiseMessage<T>(T message) where T : class
        {
            TangoMessenger.Default.Send<T>(message);
        }

        /// <summary>
        /// Raises the specified message using the default <see cref="TangoMessenger"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        protected void RaiseMessage<T>() where T : class
        {
            TangoMessenger.Default.Send<T>(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Registers a message handle for the specified message type T.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="handler">The handler.</param>
        protected void RegisterForMessage<T>(Action<T> handler)
        {
            TangoMessenger.Default.Register<T>(handler);
        }

        /// <summary>
        /// Called before the navigation system navigates from this object.
        /// Return false to abort the navigation.
        /// </summary>
        /// <returns></returns>
        public virtual Task<bool> OnNavigateOutRequest()
        {
            return Task.FromResult(true);
        }

        /// <summary>
        /// Called before the navigation system navigates back from this object.
        /// Return false to abort the navigation.
        /// </summary>
        /// <returns></returns>
        public virtual Task<bool> OnNavigateBackRequest()
        {
            return Task.FromResult(true);
        }

        /// <summary>
        /// Called when the application is ready and all modules views are loaded.
        /// </summary>
        public virtual void OnApplicationReady()
        {
            
        }
    }

    /// <summary>
    /// Represents a PPC view model base class a View property as an instance of a <see cref="IPPCView"/> contract.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <seealso cref="Tango.SharedUI.ViewModel" />
    public abstract class PPCViewModel<T> : PPCViewModel where T : IPPCView
    {
        private T _view;
        /// <summary>
        /// Gets the IPPCView instance.
        /// </summary>
        [TangoInject(TangoInjectMode.WhenAvailable)]
        public T View
        {
            get { return _view; }
            set
            {
                _view = value;
                ViewAttached = true;
                OnViewAttached();
            }
        }


        /// <summary>
        /// Gets a value indicating whether the instance of IPPCView is available.
        /// </summary>
        public bool ViewAttached { get; private set; }

        /// <summary>
        /// Called when the application has been started.
        /// </summary>
        public override void OnApplicationStarted()
        {

        }

        /// <summary>
        /// Called when the instance of IPPCView is available.
        /// </summary>
        public virtual void OnViewAttached()
        {

        }
    }
}