EasyConfigOptions.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace EasyDevCore.Configuration
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public interface IEasyConfigOptions
  14. {
  15. /// <summary>
  16. /// Gets or sets the type of the configuration.
  17. /// </summary>
  18. /// <value>
  19. /// The type of the configuration.
  20. /// </value>
  21. EasyConfigFileType ConfigType { get; }
  22. /// <summary>
  23. /// Gets or sets the encrypt password.
  24. /// </summary>
  25. /// <value>
  26. /// The encrypt password.
  27. /// </value>
  28. string EncryptPassword { get; }
  29. /// <summary>
  30. /// Gets the automatic save delay.
  31. /// </summary>
  32. /// <value>
  33. /// The automatic save delay.
  34. /// </value>
  35. int AutoSaveDelay { get; }
  36. /// <summary>
  37. /// Gets a value indicating whether [automatic save].
  38. /// </summary>
  39. /// <value>
  40. /// <c>true</c> if [automatic save]; otherwise, <c>false</c>.
  41. /// </value>
  42. bool AutoSave { get; }
  43. /// <summary>
  44. /// Gets or sets the name of the file.
  45. /// </summary>
  46. /// <value>
  47. /// The name of the file.
  48. /// </value>
  49. string FileName { get; }
  50. }
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. /// <seealso cref="EasyDevCore.Configuration.IEasyConfigOptions" />
  55. /// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
  56. /// <seealso cref="INotifyPropertyChanged" />
  57. public class EasyConfigOptions : IEasyConfigOptions, INotifyPropertyChanged
  58. {
  59. /// <summary>
  60. /// Gets or sets the type of the configuration.
  61. /// </summary>
  62. /// <value>
  63. /// The type of the configuration.
  64. /// </value>
  65. public EasyConfigFileType ConfigType { get; internal set; } = EasyConfigFileType.Auto;
  66. /// <summary>
  67. /// Gets or sets the encrypt password.
  68. /// </summary>
  69. /// <value>
  70. /// The encrypt password.
  71. /// </value>
  72. public string EncryptPassword { get; set; }
  73. private int _AutoSaveDelay = 10;
  74. /// <summary>
  75. /// Gets the automatic save delay.
  76. /// </summary>
  77. /// <value>
  78. /// The automatic save delay.
  79. /// </value>
  80. public int AutoSaveDelay
  81. {
  82. get => _AutoSaveDelay;
  83. set
  84. {
  85. _AutoSaveDelay = value;
  86. NotifyPropertyChanged();
  87. }
  88. }
  89. private bool _AutoSave = false;
  90. /// <summary>
  91. /// Gets a value indicating whether [automatic save].
  92. /// </summary>
  93. /// <value>
  94. /// <c>true</c> if [automatic save]; otherwise, <c>false</c>.
  95. /// </value>
  96. public bool AutoSave
  97. {
  98. get => _AutoSave;
  99. set
  100. {
  101. _AutoSave = value;
  102. NotifyPropertyChanged();
  103. }
  104. }
  105. /// <summary>
  106. /// Gets or sets the name of the file.
  107. /// </summary>
  108. /// <value>
  109. /// The name of the file.
  110. /// </value>
  111. public string FileName { get; set; }
  112. /// <summary>
  113. /// Occurs when a property value changes.
  114. /// </summary>
  115. public event PropertyChangedEventHandler PropertyChanged;
  116. // This method is called by the Set accessor of each property.
  117. // The CallerMemberName attribute that is applied to the optional propertyName
  118. // parameter causes the property name of the caller to be substituted as an argument.
  119. private void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
  120. {
  121. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  122. }
  123. }
  124. }