/// <inheritdoc/> public async Task <IReadOnlyList <ISettingValue> > GetAllSettingValuesAsync(SettingScopes scopes) { var settingDefinitions = new Dictionary <string, SettingDefinition>(); var settingValues = new Dictionary <string, ISettingValue>(); //Fill all setting with default values. foreach (var setting in _settingDefinitionManager.GetAllSettingDefinitions()) { settingDefinitions[setting.Name] = setting; settingValues[setting.Name] = new SettingValueObject(setting.Name, setting.DefaultValue); } //Overwrite application settings if (scopes.HasFlag(SettingScopes.Application)) { foreach (var settingValue in await GetAllSettingValuesForApplicationAsync()) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.Application)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } //Overwrite tenant settings if (scopes.HasFlag(SettingScopes.Tenant) && AbpSession.TenantId.HasValue) { foreach (var settingValue in await GetAllSettingValuesForTenantAsync(AbpSession.TenantId.Value)) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.Tenant)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } //Overwrite user settings if (scopes.HasFlag(SettingScopes.User) && AbpSession.UserId.HasValue) { foreach (var settingValue in await GetAllSettingValuesForUserAsync(AbpSession.UserId.Value)) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.User)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } return(settingValues.Values.ToImmutableList()); }
/// <inheritdoc/> public async Task <IReadOnlyList <ISettingValue> > GetAllSettingValuesAsync(SettingScopes scopes) { var settingDefinitions = new Dictionary <string, SettingDefinition>(); var settingValues = new Dictionary <string, ISettingValue>(); //Fill all setting with default values. foreach (var setting in _settingDefinitionManager.GetAllSettingDefinitions()) { settingDefinitions[setting.Name] = setting; settingValues[setting.Name] = new SettingValueObject(setting.Name, setting.DefaultValue); } //Overwrite application settings if (scopes.HasFlag(SettingScopes.Application)) { foreach (var settingValue in await GetAllSettingValuesForApplicationAsync()) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); //TODO: Conditions get complicated, try to simplify it if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Application)) { continue; } if (!setting.IsInherited && ((setting.Scopes.HasFlag(SettingScopes.User) && SmdSession.UserId.HasValue))) { continue; } settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } //Overwrite user settings if (scopes.HasFlag(SettingScopes.User) && SmdSession.UserId.HasValue) { foreach (var settingValue in await GetAllSettingValuesForUserAsync(SmdSession.UserId.Value)) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.User)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } return(settingValues.Values.ToImmutableList()); }
public async Task <IReadOnlyList <ISettingValue> > GetAllSettingValuesAsync(SettingScopes scopes) { var settingDefinitions = new Dictionary <string, SettingDefinition>(); var settingValues = new Dictionary <string, ISettingValue>(); //用默认值填充所有设置。 foreach (var setting in _settingDefinitionManager.GetAllSettingDefinitions()) { settingDefinitions[setting.Name] = setting; settingValues[setting.Name] = new SettingValueObject(setting.Name, setting.DefaultValue); } //覆盖应用程序设置 if (scopes.HasFlag(SettingScopes.Application)) { foreach (var settingValue in await GetAllSettingValuesForApplicationAsync()) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); //TODO: 条件变得复杂,试着简化它 if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Application)) { continue; } if (!setting.IsInherited && setting.Scopes.HasFlag(SettingScopes.User) && !string.IsNullOrWhiteSpace(SharePlatformSession.UserId)) { continue; } settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } //覆盖用户设置 if (scopes.HasFlag(SettingScopes.User) && !string.IsNullOrWhiteSpace(SharePlatformSession.UserId)) { foreach (var settingValue in await GetAllSettingValuesForUserAsync(SharePlatformSession.ToUserIdentifier())) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.User)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } return(settingValues.Values.ToImmutableList()); }
/// <inheritdoc/> public async Task<IReadOnlyList<ISettingValue>> GetAllSettingValuesAsync(SettingScopes scopes) { var settingDefinitions = new Dictionary<string, SettingDefinition>(); var settingValues = new Dictionary<string, ISettingValue>(); //Fill all setting with default values. foreach (var setting in _settingDefinitionManager.GetAllSettingDefinitions()) { settingDefinitions[setting.Name] = setting; settingValues[setting.Name] = new SettingValueObject(setting.Name, setting.DefaultValue); } //Overwrite application settings if (scopes.HasFlag(SettingScopes.Application)) { foreach (var settingValue in await GetAllSettingValuesForApplicationAsync()) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); //TODO: Conditions get complicated, try to simplify it if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Application)) { continue; } if (!setting.IsInherited && (setting.Scopes.HasFlag(SettingScopes.User) && AbpSession.UserId.HasValue)) { continue; } settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } //Overwrite user settings if (scopes.HasFlag(SettingScopes.User) && AbpSession.UserId.HasValue) { foreach (var settingValue in await GetAllSettingValuesForUserAsync(AbpSession.UserId.Value)) { var setting = settingDefinitions.GetOrDefault(settingValue.Name); if (setting != null && setting.Scopes.HasFlag(SettingScopes.User)) { settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value); } } } return settingValues.Values.ToImmutableList(); }