DefaultConfigSettingStore.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections.Generic;
  2. using System.Configuration;
  3. using System.Threading.Tasks;
  4. using Abp.Logging;
  5. using Abp.Threading;
  6. namespace Abp.Configuration
  7. {
  8. /// <summary>
  9. /// Implements default behavior for ISettingStore.
  10. /// Only <see cref="GetSettingOrNullAsync"/> method is implemented and it gets setting's value
  11. /// from application's configuration file if exists, or returns null if not.
  12. /// </summary>
  13. public class DefaultConfigSettingStore : ISettingStore
  14. {
  15. /// <summary>
  16. /// Gets singleton instance.
  17. /// </summary>
  18. public static DefaultConfigSettingStore Instance { get; } = new DefaultConfigSettingStore();
  19. private DefaultConfigSettingStore()
  20. {
  21. }
  22. public Task<SettingInfo> GetSettingOrNullAsync(int? tenantId, long? userId, string name)
  23. {
  24. var value = ConfigurationManager.AppSettings[name];
  25. if (value == null)
  26. {
  27. return Task.FromResult<SettingInfo>(null);
  28. }
  29. return Task.FromResult(new SettingInfo(tenantId, userId, name, value));
  30. }
  31. /// <inheritdoc/>
  32. public Task DeleteAsync(SettingInfo setting)
  33. {
  34. LogHelper.Logger.Warn("ISettingStore is not implemented, using DefaultConfigSettingStore which does not support DeleteAsync.");
  35. return AbpTaskCache.CompletedTask;
  36. }
  37. /// <inheritdoc/>
  38. public Task CreateAsync(SettingInfo setting)
  39. {
  40. LogHelper.Logger.Warn("ISettingStore is not implemented, using DefaultConfigSettingStore which does not support CreateAsync.");
  41. return AbpTaskCache.CompletedTask;
  42. }
  43. /// <inheritdoc/>
  44. public Task UpdateAsync(SettingInfo setting)
  45. {
  46. LogHelper.Logger.Warn("ISettingStore is not implemented, using DefaultConfigSettingStore which does not support UpdateAsync.");
  47. return AbpTaskCache.CompletedTask;
  48. }
  49. /// <inheritdoc/>
  50. public Task<List<SettingInfo>> GetAllListAsync(int? tenantId, long? userId)
  51. {
  52. LogHelper.Logger.Warn("ISettingStore is not implemented, using DefaultConfigSettingStore which does not support GetAllListAsync.");
  53. return Task.FromResult(new List<SettingInfo>());
  54. }
  55. }
  56. }