diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-06-23 12:04:45 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-06-23 12:04:45 -0400 |
| commit | 1e5c3db9eba730fe8b52995e5c699c22983fa62a (patch) | |
| tree | dd3aed9fe657cc48366b336591838cda756b119f /MediaBrowser.Common/Progress/ActionableProgress.cs | |
| parent | 6ff89eab78a9d25fc8a8d195af558bf1c7ab4d8f (diff) | |
support individual library refreshing
Diffstat (limited to 'MediaBrowser.Common/Progress/ActionableProgress.cs')
| -rw-r--r-- | MediaBrowser.Common/Progress/ActionableProgress.cs | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/MediaBrowser.Common/Progress/ActionableProgress.cs b/MediaBrowser.Common/Progress/ActionableProgress.cs index 39f46ce05..503f3f407 100644 --- a/MediaBrowser.Common/Progress/ActionableProgress.cs +++ b/MediaBrowser.Common/Progress/ActionableProgress.cs @@ -7,12 +7,13 @@ namespace MediaBrowser.Common.Progress /// Class ActionableProgress /// </summary> /// <typeparam name="T"></typeparam> - public class ActionableProgress<T> : Progress<T>, IDisposable + public class ActionableProgress<T> : IProgress<T>, IDisposable { /// <summary> /// The _actions /// </summary> private readonly List<Action<T>> _actions = new List<Action<T>>(); + public event EventHandler<T> ProgressChanged; /// <summary> /// Registers the action. @@ -21,22 +22,6 @@ namespace MediaBrowser.Common.Progress 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> @@ -55,9 +40,34 @@ namespace MediaBrowser.Common.Progress { if (disposing) { - ProgressChanged -= ActionableProgress_ProgressChanged; _actions.Clear(); } } + + public void Report(T value) + { + if (ProgressChanged != null) + { + ProgressChanged(this, value); + } + + foreach (var action in _actions) + { + action(value); + } + } + } + + public class SimpleProgress<T> : IProgress<T> + { + public event EventHandler<T> ProgressChanged; + + public void Report(T value) + { + if (ProgressChanged != null) + { + ProgressChanged(this, value); + } + } } } |
