Esempio n. 1
0
        /// <summary>
        /// Indexer for getting and setting values for the key specified.
        /// </summary>
        /// <param name="key">The key to check for in the property bag</param>
        /// <returns>The value for the key, null if not found</returns>

        public string this[string key]
        {
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                using (var site = CreateSite())
                {
                    var list = new ConfigurationList(site);
                    return(list.Get(buildKeyFunc(key), this.contextId));
                }
            }
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            set
            {
                if (value == null)
                {
                    Remove(key);
                }
                else
                {
                    using (var site = CreateSite())
                    {
                        // AllowUnsafeUpdates required since the list may be located outside of
                        // the current web/site.
                        site.RootWeb.AllowUnsafeUpdates = true;
                        var list = new ConfigurationList(site);
                        list.Save(buildKeyFunc(key), value, this.contextId);
                        site.RootWeb.AllowUnsafeUpdates = false;
                    }
                }
            }
        }
 /// <summary>
 /// Constructs a list backed property bag with a function for transforming the key.
 /// </summary>
 /// <param name="configListSite">The site to use for retrieving the configuration list</param>
 /// <param name="contextId">The context Id for this property bag, for example, web.ID</param>
 /// <param name="level">The level for this property bag</param>
 /// <param name="buildKeyFunc">The function to use to transform the key to use to actually store</param>
 public ListBackedPropertyBag(SPSite configListSite, string contextId, ConfigLevel level, Func <string, string> buildKeyFunc)
 {
     this.level        = level;
     this.contextId    = contextId;
     this.configList   = new ConfigurationList(configListSite);
     this.buildKeyFunc = buildKeyFunc;
 }
 /// <summary>
 /// Constructs a list backed property bag.
 /// </summary>
 /// <param name="configListSite">The site to use for retrieving the configuration list</param>
 /// <param name="contextId">The context Id for this property bag, for example, web.ID</param>
 /// <param name="level">The level for this property bag</param>
 public ListBackedPropertyBag(SPSite configListSite, string contextId, ConfigLevel level)
 {
     this.level      = level;
     this.contextId  = contextId;
     this.configList = new ConfigurationList(configListSite);
     buildKeyFunc    = (key) => key; //by default just return key.
 }
Esempio n. 4
0
 public bool Contains(string key)
 {
     using (var site = CreateSite())
     {
         var list = new ConfigurationList(site);
         return(list.ContainsKey(buildKeyFunc(key), this.contextId));
     }
 }
Esempio n. 5
0
        public void Remove(string key)
        {
            using (var site = CreateSite())
            {
                site.RootWeb.AllowUnsafeUpdates = true;
                var    list    = new ConfigurationList(site);
                string fullKey = buildKeyFunc(key);

                if (list.ContainsKey(fullKey, this.contextId))
                {
                    list.Remove(fullKey, this.contextId);
                }
                site.RootWeb.AllowUnsafeUpdates = false;
            }
        }