2023-09-15 23:57:38 +08:00
|
|
|
|
using Aitex.Core.Account;
|
|
|
|
|
using System;
|
2023-09-15 17:44:30 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace MECF.Framework.UI.Client.ClientBase.Dialog
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for LoginRequestWaitDialog.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class LoginRequestWaitDialog : Window
|
|
|
|
|
{
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
|
|
private readonly CancellationTokenSource _ctsCountDownTask;
|
|
|
|
|
private readonly IProgress<double> _progCountDown;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public LoginRequestWaitDialog()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
_ctsCountDownTask = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
_progCountDown = new Progress<double>(countDown =>
|
|
|
|
|
{
|
2023-09-18 14:17:34 +08:00
|
|
|
|
// 更新Cancel按钮倒计时数值
|
|
|
|
|
// 如果倒计时为0,则关闭当前窗口
|
2023-09-15 17:44:30 +08:00
|
|
|
|
if (countDown > 0)
|
|
|
|
|
BtnCancel.Content = $"Cancel ({countDown:F0}s)";
|
|
|
|
|
else
|
2023-09-18 14:37:21 +08:00
|
|
|
|
Close();
|
2023-09-15 17:44:30 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSourceInitialized(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnSourceInitialized(e);
|
|
|
|
|
|
2023-09-18 15:51:37 +08:00
|
|
|
|
var closeTime = DateTime.Now.Add(TimeSpan.FromSeconds(CredentialManager.REQ_LOGIN_DIALOG_LIFT_TIME_SEC));
|
2023-09-18 14:17:34 +08:00
|
|
|
|
var ct = _ctsCountDownTask?.Token;
|
2023-09-15 17:44:30 +08:00
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
var timeRemained = (closeTime - DateTime.Now).TotalSeconds;
|
|
|
|
|
if (timeRemained <= 0)
|
|
|
|
|
{
|
2023-09-18 14:37:21 +08:00
|
|
|
|
// 关闭对话框
|
2023-09-15 17:44:30 +08:00
|
|
|
|
_progCountDown.Report(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_progCountDown.Report(timeRemained);
|
2023-09-18 14:17:34 +08:00
|
|
|
|
|
2023-09-15 17:44:30 +08:00
|
|
|
|
Thread.Sleep(500);
|
|
|
|
|
|
2023-09-18 14:17:34 +08:00
|
|
|
|
// 操作被取消
|
|
|
|
|
if (ct is { IsCancellationRequested: true })
|
2023-09-18 14:37:21 +08:00
|
|
|
|
{
|
|
|
|
|
// 关闭对话框
|
|
|
|
|
_progCountDown.Report(0);
|
2023-09-15 17:44:30 +08:00
|
|
|
|
break;
|
2023-09-18 14:37:21 +08:00
|
|
|
|
}
|
2023-09-15 17:44:30 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2023-09-18 14:37:21 +08:00
|
|
|
|
Close();
|
2023-09-15 17:44:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|