From 805e16de3a404bff97399d1acfd8d8c7ac96f5d4 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 12 Feb 2019 14:26:36 +0300 Subject: [PATCH] Implemented RemoteSettingProvider --- .../Mvc/Client/RemoteSettingProvider.cs | 33 +++++++++++++++++ .../ApplicationConfigurationDto.cs | 2 + .../ApplicationSettingConfigurationDto.cs | 11 ++++++ .../AbpApplicationConfigurationAppService.cs | 37 +++++++++++++++++-- .../Abp/Settings/ISettingDefinitionManager.cs | 2 + 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteSettingProvider.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationSettingConfigurationDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteSettingProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteSettingProvider.cs new file mode 100644 index 0000000000..db3ea6e9a6 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteSettingProvider.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Settings; + +namespace Volo.Abp.AspNetCore.Mvc.Client +{ + public class RemoteSettingProvider : ISettingProvider, ITransientDependency + { + protected ICachedApplicationConfigurationClient ConfigurationClient { get; } + + public RemoteSettingProvider(ICachedApplicationConfigurationClient configurationClient) + { + ConfigurationClient = configurationClient; + } + + public async Task GetOrNullAsync(string name) + { + var configuration = await ConfigurationClient.GetAsync(); + return configuration.Setting.Values.GetOrDefault(name); + } + + public async Task> GetAllAsync() + { + var configuration = await ConfigurationClient.GetAsync(); + return configuration + .Setting.Values + .Select(s => new SettingValue(s.Key, s.Value)) + .ToList(); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs index ecafcb3274..6f41399c29 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations public ApplicationAuthConfigurationDto Auth { get; set; } + public ApplicationSettingConfigurationDto Setting { get; set; } + public CurrentUserDto CurrentUser { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationSettingConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationSettingConfigurationDto.cs new file mode 100644 index 0000000000..40cbd89fd1 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationSettingConfigurationDto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations +{ + [Serializable] + public class ApplicationSettingConfigurationDto + { + public Dictionary Values { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index a91cdebc35..086fbf1d72 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -4,10 +4,12 @@ using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Authorization; using Volo.Abp.Localization; +using Volo.Abp.Settings; using Volo.Abp.Users; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations @@ -19,18 +21,24 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations private readonly IAbpAuthorizationPolicyProvider _abpAuthorizationPolicyProvider; private readonly IAuthorizationService _authorizationService; private readonly ICurrentUser _currentUser; + private readonly ISettingProvider _settingProvider; + private readonly ISettingDefinitionManager _settingDefinitionManager; public AbpApplicationConfigurationAppService( IOptions localizationOptions, IServiceProvider serviceProvider, IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider, IAuthorizationService authorizationService, - ICurrentUser currentUser) + ICurrentUser currentUser, + ISettingProvider settingProvider, + SettingDefinitionManager settingDefinitionManager) { _serviceProvider = serviceProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; _authorizationService = authorizationService; _currentUser = currentUser; + _settingProvider = settingProvider; + _settingDefinitionManager = settingDefinitionManager; _localizationOptions = localizationOptions.Value; } @@ -40,9 +48,10 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations return new ApplicationConfigurationDto { - Auth = await GetAuthConfig(), + Auth = await GetAuthConfigAsync(), Localization = GetLocalizationConfig(), - CurrentUser = GetCurrentUser() + CurrentUser = GetCurrentUser(), + Setting = await GetSettingConfigAsync() }; } @@ -57,7 +66,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations }; } - protected virtual async Task GetAuthConfig() + protected virtual async Task GetAuthConfigAsync() { var authConfig = new ApplicationAuthConfigurationDto(); @@ -97,5 +106,25 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations return localizationConfig; } + + private async Task GetSettingConfigAsync() + { + var result = new ApplicationSettingConfigurationDto + { + Values = new Dictionary() + }; + + foreach (var settingDefinition in _settingDefinitionManager.GetAll()) + { + if (!settingDefinition.IsVisibleToClients) + { + continue; + } + + result.Values[settingDefinition.Name] = await _settingProvider.GetOrNullAsync(settingDefinition.Name); + } + + return result; + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingDefinitionManager.cs b/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingDefinitionManager.cs index 176f5b314c..3ff30c575a 100644 --- a/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingDefinitionManager.cs +++ b/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingDefinitionManager.cs @@ -9,5 +9,7 @@ namespace Volo.Abp.Settings SettingDefinition Get([NotNull] string name); IReadOnlyList GetAll(); + + SettingDefinition GetOrNull(string name); } } \ No newline at end of file