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 _progress; public FSEProgress 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() { 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() { Value = value, Maximum = maximum, IsIndeterminate = isIndeterminate, Message = message, }; } public void Dispose() { TangoIOC.Default.GetInstance().PopTaskItem(this); } } }