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 { /// /// Represents a machine controlled disconnection dialog with a timeout for reconnection. /// /// public class MachineWaitForConnectionViewVM : FSEDialogViewVM { public event EventHandler RequestCancel; /// /// Gets or sets the connected machine. /// public IExternalBridgeClient Machine { get; set; } private int _remainingSeconds; /// /// Gets or sets the remaining seconds. /// public int RemainingSeconds { get { return _remainingSeconds; } set { _remainingSeconds = value; RaisePropertyChangedAuto(); } } private String _message; /// /// Gets or sets the message. /// public String Message { get { return _message; } set { _message = value; RaisePropertyChangedAuto(); } } private bool _blockCancel; /// /// Blocks the cancellation of the dialog until the reconnection procedure completes. /// public bool BlockCancel { get { return _blockCancel; } set { _blockCancel = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } /// /// Initializes a new instance of the class. /// /// The machine. /// The automatic reconnect timeout in seconds. 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()); } } }