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(); } }
/// <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(); } } }