aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Progress/ActionableProgress.cs
blob: fe7cb107886860031e0ab5b7242a4041e5a9d7c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma warning disable CS1591
#pragma warning disable CA1003

using System;

namespace MediaBrowser.Common.Progress
{
    /// <summary>
    /// Class ActionableProgress.
    /// </summary>
    /// <typeparam name="T">The type for the action parameter.</typeparam>
    public class ActionableProgress<T> : IProgress<T>
    {
        /// <summary>
        /// The _actions.
        /// </summary>
        private Action<T> _action;

        public event EventHandler<T> ProgressChanged;

        /// <summary>
        /// Registers the action.
        /// </summary>
        /// <param name="action">The action.</param>
        public void RegisterAction(Action<T> action)
        {
            _action = action;
        }

        public void Report(T value)
        {
            ProgressChanged?.Invoke(this, value);

            _action?.Invoke(value);
        }
    }
}