Beispiel #1
0
 /// <summary>
 /// Saves the value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void SaveValue(T value)
 {
     using (CacheLock.WriteLock())
     {
         Cache[Name] = value;
         string rawValue = SettingValueConverter.ConvertToString(value);
         _settingProvider.SaveValue(Name, rawValue);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Loads the value.
        /// </summary>
        private T LoadValue()
        {
            T    value           = _defaultValue;
            bool loadedFromCache = false;

            using (CacheLock.ReadLock())
            {
                if (Cache.ContainsKey(Name))
                {
                    value           = Cache[Name];
                    loadedFromCache = true;
                }
            }

            if (!loadedFromCache)
            {
                using (CacheLock.WriteLock())
                {
                    if (!Cache.ContainsKey(Name))
                    {
                        string rawValue = null;
                        if (_settingProvider.GetValue(Name, ref rawValue))
                        {
                            value = SettingValueConverter.ConvertToValue <T>(rawValue);
                        }
                        else
                        {
                            Cache[Name] = _defaultValue;
                        }
                    }
                    else
                    {
                        value = Cache[Name];
                    }
                }
            }

            return(value);
        }