aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Progress
diff options
context:
space:
mode:
authorLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
committerLukePulverenti <luke.pulverenti@gmail.com>2013-02-20 20:33:05 -0500
commit767cdc1f6f6a63ce997fc9476911e2c361f9d402 (patch)
tree49add55976f895441167c66cfa95e5c7688d18ce /MediaBrowser.Common/Progress
parent845554722efaed872948a9e0f7202e3ef52f1b6e (diff)
Pushing missing changes
Diffstat (limited to 'MediaBrowser.Common/Progress')
-rw-r--r--MediaBrowser.Common/Progress/ActionableProgress.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Progress/ActionableProgress.cs b/MediaBrowser.Common/Progress/ActionableProgress.cs
new file mode 100644
index 0000000000..39f46ce057
--- /dev/null
+++ b/MediaBrowser.Common/Progress/ActionableProgress.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Common.Progress
+{
+ /// <summary>
+ /// Class ActionableProgress
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ public class ActionableProgress<T> : Progress<T>, IDisposable
+ {
+ /// <summary>
+ /// The _actions
+ /// </summary>
+ private readonly List<Action<T>> _actions = new List<Action<T>>();
+
+ /// <summary>
+ /// Registers the action.
+ /// </summary>
+ /// <param name="action">The action.</param>
+ public void RegisterAction(Action<T> action)
+ {
+ _actions.Add(action);
+
+ ProgressChanged -= ActionableProgress_ProgressChanged;
+ ProgressChanged += ActionableProgress_ProgressChanged;
+ }
+
+ /// <summary>
+ /// Actionables the progress_ progress changed.
+ /// </summary>
+ /// <param name="sender">The sender.</param>
+ /// <param name="e">The e.</param>
+ void ActionableProgress_ProgressChanged(object sender, T e)
+ {
+ foreach (var action in _actions)
+ {
+ action(e);
+ }
+ }
+
+ /// <summary>
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ /// <summary>
+ /// Releases unmanaged and - optionally - managed resources.
+ /// </summary>
+ /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ ProgressChanged -= ActionableProgress_ProgressChanged;
+ _actions.Clear();
+ }
+ }
+ }
+}