aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Dialogs/PowerUpViewVM.cs
blob: ec4b3bb2b4de309f00a981ccb9712ad63f8778de (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-co
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Tango.BL.Entities;
using Tango.PPC.Common;
using Tango.Settings;
using Tango.SharedUI;

namespace Tango.PPC.UI.Dialogs
{
    public class PowerUpViewVM : DialogViewVM
    {
        private Timer _timer;

        private List<Rml> _rmls;
        public List<Rml> Rmls
        {
            get { return _rmls; }
            set { _rmls = value; RaisePropertyChangedAuto(); }
        }

        private Rml _selectedRml;
        public Rml SelectedRml
        {
            get { return _selectedRml; }
            set { _selectedRml = value; RaisePropertyChangedAuto(); }
        }

        private bool _isSelectedRml;
        public bool IsSelectedRml
        {
            get { return _isSelectedRml; }
            set
            {
                _isSelectedRml = value;
                RaisePropertyChangedAuto();

                if (_isSelectedRml)
                {
                    IsMinimalTemperature = false;
                }
            }
        }

        private bool _isMinimalTemperature;
        public bool IsMinimalTemperature
        {
            get { return _isMinimalTemperature; }
            set
            {
                _isMinimalTemperature = value;
                RaisePropertyChangedAuto();

                if (_isMinimalTemperature)
                {
                    IsSelectedRml = false;
                }
            }
        }

        private int _remainingSeconds;
        public int RemainingSeconds
        {
            get { return _remainingSeconds; }
            set { _remainingSeconds = value; RaisePropertyChangedAuto(); }
        }

        private bool _isTimeoutEnabled;
        public bool IsTimeoutEnabled
        {
            get { return _isTimeoutEnabled; }
            set
            {
                _isTimeoutEnabled = value; RaisePropertyChangedAuto();

                if (!_isTimeoutEnabled)
                {
                    _timer.Stop();
                }
            }
        }

        public PowerUpViewVM()
        {
            RemainingSeconds = (int)SettingsManager.Default.GetOrCreate<PPCSettings>().PowerUpScreenTimeout.TotalSeconds;
            CanClose = true;
            IsMinimalTemperature = true;
            IsTimeoutEnabled = true;
            _timer = new Timer();
            _timer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds;
            _timer.Elapsed += _timer_Elapsed;
        }

        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            RemainingSeconds--;

            if (RemainingSeconds == 0)
            {
                InvokeUI(() =>
                {
                    Accept();
                });
            }
        }

        protected override void Cancel()
        {
            _timer.Stop();
            base.Cancel();
        }

        protected override void Accept()
        {
            _timer.Stop();
            base.Accept();
        }

        public override void OnShow()
        {
            base.OnShow();
            _timer.Start();
        }
    }
}