/// <summary>
 /// Saves the settings in the db
 /// </summary>
 /// <param name="config"></param>
 public void SaveSetting(SettingConfigurationElement element)
 {
     string elementName = null;
     if (element is GeneralElement)
     {
         elementName = "general";
     }
     else if (element is UIElement)
     {
         elementName = "ui";
     }
     else if (element is SpamPreventionElement)
     {
         elementName = "spamPrevention";
     }
     else if (element is SearchElement)
     {
         elementName = "search";
     }
     else
     {
         throw new NotSupportedException("Element of type " + element.GetType().Name + " is not supported.");
     }
     element.ValidateFields();
     SaveElement(element, elementName);
 }
示例#2
0
        /// <summary>
        /// Saves current settings.
        /// </summary>
        /// <exception cref="ValidationException"></exception>
        public virtual void SaveSetting(SettingConfigurationElement element)
        {
            if (!UseSettings)
            {
                throw new ConfigurationErrorsException("Saving settings is not possible when is not enabled by configuration (useSettings)");
            }
            if (_settingsRepository == null)
            {
                throw new NullReferenceException("settings repository can not be null");
            }
            _settingsRepository.SaveSetting(element);

            if (element is GeneralElement)
            {
                General = (GeneralElement) element;
            }
            else if (element is UIElement)
            {
                UI = (UIElement)element;
            }
            else if (element is SpamPreventionElement)
            {
                SpamPrevention = (SpamPreventionElement)element;
            }
            else if (element is SearchElement)
            {
                Search = (SearchElement)element;
            }
            else
            {
                throw new NotSupportedException("Element of type " + element.GetType().Name + " is not supported.");
            }
        }
 /// <summary>
 /// Serializes an element and stores into the database
 /// </summary>
 /// <param name="element"></param>
 /// <param name="elementName"></param>
 /// <exception cref="ValidationException"></exception>
 protected virtual void SaveElement(SettingConfigurationElement element, string elementName)
 {
     var builder = new StringBuilder();
     element.Serialize(builder, elementName);
     SaveToDb(builder, elementName);
 }
 protected virtual void LoadElement(SettingConfigurationElement element, string elementName)
 {
     var serializedValue = GetFromDb(elementName);
     if (serializedValue != null && serializedValue.Length > 0)
     {
         element.Deserialize(serializedValue);
     }
 }