2021-12-31 17:48:04 +00:00
|
|
|
|
using System;
|
2022-01-10 10:52:07 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2021-12-31 17:48:04 +00:00
|
|
|
|
|
|
|
|
|
namespace PettingZoo.Tapeti.UI.PackageProgress
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for PackageProgressWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class PackageProgressWindow : IProgress<int>
|
|
|
|
|
{
|
2022-01-10 10:52:07 +00:00
|
|
|
|
private readonly CancellationTokenSource cancellationTokenSource = new();
|
|
|
|
|
|
|
|
|
|
public CancellationToken CancellationToken => cancellationTokenSource.Token;
|
|
|
|
|
|
|
|
|
|
|
2021-12-31 17:48:04 +00:00
|
|
|
|
public PackageProgressWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2022-01-10 10:52:07 +00:00
|
|
|
|
|
|
|
|
|
Closed += (_, _) =>
|
|
|
|
|
{
|
|
|
|
|
cancellationTokenSource.Cancel();
|
|
|
|
|
};
|
2021-12-31 17:48:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Report(int value)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.BeginInvoke(() =>
|
|
|
|
|
{
|
|
|
|
|
Progress.Value = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-01-10 10:52:07 +00:00
|
|
|
|
|
|
|
|
|
private void CancelButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
cancellationTokenSource.Cancel();
|
|
|
|
|
((Button)sender).IsEnabled = false;
|
|
|
|
|
}
|
2021-12-31 17:48:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|