ANTFS_TransferStatus.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. //////////////////////////////////////////////////////////////////////////
  9. // This file contains all the enumerations and constants for general
  10. // use with ANT-FS
  11. //////////////////////////////////////////////////////////////////////////
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15. namespace ANT_Managed_Library.ANTFS
  16. {
  17. /// <summary>
  18. /// Status of an ongoing or completed data transfer
  19. /// </summary>
  20. public class TransferStatus
  21. {
  22. private uint myByteProgress;
  23. private uint myTotalLength;
  24. private byte myPercentage;
  25. /// <summary>
  26. /// Constructor initializes status and obtains percentage from parameters
  27. /// </summary>
  28. /// <param name="Progress">Current byte progress</param>
  29. /// <param name="Length">Expected data length</param>
  30. public TransferStatus(uint Progress, uint Length)
  31. {
  32. this.myByteProgress = Progress;
  33. this.myTotalLength = Length;
  34. if (Length != 0)
  35. this.myPercentage = (byte)Math.Round(((decimal)Progress / (decimal)Length) * 100);
  36. else
  37. this.myPercentage = 0;
  38. }
  39. /// <summary>
  40. /// Current byte progress of a data transfer
  41. /// </summary>
  42. public uint ByteProgress
  43. {
  44. get { return myByteProgress; }
  45. }
  46. /// <summary>
  47. /// Expected length of a data transfer
  48. /// </summary>
  49. public uint TotalLength
  50. {
  51. get { return myTotalLength; }
  52. }
  53. /// <summary>
  54. /// Current percentage of completion of a data transfer
  55. /// </summary>
  56. public byte Percentage
  57. {
  58. get { return myPercentage; }
  59. }
  60. /// <summary>
  61. /// Provides a string containing the transfer status
  62. /// </summary>
  63. /// <returns>Formatted string with the current byte progress, expected length and percentage</returns>
  64. public override string ToString()
  65. {
  66. return "Transfer Status: (" + myByteProgress + "/" + myTotalLength + ") ... " + myPercentage + '%';
  67. }
  68. }
  69. }