예제 #1
0
        private Dictionary <string, SettingInfo> ConvertSettingInfosToDictionary(List <SettingInfo> settingValues)
        {
            var dictionary = new Dictionary <string, SettingInfo>();

            foreach (var settingValue in settingValues)
            {
                var settingDefinition = _settingDefinitionManager.GetSettingDefinition(settingValue.Name);
                if (settingDefinition.IsEncrypted)
                {
                    settingValue.Value = SettingEncryptionService.Decrypt(settingDefinition, settingValue.Value);
                }

                dictionary[settingValue.Name] = settingValue;
            }

            return(dictionary);
        }
예제 #2
0
        private Dictionary <string, SettingInfo> ConvertSettingInfosToDictionary(List <SettingInfo> settingValues)
        {
            var dictionary            = new Dictionary <string, SettingInfo>();
            var allSettingDefinitions = _settingDefinitionManager.GetAllSettingDefinitions();

            foreach (var setting in allSettingDefinitions.Join(settingValues,
                                                               definition => definition.Name,
                                                               value => value.Name,
                                                               (definition, value) => new
            {
                SettingDefinition = definition,
                SettingValue = value
            }))
            {
                if (setting.SettingDefinition.IsEncrypted)
                {
                    setting.SettingValue.Value = SettingEncryptionService.Decrypt(setting.SettingDefinition, setting.SettingValue.Value);
                }

                dictionary[setting.SettingValue.Name] = setting.SettingValue;
            }

            return(dictionary);
        }
예제 #3
0
        private SettingInfo InsertOrUpdateOrDeleteSettingValue(string name, string value, int?tenantId, long?userId)
        {
            var settingDefinition = _settingDefinitionManager.GetSettingDefinition(name);
            var settingValue      = SettingStore.GetSettingOrNull(tenantId, userId, name);

            //Determine defaultValue
            var defaultValue = settingDefinition.DefaultValue;

            if (settingDefinition.IsInherited)
            {
                //For Tenant and User, Application's value overrides Setting Definition's default value when multi tenancy is enabled.
                if (_multiTenancyConfig.IsEnabled && (tenantId.HasValue || userId.HasValue))
                {
                    var applicationValue = GetSettingValueForApplicationOrNull(name);
                    if (applicationValue != null)
                    {
                        defaultValue = applicationValue.Value;
                    }
                }

                //For User, Tenants's value overrides Application's default value.
                if (userId.HasValue && tenantId.HasValue)
                {
                    var tenantValue = GetSettingValueForTenantOrNull(tenantId.Value, name);
                    if (tenantValue != null)
                    {
                        defaultValue = tenantValue.Value;
                    }
                }
            }

            //No need to store on database if the value is the default value
            if (value == defaultValue)
            {
                if (settingValue != null)
                {
                    SettingStore.Delete(settingValue);
                }

                return(null);
            }

            //If it's not default value and not stored on database, then insert it
            if (settingValue == null)
            {
                settingValue = new SettingInfo
                {
                    TenantId = tenantId,
                    UserId   = userId,
                    Name     = name,
                    Value    = value
                };

                if (settingDefinition.IsEncrypted)
                {
                    settingValue.Value = SettingEncryptionService.Encrypt(settingDefinition, value);
                }

                SettingStore.Create(settingValue);
                return(settingValue);
            }

            var rawSettingValue = settingDefinition.IsEncrypted ? SettingEncryptionService.Decrypt(settingDefinition, settingValue.Value) : settingValue.Value;

            if (rawSettingValue == value)
            {
                return(settingValue);
            }

            //Update the setting on database.
            settingValue.Value = settingDefinition.IsEncrypted ? SettingEncryptionService.Encrypt(settingDefinition, value) : value;
            SettingStore.Update(settingValue);

            return(settingValue);
        }