blob: 9492433f6d142d804f6b7c14a91fbdee99f4c919 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.FSE.Common.Core;
namespace Tango.FSE.Common.Notifications
{
public class TaskItem : ExtendedObject, IDisposable
{
private Action _cancelAction;
private FSEProgress<double> _progress;
public FSEProgress<double> Progress
{
get { return _progress; }
set { _progress = value; RaisePropertyChangedAuto(); }
}
private bool _hasCancel;
public bool CanCancel
{
get { return _hasCancel; }
set { _hasCancel = value; RaisePropertyChangedAuto(); CancelCommand?.RaiseCanExecuteChanged(); }
}
public RelayCommand CancelCommand { get; set; }
public TaskItem()
{
Progress = new FSEProgress<double>() { Maximum = 100 };
}
public TaskItem(String message) : this()
{
Progress.Message = message;
}
public TaskItem(String message, Action cancelAction) : this(message)
{
_cancelAction = cancelAction;
CancelCommand = new RelayCommand(() =>
{
CanCancel = false;
cancelAction?.Invoke();
}, () => CanCancel);
CanCancel = true;
}
public void UpdateProgress(String message, double value = 0, double maximum = 100, bool isIndeterminate = true)
{
Progress = new FSEProgress<double>()
{
Value = value,
Maximum = maximum,
IsIndeterminate = isIndeterminate,
Message = message,
};
}
public void Dispose()
{
TangoIOC.Default.GetInstance<INotificationProvider>().PopTaskItem(this);
}
}
}
|