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
}
///
/// A task is a piece of work that can be run independentaly from any other task
///
public abstract class Task : INotifyPropertyChanged
{
#region Variables
private bool _enabled = true;
#endregion
#region Properties
///
/// Indicates whether the task is active or not
///
public bool Enabled
{
get { return _enabled; }
set
{
if (_enabled != value)
{
_enabled = value;
OnPropertyChanged("Enabled");
}
}
}
///
/// The name of the task
///
public abstract string Name
{
get; set;
}
///
/// The text displayed during execution of task
///
public abstract string ProgressText
{
get;
}
///
/// The context of the task, containing some useful informations like the current song being converted
///
public TaskContext Context
{
get; set;
}
#endregion
#region Methods
///
/// The method where task execution takes place
///
/// the logger to log errors/warnings
/// the result of the task
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));
}));
}
}
}