Exemple #1
0
        public void Remove(string key)
        {
            var logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>();

            rrLock.EnterWriteLock();

            try
            {
                //intentionally nested, both cases getting a write lock, is safe and ensures no race.
                //Force the reload of the persisted object, which minimizes chances of a failure due
                // to a concurrency failure.

                Reset();
                WebAppSettingStore store = GetWriteSettingStore();

                if (store.Settings.ContainsKey(key))
                {
                    store.Settings.Remove(key);
                    store.Update();
                }
            }
            catch (SPUpdatedConcurrencyException)
            {
                Reset();
                throw;
            }
            finally
            {
                rrLock.ExitWriteLock();
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets or sets a value based on the key. If the value is not defined in this PropertyBag, it will look in it's
        /// parent property bag.
        /// </summary>
        /// <value></value>
        /// <returns>The config value defined in the property bag. </returns>
        public string this[string key]
        {
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                WebAppSettingStore store = GetSettingStore();

                if (store == null)      //store doesn't exist, so setting doesn't exist...
                {
                    return(null);
                }

                rrLock.EnterReadLock();

                try
                {
                    if (!store.Settings.ContainsKey(key))
                    {
                        return(null);
                    }

                    return(store.Settings[key]);
                }
                finally
                {
                    rrLock.ExitReadLock();
                }
            }
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            set
            {
                rrLock.EnterWriteLock();

                try
                {
                    //intentionally nested, Reset is also getting a write lock, is safe and ensures no race.
                    //Force the reload of the persisted object, which minimizes chances of a failure due
                    // to a concurrency failure.
                    Reset();
                    WebAppSettingStore store = GetWriteSettingStore();

                    store.Settings[key] = value;
                    store.Update();
                }
                catch (SPUpdatedConcurrencyException)
                {
                    Reset();

                    throw;
                }
                finally
                {
                    rrLock.ExitWriteLock();
                }
            }
        }
 /// <summary>
 /// Creates the setting store for a web application
 /// </summary>
 /// <param name="webApp">The parent web app to store the settings</param>
 /// <returns>The web app setting store instance</returns>
 public static WebAppSettingStore Create(SPWebApplication webApp)
 {
     lock (createlock)
     {
         //load to make sure it wasn't already created in a race...
         var settingStore = webApp.GetChild <WebAppSettingStore>(WebAppSettingStore.StoreName);
         if (settingStore == null)
         {
             settingStore = new WebAppSettingStore(WebAppSettingStore.StoreName, webApp);
             settingStore.Update();
         }
         return(settingStore);
     }
 }
 /// <summary>
 /// Creates the setting store for a web application
 /// </summary>
 /// <param name="webApp">The parent web app to store the settings</param>
 /// <returns>The web app setting store instance</returns>
 public static WebAppSettingStore Create(SPWebApplication webApp)
 {
     lock (createlock)
     {
         //load to make sure it wasn't already created in a race...
         var settingStore = webApp.GetChild<WebAppSettingStore>(WebAppSettingStore.StoreName);
         if (settingStore == null)
         {
             settingStore = new WebAppSettingStore(WebAppSettingStore.StoreName, webApp);
             settingStore.Update();
         }
         return settingStore;
     }
 }