77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
|
using System;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows;
|
|||
|
|
|||
|
namespace MECF.Framework.UI.Client.ClientBase.Dialog
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Interaction logic for LoginRequestConfirmationDialog.xaml
|
|||
|
/// </summary>
|
|||
|
public partial class LoginRequestConfirmationDialog : Window
|
|||
|
{
|
|||
|
#region Variables
|
|||
|
|
|||
|
private readonly CancellationTokenSource _ctsCountDownTask;
|
|||
|
private readonly IProgress<double> _progCountDown;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public LoginRequestConfirmationDialog()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
_ctsCountDownTask = new CancellationTokenSource ();
|
|||
|
|
|||
|
_progCountDown = new Progress<double>(countDown =>
|
|||
|
{
|
|||
|
if(countDown > 0)
|
|||
|
BtnRejected.Content = $"Reject ({countDown:F0}s)";
|
|||
|
else
|
|||
|
DialogResult = false;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
protected override void OnSourceInitialized(EventArgs e)
|
|||
|
{
|
|||
|
base.OnSourceInitialized(e);
|
|||
|
|
|||
|
var closeTime = DateTime.Now.Add(TimeSpan.FromSeconds(30));
|
|||
|
Task.Run(() =>
|
|||
|
{
|
|||
|
while (true)
|
|||
|
{
|
|||
|
var timeRemained = (closeTime - DateTime.Now).TotalSeconds;
|
|||
|
if (timeRemained <= 0)
|
|||
|
{
|
|||
|
// force to reject
|
|||
|
_progCountDown.Report(0);
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
_progCountDown.Report(timeRemained);
|
|||
|
Thread.Sleep(500);
|
|||
|
|
|||
|
if (_ctsCountDownTask.Token.IsCancellationRequested)
|
|||
|
break;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|||
|
{
|
|||
|
_ctsCountDownTask?.Cancel();
|
|||
|
}
|
|||
|
|
|||
|
private void BtnRejected_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
DialogResult = false;
|
|||
|
}
|
|||
|
|
|||
|
private void BtnAccept_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
DialogResult = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|