PercentDoneEventArgs.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace SevenZip
  2. {
  3. using System;
  4. /// <summary>
  5. /// EventArgs for storing PercentDone property.
  6. /// </summary>
  7. public class PercentDoneEventArgs : EventArgs
  8. {
  9. /// <summary>
  10. /// Initializes a new instance of the PercentDoneEventArgs class.
  11. /// </summary>
  12. /// <param name="percentDone">The percent of finished work.</param>
  13. /// <exception cref="System.ArgumentOutOfRangeException"/>
  14. public PercentDoneEventArgs(byte percentDone)
  15. {
  16. if (percentDone > 100 || percentDone < 0)
  17. {
  18. throw new ArgumentOutOfRangeException(nameof(percentDone),
  19. "The percent of finished work must be between 0 and 100.");
  20. }
  21. PercentDone = percentDone;
  22. }
  23. /// <summary>
  24. /// Gets the percent of finished work.
  25. /// </summary>
  26. public byte PercentDone { get; }
  27. /// <summary>
  28. /// Converts a [0, 1] rate to its percent equivalent.
  29. /// </summary>
  30. /// <param name="doneRate">The rate of the done work.</param>
  31. /// <returns>Percent integer equivalent.</returns>
  32. /// <exception cref="System.ArgumentException"/>
  33. internal static byte ProducePercentDone(float doneRate)
  34. {
  35. return (byte)Math.Round(Math.Min(100 * doneRate, 100), MidpointRounding.AwayFromZero);
  36. }
  37. }
  38. }