aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Security/RefreshTokenEncoder.cs
blob: 896788ffc0ce91bc30641891a5273e9a9475b017 (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
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
    {
        private DispatcherTimer _timer;

        /// <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(); }
        }


        /// <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;

            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick += _timer_Tick;

            RemainingSeconds = autoReconnectTimeout;
            _timer.Start();
        }

        /// <summary>
        /// Invokes the <see cref="E:Tango.SharedUI.DialogViewVM.Accepted" /> event.
        /// </summary>
        protected override void Accept()
        {
            _timer.Stop();
            base.Accept();
        }

        /// <summary>
        /// Invokes the <see cref="E:Tango.SharedUI.DialogViewVM.Canceled" /> event.
        /// </summary>
        protected override void Cancel()
        {
            _timer.Stop();
            base.Cancel();
        }

        private void _timer_Tick(object sender, EventArgs e)
        {
            RemainingSeconds--;

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

    }
}