using System;
using System.Collections.Generic;
namespace MediaBrowser.Common.Progress
{
///
/// Class ActionableProgress
///
///
public class ActionableProgress : Progress, IDisposable
{
///
/// The _actions
///
private readonly List> _actions = new List>();
///
/// Registers the action.
///
/// The action.
public void RegisterAction(Action action)
{
_actions.Add(action);
ProgressChanged -= ActionableProgress_ProgressChanged;
ProgressChanged += ActionableProgress_ProgressChanged;
}
///
/// Actionables the progress_ progress changed.
///
/// The sender.
/// The e.
void ActionableProgress_ProgressChanged(object sender, T e)
{
foreach (var action in _actions)
{
action(e);
}
}
///
/// 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)
{
ProgressChanged -= ActionableProgress_ProgressChanged;
_actions.Clear();
}
}
}
}