Exemplo n.º 1
0
        private WebAppSettingStore GetWriteSettingStore()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                GetSettingStore();

                if (_settingStore == null) // setting store not yet created
                {
                    rrLock.EnterWriteLock();

                    try
                    {
                        _settingStore = WebAppSettingStore.Create(this.webApplication);
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }
                return _settingStore;
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 2
0
        private WebAppSettingStore GetSettingStore()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                if (_settingStore == null || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                {
                    //Need to exist so don't deadlock.

                    rrLock.EnterWriteLock();
                    try
                    {
                        //make sure first another thread didn't already load...
                        if (_settingStore == null || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                        {
                            _settingStore = WebAppSettingStore.Load(this.webApplication);
                            lastLoad      = DateTime.Now;
                        }
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }

                return(_settingStore);
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        private WebAppSettingStore GetWriteSettingStore()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                GetSettingStore();

                if (_settingStore == null) // setting store not yet created
                {
                    rrLock.EnterWriteLock();

                    try
                    {
                        _settingStore = WebAppSettingStore.Create(this.webApplication);
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }
                return(_settingStore);
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 5
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();
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Forces the property bag to reload settings on next access.
        /// </summary>
        public void Reset()
        {
            rrLock.EnterWriteLock();

            try
            {
                _settingStore = null;
            }
            finally
            {
                rrLock.ExitWriteLock();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Forces the property bag to reload settings on next access.
        /// </summary>
        public void Reset()
        {
            rrLock.EnterWriteLock();

            try
            {
                _settingStore = null;
            }
            finally
            {
                rrLock.ExitWriteLock();
            }
        }
Exemplo n.º 8
0
 /// <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);
     }
 }
Exemplo n.º 9
0
        public bool Contains(string key)
        {
            WebAppSettingStore store = GetSettingStore();

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

            rrLock.EnterReadLock();

            try
            {
                return(store.Settings.ContainsKey(key));
            }
            finally
            {
                rrLock.ExitReadLock();
            }
        }
Exemplo n.º 10
0
        private WebAppSettingStore GetSettingStore()
        {
            rrLock.EnterUpgradeableReadLock();

            try
            {
                if (_settingStore == null || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                {
                    //Need to exist so don't deadlock.

                    rrLock.EnterWriteLock();
                    try
                    {
                        //make sure first another thread didn't already load...
                        if (_settingStore == null || (DateTime.Now.Subtract(lastLoad).TotalSeconds) > cacheInterval)
                        {
                            _settingStore = WebAppSettingStore.Load(this.webApplication);
                            lastLoad = DateTime.Now;
                        }
                    }
                    finally
                    {
                        rrLock.ExitWriteLock();
                    }
                }

                return _settingStore;
            }
            finally
            {
                rrLock.ExitUpgradeableReadLock();
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// For internal use, clears the cached setting store data
 /// </summary>
 public static void ClearCache()
 {
     _settingStore = null;
 }
Exemplo n.º 12
0
 /// <summary>
 /// For internal use, clears the cached setting store data
 /// </summary>
 public static void ClearCache()
 {
     _settingStore = null;
 }
Exemplo n.º 13
0
 /// <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;
     }
 }