Exemplo n.º 1
0
        public virtual async Task <List <SettingValue> > GetAllAsync(string[] names)
        {
            var result             = new Dictionary <string, SettingValue>();
            var settingDefinitions = SettingDefinitionManager.GetAll().Where(x => names.Contains(x.Name)).ToList();

            foreach (var definition in settingDefinitions)
            {
                result.Add(definition.Name, new SettingValue(definition.Name, null));
            }

            foreach (var provider in Enumerable.Reverse(SettingValueProviderManager.Providers))
            {
                var settingValues = await provider.GetAllAsync(settingDefinitions.Where(x => !x.Providers.Any() || x.Providers.Contains(provider.Name)).ToArray());

                var notNullValues = settingValues.Where(x => x.Value != null).ToList();
                foreach (var settingValue in notNullValues)
                {
                    var settingDefinition = settingDefinitions.First(x => x.Name == settingValue.Name);
                    if (settingDefinition.IsEncrypted)
                    {
                        settingValue.Value = SettingEncryptionService.Decrypt(settingDefinition, settingValue.Value);
                    }

                    if (result.ContainsKey(settingValue.Name) && result[settingValue.Name].Value == null)
                    {
                        result[settingValue.Name].Value = settingValue.Value;
                    }
                }

                settingDefinitions.RemoveAll(x => notNullValues.Any(v => v.Name == x.Name));
            }

            return(result.Values.ToList());
        }
Exemplo n.º 2
0
        public virtual async Task <string> GetOrNullAsync(string name)
        {
            var setting   = SettingDefinitionManager.Get(name);
            var providers = Enumerable
                            .Reverse(SettingValueProviderManager.Providers);

            if (setting.Providers.Any())
            {
                providers = providers.Where(p => setting.Providers.Contains(p.Name));
            }

            //TODO: How to implement setting.IsInherited?

            var value = await GetOrNullValueFromProvidersAsync(providers, setting);

            if (value != null && setting.IsEncrypted)
            {
                value = SettingEncryptionService.Decrypt(setting, value);
            }

            return(value);
        }