aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.UI/Dialogs/MachineWaitForConnectionViewVM.cs
blob: 5556e27dcfcb1258f4321cd8c7a453b96f6cddee (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using Tango.FSE.Common;
using Tango.Integration.ExternalBridge;

namespace Tango.FSE.UI.Dialogs
{
    /// <summary>
    /// Represents a machine controlled disconnection dialog with a timeout for reconnection.
    /// </summary>
    /// <seealso cref="Tango.FSE.Common.FSEDialogViewVM" />
    public class MachineWaitForConnectionViewVM : FSEDialogViewVM
    {
        public event EventHandler RequestCancel;

        /// <summary>
        /// Gets or sets the connected machine.
        /// </summary>
        public IExternalBridgeClient Machine { get; set; }

        private int _remainingSeconds;
        /// <summary>
        /// Gets or sets the remaining seconds.
        /// </summary>
        public int RemainingSeconds
        {
            get { return _remainingSeconds; }
            set { _remainingSeconds = value; RaisePropertyChangedAuto(); }
        }

        private String _message;
        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        public String Message
        {
            get { return _message; }
            set { _message = value; RaisePropertyChangedAuto(); }
        }

        private bool _blockCancel;
        /// <summary>
        /// Blocks the cancellation of the dialog until the reconnection procedure completes.
        /// </summary>
        public bool BlockCancel
        {
            get { return _blockCancel; }
            set { _blockCancel = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); }
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="MachineWaitForConnectionViewVM"/> class.
        /// </summary>
        /// <param name="machine">The machine.</param>
        /// <param name="autoReconnectTimeout">The automatic reconnect timeout in seconds.</param>
        public MachineWaitForConnectionViewVM(IExternalBridgeClient machine, int autoReconnectTimeout, String message = null)
        {
            Message = message;

            if (Message == null)
            {
                Message = "The connection with the machine had been lost due to a controlled disconnection.";
            }

            AutoMode = true;
            OKText = "CANCEL";
            CanClose = false;
            HasDefault = false;

            Machine = machine;

            RemainingSeconds = autoReconnectTimeout;
        }

        protected override bool CanOK()
        {
            return base.CanOK() && !BlockCancel;
        }

        protected override void Accept()
        {
            RequestCancel?.Invoke(this, new EventArgs());
        }
    }
}