TransferResumeSupport.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Runtime.InteropServices;
  2. using System;
  3. using System.Globalization;
  4. namespace WinSCP
  5. {
  6. [Guid("0ADAAEBC-4A15-4A9C-8ED4-D85F5630035C")]
  7. [ComVisible(true)]
  8. public enum TransferResumeSupportState
  9. {
  10. Default,
  11. On,
  12. Off,
  13. Smart
  14. }
  15. [Guid("6CED4579-0DF2-4E46-93E9-18780546B421")]
  16. [ClassInterface(Constants.ClassInterface)]
  17. [ComVisible(true)]
  18. public sealed class TransferResumeSupport
  19. {
  20. public TransferResumeSupportState State { get; set; }
  21. public int Threshold { get { return GetThreshold(); } set { SetThreshold(value); } }
  22. internal TransferResumeSupport()
  23. {
  24. State = TransferResumeSupportState.Default;
  25. _threshold = 100; // (100 KiB)
  26. }
  27. public override string ToString()
  28. {
  29. string result;
  30. switch (State)
  31. {
  32. case TransferResumeSupportState.Default:
  33. result = "default";
  34. break;
  35. case TransferResumeSupportState.Off:
  36. result = "off";
  37. break;
  38. case TransferResumeSupportState.On:
  39. result = "on";
  40. break;
  41. case TransferResumeSupportState.Smart:
  42. result = Threshold.ToString(CultureInfo.InvariantCulture);
  43. break;
  44. default:
  45. result = "unknown";
  46. break;
  47. }
  48. return result;
  49. }
  50. private int GetThreshold()
  51. {
  52. CheckSmart();
  53. return _threshold;
  54. }
  55. private void SetThreshold(int threshold)
  56. {
  57. if (threshold <= 0)
  58. {
  59. throw new ArgumentOutOfRangeException("threshold", "Threshold must be possitive");
  60. }
  61. CheckSmart();
  62. _threshold = threshold;
  63. }
  64. private void CheckSmart()
  65. {
  66. if (State != TransferResumeSupportState.Smart)
  67. {
  68. throw new InvalidOperationException("Threshold is undefined when state is not Smart");
  69. }
  70. }
  71. private int _threshold;
  72. }
  73. }