JD2022-TU1/main/tools/apps/JDSongConverter/Tasks/Task.cs

96 lines
2.4 KiB
C#

using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
using JetBrains.Annotations;
using TeaBox.Macros;
namespace JDSongConverter.Tasks
{
public enum TaskResult
{
Ok,
Error,
ParametersError,
FileMissing
}
/// <summary>
/// A task is a piece of work that can be run independentaly from any other task
/// </summary>
public abstract class Task : INotifyPropertyChanged
{
#region Variables
private bool _enabled = true;
#endregion
#region Properties
/// <summary>
/// Indicates whether the task is active or not
/// </summary>
public bool Enabled
{
get { return _enabled; }
set
{
if (_enabled != value)
{
_enabled = value;
OnPropertyChanged("Enabled");
}
}
}
/// <summary>
/// The name of the task
/// </summary>
public abstract string Name
{
get; set;
}
/// <summary>
/// The text displayed during execution of task
/// </summary>
public abstract string ProgressText
{
get;
}
/// <summary>
/// The context of the task, containing some useful informations like the current song being converted
/// </summary>
public TaskContext Context
{
get; set;
}
#endregion
#region Methods
/// <summary>
/// The method where task execution takes place
/// </summary>
/// <param name="executionContext">the logger to log errors/warnings</param>
/// <returns>the result of the task</returns>
public abstract TaskResult Process(IExecutionContext executionContext);
#endregion
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}));
}
}
}