using System; using System.Collections.Generic; using System.Linq; using Kurs.Settings.Localization; using Volo.Abp.Domain.Repositories; using Volo.Abp.Localization; using Volo.Abp.Settings; using SettingDefinition = Kurs.Settings.Entities.SettingDefinition; namespace Kurs.Settings; public class SettingsDefinitionProvider : SettingDefinitionProvider { private readonly IRepository repository; private const char MultiValueDelimiter = '|'; public SettingsDefinitionProvider(IRepository repository) { this.repository = repository; } public override void Define(ISettingDefinitionContext context) { repository.DisableTracking(); var settingDefinitions = repository.GetListAsync().Result; //var settingDefinitions = AsyncHelper.RunSync(() => repository.ToListAsync()); foreach (var item in settingDefinitions.OrderBy(a => a.Order)) { var iDescription = item.DescriptionKey.IsNullOrEmpty() ? null : L(item.DescriptionKey); var def = new Volo.Abp.Settings.SettingDefinition( item.Code, item.DefaultValue, L(item.NameKey), iDescription, item.IsVisibleToClients, item.IsInherited, item.IsEncrypted) .WithProperty(SettingsConsts.MainGroup, item.MainGroupKey) .WithProperty(SettingsConsts.SubGroup, item.SubGroupKey) .WithProperty(SettingsConsts.DataType, item.DataType) .WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName) .WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value))); if (!item.Providers.IsNullOrEmpty()) { def.Providers.AddRange(item.Providers.Split(MultiValueDelimiter)); } context.Add(def); } } private static ILocalizableString L(string name) { return new LocalizableString(typeof(SettingsResource), name); } } /* Definitionlar normalde eziliyor fakat bir sebepten mevcut definitionlar ezilmezse, mevcutları alıp değiştirmek için gerekli yapı şu şekilde: var iDescription = item.DescriptionKey.IsNullOrEmpty() ? null : L(item.DescriptionKey); var providers = item.Providers.IsNullOrEmpty() ? new string[] { } : item.Providers.ToArray(); var def = context.GetOrNull(item.Code); if (def == null) { def = new Volo.Abp.Settings.SettingDefinition( item.Code, item.DefaultValue, L(item.NameKey), iDescription, item.IsVisibleToClients, item.IsInherited, item.IsEncrypted) .WithProperty(SettingsConsts.MainGroup, L(item.MainGroupKey)) .WithProperty(SettingsConsts.SubGroup, L(item.SubGroupKey)) .WithProperty(SettingsConsts.DataType, item.DataType) .WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName) .WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value))) .WithProviders(providers); context.Add(def); } else { def.DefaultValue = item.DefaultValue; def.DisplayName = L(item.NameKey); def.Description = iDescription; def.IsVisibleToClients = item.IsVisibleToClients; def.IsInherited = item.IsInherited; def.IsEncrypted = item.IsEncrypted; def.Properties.Clear(); def.Providers.Clear(); def.WithProperty(SettingsConsts.MainGroup, L(item.MainGroupKey)) .WithProperty(SettingsConsts.SubGroup, L(item.SubGroupKey)) .WithProperty(SettingsConsts.DataType, item.DataType) .WithProperty(SettingsConsts.RequiredPermission, item.RequiredPermissionName) .WithProperty(SettingsConsts.SelectOptions, item.SelectOptions?.ToDictionary(x => x.Key, x => L(x.Value))) .WithProviders(providers); } */