public void StructuredProperties() { StringBuilder sb = new StringBuilder(); sb.AppendLine("test.me = pass"); sb.AppendLine("test.two = ed"); sb.AppendLine("stress.it.to.the.max = 200"); sb.AppendLine("stress.it.again = 23d"); ConfigSource source = new ConfigSource(); source.LoadProperties(GetStream(sb)); Assert.AreEqual(2, source.GetChild("test").Keys.Length); Assert.AreEqual("ed", source.GetChild("test").GetString("two")); }
public void Configure(ConfigSource config) { consumerRequests = config.GetBoolean("consumerRequests"); ConfigSource child = config.GetChild("accessVerifier"); if (child != null) { string typeString = child.GetString("type"); if (String.IsNullOrEmpty(typeString)) throw new ConfigurationException("The 'accessVerifier' type was not specified.", child, "type"); Type type = Type.GetType(typeString, false, true); if (type == null) throw new ConfigurationException("The type '" + typeString + "' could not be found.", child, "type"); if (!typeof (IPathAccessVerifier).IsAssignableFrom(type)) throw new ConfigurationException( "The type '" + type + "' cannot be is not an implementation of '" + typeof (IPathAccessVerifier) + "'.", child, "type"); try { accessVerifier = (IPathAccessVerifier) Activator.CreateInstance(type); accessVerifier.Context = OAuthProvider.Current; accessVerifier.Configure(child); } catch (ConfigurationException) { throw; } catch (Exception e) { throw new ConfigurationException("Error while initializing the type '" + type + "': " + e.Message, e); } } }
public void LoadProperties() { StringBuilder sb = new StringBuilder(); sb.AppendLine("test=23"); sb.AppendLine("test.foo=12"); sb.AppendLine("test.bar=test"); Stream input = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())); ConfigSource config = new ConfigSource(); config.LoadProperties(input); Assert.AreEqual(1, config.Keys.Length); Assert.AreEqual("test", config.Keys[0]); Assert.AreEqual(2, config.GetChild("test").Keys.Length); Assert.AreEqual("foo", config.GetChild("test").Keys[0]); Assert.AreEqual("bar", config.GetChild("test").Keys[1]); Assert.AreEqual(12, config.GetChild("test").GetInt32("foo")); Assert.AreEqual("test", config.GetChild("test").GetString("bar")); }
protected virtual void Configure(ConfigSource config) { tokenStore = (ITokenStore)ConfigureComponent(config.GetChild("tokenStore"), typeof(ITokenStore), typeof(HeapTokenStore)); callbackStore = (ICallbackStore)ConfigureComponent(config.GetChild("callbackStore"), typeof(ICallbackStore), typeof(HeapCallbackStore)); consumerStore = (IConsumerStore)ConfigureComponent(config.GetChild("consumerStore"), typeof(IConsumerStore), typeof(HeapConsumerStore)); requestIdValidator = (IRequestIdValidator)ConfigureComponent(config.GetChild("requestIdValidator"), typeof(IRequestIdValidator), typeof(HeapRequestIdValidator)); resourceAccessVerifier = (IResourceAccessVerifier)ConfigureComponent(config.GetChild("resourceAccessVerifier"), typeof(IResourceAccessVerifier), null); tokenGenerator = (ITokenGenerator)ConfigureComponent(config.GetChild("tokenGenerator"), typeof(ITokenGenerator), typeof(GuidTokenGenerator)); verificationProvider = (IVerificationProvider)ConfigureComponent(config.GetChild("verificationProvider"), typeof(IVerificationProvider), typeof(MD5HashVerificationProvider)); allowOutOfBandCallback = config.GetBoolean("oobCallback"); }
public static void Init(ConfigSource config) { lock (logSyncLock) { InspectLoggers(); ConfigSource loggerConfig = config; // if it is a root configuration, get the 'logger' child if (loggerConfig.Parent == null) { loggerConfig = config.GetChild("logger"); } // if we haven't found any 'logger' or if the element has no // children, simply return and get empty loggers ... if (loggerConfig == null) { return; } // this means there's just one logger and its children are config... if (loggerConfig.ChildCount == 0) { DoInit(String.Empty, loggerConfig, null); } else { List <ILogger> composites = new List <ILogger>(); foreach (ConfigSource child in loggerConfig.Children) { DoInit(child.Name, child, composites); } // let's late process the composite loggers found if (composites.Count > 0) { for (int i = 0; i < composites.Count; i++) { composites[i].Init(config); } } } initid = true; } }
public void Configure(ConfigSource config) { consumerRequests = config.GetBoolean("consumerRequests"); ConfigSource child = config.GetChild("accessVerifier"); if (child != null) { string typeString = child.GetString("type"); if (String.IsNullOrEmpty(typeString)) { throw new ConfigurationException("The 'accessVerifier' type was not specified.", child, "type"); } Type type = Type.GetType(typeString, false, true); if (type == null) { throw new ConfigurationException("The type '" + typeString + "' could not be found.", child, "type"); } if (!typeof(IPathAccessVerifier).IsAssignableFrom(type)) { throw new ConfigurationException( "The type '" + type + "' cannot be is not an implementation of '" + typeof(IPathAccessVerifier) + "'.", child, "type"); } try { accessVerifier = (IPathAccessVerifier)Activator.CreateInstance(type); accessVerifier.Context = OAuthProvider.Current; accessVerifier.Configure(child); } catch (ConfigurationException) { throw; } catch (Exception e) { throw new ConfigurationException("Error while initializing the type '" + type + "': " + e.Message, e); } } }
public static void Init(ConfigSource config) { lock(logSyncLock) { InspectLoggers(); ConfigSource loggerConfig = config; // if it is a root configuration, get the 'logger' child if (loggerConfig.Parent == null) loggerConfig = config.GetChild("logger"); // if we haven't found any 'logger' or if the element has no // children, simply return and get empty loggers ... if (loggerConfig == null) return; // this means there's just one logger and its children are config... if (loggerConfig.ChildCount == 0) { DoInit(String.Empty, loggerConfig, null); } else { List<ILogger> composites = new List<ILogger>(); foreach (ConfigSource child in loggerConfig.Children) { DoInit(child.Name, child, composites); } // let's late process the composite loggers found if (composites.Count > 0) { for (int i = 0; i < composites.Count; i++) { composites[i].Init(config); } } } initid = true; } }