private BIPropertyBag GetPropertyBag(ConfigLevel level) { var propBag = new BIPropertyBag(); propBag.Values.Count = 0; propBag.Level = level; return propBag; }
/// <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; }
public TValue GetByKey <TValue>(string key, ConfigLevel level) { Validation.ArgumentNotNull(key, "key"); string serializedSetting = this.GetSettingFrom(ConfigManager.GetNamespacedKey(key), level); return(DeserializeSetting <TValue>(key, serializedSetting)); }
/// <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 void GetIndexerSucceeds() { //Arrange string assemblyName = null; string typeName = null; string key = TestsConstants.TestGuidName; string resultKey = null; ConfigLevel resultLevel = ConfigLevel.CurrentSPWeb; string targetValue = "foobar"; MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (assembly, type, args) => { assemblyName = assembly; typeName = type; var proxyArgs = args as ProxyArgs.ReadConfigArgs; resultKey = proxyArgs.Key; resultLevel = (ConfigLevel)proxyArgs.Level; return(targetValue); }; var target = new SandboxWebAppPropertyBag(TestsConstants.TestGuid); //Act string result = target[key]; //Assert Assert.AreEqual <string>(assemblyName, ProxyArgs.ReadConfigArgs.OperationAssemblyName); Assert.AreEqual <string>(typeName, ProxyArgs.ReadConfigArgs.OperationTypeName); Assert.AreEqual(key, resultKey); Assert.AreEqual(ConfigLevel.CurrentSPWebApplication, resultLevel); Assert.AreEqual(targetValue, result); }
/// <summary> /// Sets a setting /// </summary> /// <param name="key">The name (ID) of the setting</param> /// <param name="o">The object to save</param> /// <param name="level">The configuration level</param> protected void Set(string key, object o, ConfigLevel level = ConfigLevel.User) { object old; switch (level) { case ConfigLevel.Application: old = appconfig.ContainsKey(key) ? appconfig[key] : null; appconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; case ConfigLevel.User: old = userconfig.ContainsKey(key) ? userconfig[key] : null; userconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; case ConfigLevel.Instance: old = instconfig.ContainsKey(key) ? instconfig[key] : null; instconfig[key] = o; if (!SuppressConfigChanged && ConfigChanged != null) { ConfigChanged(this, new ConfigChangedEventArgs(key, level, o, old)); } break; } }
internal static void ThrowSandboxConfigurationException(Exception exception, ConfigLevel configLevel) { var ex = new ConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.UnexpectedExceptionFromSandbox, configLevel.ToString()), exception); throw ex; }
public void ContainsSucceeds() { //Arrange string assemblyName = null; string typeName = null; string key = TestsConstants.TestGuidName; string resultKey = null; ConfigLevel resultLevel = ConfigLevel.CurrentSPWeb; MSPUtility.ExecuteRegisteredProxyOperationStringStringSPProxyOperationArgs = (assembly, type, args) => { assemblyName = assembly; typeName = type; var proxyArgs = args as ProxyArgs.ContainsKeyDataArgs; resultKey = proxyArgs.Key; resultLevel = (ConfigLevel)proxyArgs.Level; return(true); }; var target = new SandboxWebAppPropertyBag(TestsConstants.TestGuid); //Act bool result = target.Contains(key); //Assert Assert.AreEqual <string>(assemblyName, ProxyArgs.ContainsKeyDataArgs.OperationAssemblyName); Assert.AreEqual <string>(typeName, ProxyArgs.ContainsKeyDataArgs.OperationTypeName); Assert.AreEqual(key, resultKey); Assert.AreEqual(ConfigLevel.CurrentSPWebApplication, resultLevel); Assert.IsTrue(result); }
/// <summary> /// Constructs a property bag backed by a list using the site url to access the list. /// </summary> /// <param name="siteUrl">The site url where the configuration list is located</param> /// <param name="contextId">The unique ID for this context</param> /// <param name="level">The level of the list based property bag</param> public ListBackedUrlPropertyBag(string siteUrl, string contextId, ConfigLevel level) { this.level = level; this.contextId = contextId; this.siteUrl = siteUrl; buildKeyFunc = (key) => key; //by default just return key. }
/// <summary> /// Creates a new object /// </summary> /// <param name="k"></param> /// <param name="l"></param> /// <param name="newValue"></param> /// <param name="oldValue"></param> public ConfigChangedEventArgs(string k, ConfigLevel l, object newValue, object oldValue) { Key = k; Level = l; NewValue = newValue; OldValue = oldValue; }
/// <summary> /// Gets a setting /// </summary> /// <typeparam name="T">Type of the read object (the object will be casted to this type)</typeparam> /// <param name="key">The name (ID) of the setting</param> /// <param name="level">The configuration level</param> /// <returns></returns> protected T Get <T>(string key, ConfigLevel level = ConfigLevel.User) { switch (level) { case ConfigLevel.Application: if (appconfig.ContainsKey(key)) { return((T)appconfig[key]); } return(default(T)); case ConfigLevel.User: if (userconfig.ContainsKey(key)) { return((T)userconfig[key]); } return(default(T)); case ConfigLevel.Instance: default: if (instconfig.ContainsKey(key)) { return((T)instconfig[key]); } return(default(T)); } }
/// <summary> /// Constructs a list based property bag backed by a list using the site url to access the list. /// </summary> /// <param name="siteUrl">The site url where the configuration list is located</param> /// <param name="contextId">The unique ID for this context</param> /// <param name="level">The level of the list based property bag</param> /// <param name="buildKeyFunc">the function to use for transforming the key value used for storage</param> public ListBackedUrlPropertyBag(string siteUrl, string contextId, ConfigLevel level, Func <string, string> buildKeyFunc) { this.level = level; this.contextId = contextId; this.siteUrl = siteUrl; this.buildKeyFunc = buildKeyFunc; }
IPropertyBag GetPropertyBagLevelImpl(ConfigLevel level) { BIPropertyBag bag = new BIPropertyBag(); bag.Level = level; bag.Values.Count = 0; return(bag); }
public bool ContainsKey(string key, ConfigLevel level) { if (level == ConfigLevel.CurrentSPFarm) { return(ContainsReturnValue); } throw new NotImplementedException(); }
public BIPropertyBag(ConfigLevel configLevel) { this.values = new BehavedDictionary <string, string>(this, "Values"); this.level = new BehavedValue <ConfigLevel>(this, "Level"); this.Level = configLevel; InitializeStubs(); }
public TValue GetByKey <TValue>(string key, ConfigLevel level) { if (level == ConfigLevel.CurrentSPFarm) { return((TValue)(Object)GetBykeyReturnValue); } throw new NotImplementedException(); }
public object GetFromPropertyBag(Type type, string key, ConfigLevel level) { Validation.ArgumentNotNull(type, "type"); Validation.ArgumentNotNull(key, "key"); var propertyBag = GetPropertyBag(level); return(GetProperty(type, key, propertyBag)); }
/// <summary> /// Gets the property bag for the level specified. /// </summary> /// <param name="level">The level to get the property bag for</param> /// <returns>the property bag for the level, null if the bag is not available</returns> public IPropertyBag GetPropertyBagForLevel(ConfigLevel level) { foreach (IPropertyBag bag in bags) { if (bag.Level == level) return bag; } return null; }
public IPropertyBag GetPropertyBag(ConfigLevel level) { IPropertyBag bag = GetHierarchy().GetPropertyBagForLevel(level); if (bag == null) { throw new ConfigurationException(string.Format(CultureInfo.CurrentCulture, Resources.PropertyBagNotValidForContext, level)); } return(bag); }
public void GetLevelSucceeds() { //Arrange var target = new SandboxFarmPropertyBag(); //Act ConfigLevel level = target.Level; //Assert Assert.AreEqual <ConfigLevel>(ConfigLevel.CurrentSPFarm, level); }
public void GetLevelSucceeds() { //Arrange var target = new SandboxWebAppPropertyBag(TestsConstants.TestGuid); //Act ConfigLevel level = target.Level; //Assert Assert.AreEqual <ConfigLevel>(ConfigLevel.CurrentSPWebApplication, level); }
/// <summary> /// Gets the property bag for the level specified. /// </summary> /// <param name="level">The level to get the property bag for</param> /// <returns>the property bag for the level, null if the bag is not available</returns> public IPropertyBag GetPropertyBagForLevel(ConfigLevel level) { foreach (IPropertyBag bag in bags) { if (bag.Level == level) { return(bag); } } return(null); }
public bool ContainsKey(string key, ConfigLevel level) { if (level != ConfigLevel.CurrentSPFarm) { throw new InvalidOperationException(); } if (key == Constants.AreasConfigKey) { return(true); } return(false); }
public IPropertyBag GetPropertyBagForLevel(ConfigLevel level) { int i = 0; while (i < Bags.Count && Bags[i].Level != level) { i++; } if (i == Bags.Count) { return(null); } return(Bags[i]); }
protected bool ContainsFrom(string key, ConfigLevel level) { Validation.ArgumentNotNull(key, "key"); bool contains = false; IPropertyBagHierarchy hierarchy = GetHierarchy(); foreach (IPropertyBag bag in hierarchy.PropertyBags) { //property bags are ordered by level in the hierarchy if (bag.Level >= level) { contains = bag.Contains(key); if (contains) { break; } } } return(contains); }
protected string GetSettingFrom(string key, ConfigLevel level) { Validation.ArgumentNotNull(key, "key"); string value = null; IPropertyBagHierarchy hierarchy = GetHierarchy(); foreach (IPropertyBag bag in hierarchy.PropertyBags) { //property bags are ordered by level in the hierarchy if (bag.Level >= level) { value = bag[key]; if (value != null) { break; } } } return(value); }
private IPropertyBag GetIPropertyBag(ConfigLevel level) { switch (level) { case ConfigLevel.CurrentSPFarm: return(new SPFarmPropertyBag()); case ConfigLevel.CurrentSPWebApplication: return(new SPWebAppPropertyBag()); case ConfigLevel.CurrentSPSite: return(new SPSitePropertyBag()); case ConfigLevel.CurrentSPWeb: return(new SPWebPropertyBag()); default: throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, "The config level '{0}' was not supported. Use Farm, WebApplication, Site or Web.", level), "level"); } }
/// <summary> /// Adds a value to a multi-valued variable in the given section and optional subsection. /// </summary> /// <param name="config">The configuration section to operate on.</param> /// <param name="variable">The variable to assign.</param> /// <param name="value">Value add to the variable.</param> /// <param name="level">The configuration level to operate on.</param> public static ConfigSection AddBoolean(this ConfigSection config, string variable, bool value, ConfigLevel level) => config with
/// <summary> /// Implements the operation for determining if a key exists in a web application /// </summary> /// <param name="args">The arguments for the contains key operation. This must be an instance of ContainsKeyDataArgs.</param> /// <returns>true if the key found, false if the key is not found, or an exception representing an error if an error occurred</returns> public override object Execute(SPProxyOperationArgs args) { if (args == null) { throw new ArgumentNullException("args"); } var containsKeyArgs = args as ContainsKeyDataArgs; if (containsKeyArgs == null) { string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidProxyArgumentType, typeof(ContainsKeyDataArgs).FullName, args.GetType().FullName); var ex = new ConfigurationException(message); return(ex); } else if (containsKeyArgs.Key == null) { return(new ArgumentNullException("ContainsKeyDataArgs.Key")); } try { ConfigLevel level = (ConfigLevel)containsKeyArgs.Level; if (containsKeyArgs.Key.StartsWith(ConfigManager.PnPKeyNamespace) == false) { string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidKeyName, containsKeyArgs.Key); ConfigurationException ex = new ConfigurationException(message); return(ex); } else { bool contains = false; if (level == ConfigLevel.CurrentSPWebApplication) { if (containsKeyArgs.SiteId == Guid.Empty) { return(new ConfigurationException(Resources.EmptySiteGuid)); } using (SPSite site = new SPSite(containsKeyArgs.SiteId)) { SPWebAppPropertyBag bag = new SPWebAppPropertyBag(site.WebApplication); contains = bag.Contains(containsKeyArgs.Key); } } else if (level == ConfigLevel.CurrentSPFarm) { var bag = new SPFarmPropertyBag(SPFarm.Local); contains = bag.Contains(containsKeyArgs.Key); } else { string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidConfigLevel, level.ToString()); ConfigurationException ex = new ConfigurationException(message); return(ex); } return(contains); } } catch (Exception excpt) { return(excpt); } }
public TValue GetByKey <TValue>(string key, ConfigLevel level) { return((TValue)(object)"http://localhost"); }
public bool ContainsKey(string key, ConfigLevel level) { throw new NotImplementedException(); }
/// <summary> /// Constructs a list based property bag backed by a list using the site url to access the list. /// </summary> /// <param name="siteUrl">The site url where the configuration list is located</param> /// <param name="contextId">The unique ID for this context</param> /// <param name="level">The level of the list based property bag</param> /// <param name="buildKeyFunc">the function to use for transforming the key value used for storage</param> public ListBackedUrlPropertyBag(string siteUrl, string contextId, ConfigLevel level, Func<string, string> buildKeyFunc) { this.level = level; this.contextId = contextId; this.siteUrl = siteUrl; this.buildKeyFunc = buildKeyFunc; }