示例#1
0
 /// <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>
        /// 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);
                    }
                }
            }
        }
示例#3
0
 /// <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.
 }
 public bool Contains(string key)
 {
     using (var site = CreateSite())
     {
         var list = new ConfigurationList(site);
         return(list.ContainsKey(buildKeyFunc(key), this.contextId));
     }
 }
        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);
                }
            }
        }
        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);
                }
            }
        }
        /// <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);
                     }

                }
            }
        }
 public bool Contains(string key)
 {
     using (var site = CreateSite())
     {
         var list = new ConfigurationList(site);
         return list.ContainsKey(buildKeyFunc(key), this.contextId);
     }
 }