ActionableProgress.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. namespace MediaBrowser.Common.Progress
  4. {
  5. /// <summary>
  6. /// Class ActionableProgress
  7. /// </summary>
  8. /// <typeparam name="T"></typeparam>
  9. public class ActionableProgress<T> : IProgress<T>
  10. {
  11. /// <summary>
  12. /// The _actions
  13. /// </summary>
  14. private Action<T> _action;
  15. public event EventHandler<T> ProgressChanged;
  16. /// <summary>
  17. /// Registers the action.
  18. /// </summary>
  19. /// <param name="action">The action.</param>
  20. public void RegisterAction(Action<T> action)
  21. {
  22. _action = action;
  23. }
  24. public void Report(T value)
  25. {
  26. if (ProgressChanged != null)
  27. {
  28. ProgressChanged(this, value);
  29. }
  30. var action = _action;
  31. if (action != null)
  32. {
  33. action(value);
  34. }
  35. }
  36. }
  37. public class SimpleProgress<T> : IProgress<T>
  38. {
  39. public event EventHandler<T> ProgressChanged;
  40. public void Report(T value)
  41. {
  42. if (ProgressChanged != null)
  43. {
  44. ProgressChanged(this, value);
  45. }
  46. }
  47. }
  48. }