ISettingManager.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using Abp;
  4. using Abp.Configuration;
  5. namespace IwbZero.Setting
  6. {
  7. /// <summary>
  8. /// This is the main interface that must be implemented to be able to load/change values of settings.
  9. /// </summary>
  10. public interface IIwbSettingManager
  11. {
  12. Task RefreshAsync();
  13. Task RefreshForUserAsync(long userId);
  14. Task RefreshForUserAsync(UserIdentifier user);
  15. /// <summary>
  16. /// Gets current value of a setting.
  17. /// It gets the setting value, overwritten by application, current tenant and current user if exists.
  18. /// </summary>
  19. /// <param name="name">Unique name of the setting</param>
  20. /// <returns>Current value of the setting</returns>
  21. Task<string> GetSettingValueAsync(string name);
  22. /// <summary>
  23. /// Gets current value of a setting for the application level.
  24. /// </summary>
  25. /// <param name="name">Unique name of the setting</param>
  26. /// <returns>Current value of the setting for the application</returns>
  27. Task<string> GetSettingValueForApplicationAsync(string name);
  28. /// <summary>
  29. /// Gets current value of a setting for the application level.
  30. /// If fallbackToDefault is false, it just gets value from application and returns null if application has not defined a value for the setting.
  31. /// </summary>
  32. /// <param name="name">Unique name of the setting</param>
  33. /// <param name="fallbackToDefault"></param>
  34. /// <returns>Current value of the setting for the application</returns>
  35. Task<string> GetSettingValueForApplicationAsync(string name, bool fallbackToDefault);
  36. /// <summary>
  37. /// Gets current value of a setting for a user level.
  38. /// It gets the setting value, overwritten by given tenant and user.
  39. /// </summary>
  40. /// <param name="name">Unique name of the setting</param>
  41. /// <param name="userId">User id</param>
  42. /// <returns>Current value of the setting for the user</returns>
  43. Task<string> GetSettingValueForUserAsync(string name, long userId);
  44. /// <summary>
  45. /// Gets current value of a setting for a user level.
  46. /// It gets the setting value, overwritten by given tenant and user if fallbackToDefault is true.
  47. /// If fallbackToDefault is false, it just gets value from user and returns null if user has not defined a value for the setting.
  48. /// </summary>
  49. /// <param name="name">Unique name of the setting</param>
  50. /// <param name="userId">User id</param>
  51. /// <param name="fallbackToDefault"></param>
  52. /// <returns>Current value of the setting for the user</returns>
  53. Task<string> GetSettingValueForUserAsync(string name, long userId, bool fallbackToDefault);
  54. /// <summary>
  55. /// Gets current value of a setting for a user level.
  56. /// It gets the setting value, overwritten by given tenant and user.
  57. /// </summary>
  58. /// <param name="name">Unique name of the setting</param>
  59. /// <param name="user">User</param>
  60. /// <returns>Current value of the setting for the user</returns>
  61. Task<string> GetSettingValueForUserAsync(string name, UserIdentifier user);
  62. /// <summary>
  63. /// Gets current values of all settings.
  64. /// It gets all setting values, overwritten by application, current tenant (if exists) and the current user (if exists).
  65. /// </summary>
  66. /// <returns>List of setting values</returns>
  67. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesAsync();
  68. /// <summary>
  69. /// Gets current values of all settings.
  70. /// It gets default values of all settings then overwrites by given scopes.
  71. /// </summary>
  72. /// <param name="scopes">One or more scope to overwrite</param>
  73. /// <returns>List of setting values</returns>
  74. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesAsync(SettingScopes scopes);
  75. /// <summary>
  76. /// Gets a list of all setting values specified for the application.
  77. /// It returns only settings those are explicitly set for the application.
  78. /// If a setting's default value is used, it's not included the result list.
  79. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  80. /// </summary>
  81. /// <returns>List of setting values</returns>
  82. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForApplicationAsync();
  83. /// <summary>
  84. /// Gets a list of all setting values specified for a tenant.
  85. /// It returns only settings those are explicitly set for the tenant.
  86. /// If a setting's default value is used, it's not included the result list.
  87. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  88. /// </summary>
  89. /// <param name="tenantId">Tenant to get settings</param>
  90. /// <returns>List of setting values</returns>
  91. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForTenantAsync(int tenantId);
  92. /// <summary>
  93. /// Gets a list of all setting values specified for a user.
  94. /// It returns only settings those are explicitly set for the user.
  95. /// If a setting's value is not set for the user (for example if user uses the default value), it's not included the result list.
  96. /// If you want to get current values of all settings, use <see cref="GetAllSettingValuesAsync()"/> method.
  97. /// </summary>
  98. /// <param name="user">User to get settings</param>
  99. /// <returns>All settings of the user</returns>
  100. Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesForUserAsync(UserIdentifier user);
  101. /// <summary>
  102. /// Changes setting for the application level.
  103. /// </summary>
  104. /// <param name="name">Unique name of the setting</param>
  105. /// <param name="value">Value of the setting</param>
  106. Task ChangeSettingForApplicationAsync(string name, string value);
  107. /// <summary>
  108. /// Changes setting for a Tenant.
  109. /// </summary>
  110. /// <param name="tenantId">TenantId</param>
  111. /// <param name="name">Unique name of the setting</param>
  112. /// <param name="value">Value of the setting</param>
  113. Task ChangeSettingForTenantAsync(int tenantId, string name, string value);
  114. /// <summary>
  115. /// Changes setting for a user.
  116. /// </summary>
  117. /// <param name="user">UserId</param>
  118. /// <param name="name">Unique name of the setting</param>
  119. /// <param name="value">Value of the setting</param>
  120. Task ChangeSettingForUserAsync(UserIdentifier user, string name, string value);
  121. }
  122. }