using System;
using System.Collections.Generic;
namespace MediaBrowser.Common.Progress
{
///
/// Class ActionableProgress
///
///
public class ActionableProgress : IProgress, IDisposable
{
///
/// The _actions
///
private readonly List> _actions = new List>();
public event EventHandler ProgressChanged;
///
/// Registers the action.
///
/// The action.
public void RegisterAction(Action action)
{
_actions.Add(action);
}
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose()
{
Dispose(true);
}
///
/// Releases unmanaged and - optionally - managed resources.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_actions.Clear();
}
}
public void Report(T value)
{
if (ProgressChanged != null)
{
ProgressChanged(this, value);
}
foreach (var action in _actions)
{
action(value);
}
}
}
public class SimpleProgress : IProgress
{
public event EventHandler ProgressChanged;
public void Report(T value)
{
if (ProgressChanged != null)
{
ProgressChanged(this, value);
}
}
}
}