/// <summary> /// Initializes a new instance of the <see cref="AppDomainBootstrap"/> class. /// </summary> public AppDomainBootstrap(IConfigurationSource config) { string startupConfigFile = string.Empty; if (config == null) { throw new ArgumentNullException("config"); } var configSectionSource = config as ConfigurationSection; if (configSectionSource != null) { startupConfigFile = configSectionSource.GetConfigSource(); } //Keep serializable version of configuration if (!config.GetType().IsSerializable) { config = new ConfigurationSource(config); } //Still use raw configuration type to bootstrap m_InnerBootstrap = CreateBootstrapWrap(this, config, startupConfigFile); AppDomain.CurrentDomain.SetData("Bootstrap", this); }
public void AddGetAndRemoveASection() { IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); source.Remove(CreateParameter(), localSection); newSection = source.GetSection(localSection); Assert.AreEqual(null, newSection); }
public void CanCreateConfigurationSourceFromConfigurationElement() { ManageableConfigurationSourceElement element = new ManageableConfigurationSourceElement( "manageable", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, "testapp", true, false); element.ConfigurationManageabilityProviders.Add(new ConfigurationSectionManageabilityProviderData("section1", typeof(MockConfigurationSectionManageabilityProvider))); element.ConfigurationManageabilityProviders.Get(0).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("1", typeof(MockConfigurationElementManageabilityProvider), typeof(String))); element.ConfigurationManageabilityProviders.Add(new ConfigurationSectionManageabilityProviderData("section2", typeof(MockConfigurationSectionManageabilityProvider))); element.ConfigurationManageabilityProviders.Get(1).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("2", typeof(MockConfigurationElementManageabilityProvider), typeof(Boolean))); element.ConfigurationManageabilityProviders.Get(1).ManageabilityProviders.Add(new ConfigurationElementManageabilityProviderData("3", typeof(MockConfigurationElementManageabilityProvider), typeof(Int32))); IConfigurationSource configurationSource = element.InvokeCreateSource(); Assert.IsNotNull(configurationSource); Assert.AreSame(typeof(ManageableConfigurationSource), configurationSource.GetType()); ManageableConfigurationSourceImplementation implementation = ((ManageableConfigurationSource)configurationSource).Implementation; Assert.AreSame(typeof(ManageabilityHelper), implementation.ManageabilityHelper.GetType()); ManageabilityHelper manageabilityHelper = (ManageabilityHelper)implementation.ManageabilityHelper; Assert.AreEqual(2, manageabilityHelper.ManageabilityProviders.Count); }
private T GetValue <T>(IConfigurationSource source, string propName) { var type = source.GetType(); var prop = Reflect.OnProperties.GetPropertyInformation(type, propName); //type.GetProperty(propName); var value = prop.GetValue(source); return((T)value); }
/// <summary> 添加配置 </summary> /// <param name="source"></param> /// <param name="predicate"></param> public void AddProvider(IConfigurationSource source, Func <IConfigurationSource, bool> predicate = null) { predicate = predicate ?? (t => t.GetType() == source.GetType()); var config = Builder.Sources.FirstOrDefault(predicate); if (config != null) { Builder.Sources.Remove(config); } Builder.Sources.Insert(0, source); }
public void GetsNotificationWhenUpdatingAndRemovingSections() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); DummySection dummySection1 = new DummySection(); dummySection1.Value = 10; source.Add(CreateParameter(), localSection, dummySection1); bool sourceChanged = false; SqlConfigurationSource sqlSource = source as SqlConfigurationSource; sqlSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sourceChanged = true; }); ConfigurationSection newSection = source.GetSection(localSection); Assert.AreEqual(typeof(DummySection), newSection.GetType()); DummySection dummySection2 = newSection as DummySection; Assert.AreEqual(dummySection1, dummySection2); //update the section dummySection2.Value = 15; sqlSource.Add(CreateParameter(), localSection, dummySection2); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; //remove the section sqlSource.Remove(CreateParameter(), localSection); Thread.Sleep(500); Assert.IsTrue(sourceChanged); sourceChanged = false; newSection = sqlSource.GetSection(localSection); Assert.AreEqual(null, newSection); }
protected override object Invoke(MethodInfo targetMethod, object[] args) { object result; if ("Add" == targetMethod.Name) { IConfigurationSource src = (IConfigurationSource)args[0]; if (src.GetType() != typeof(ConfigurationSourceProxy)) { args[0] = ConfigurationSourceProxy.Create(src); } } result = targetMethod.Invoke(decoratedBuilder, args); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="AppDomainBootstrap"/> class. /// </summary> public AppDomainBootstrap(IConfigurationSource config) { string startupConfigFile = string.Empty; if (config == null) throw new ArgumentNullException("config"); var configSectionSource = config as ConfigurationSection; if (configSectionSource != null) startupConfigFile = configSectionSource.GetConfigSource(); //Keep serializable version of configuration if(!config.GetType().IsSerializable) config = new ConfigurationSource(config); //Still use raw configuration type to bootstrap m_InnerBootstrap = new DefaultBootstrapAppDomainWrap(this, config, startupConfigFile); }
private void HandleConfigSourceError(IConfigurationSource source, Exception exception, SourceExceptionHandleResult handleResult) { handleResult.IsHandled = true; if (exception is ConfigurationFileSourceException fileException) { Log.Error($"Configuration file '{fileException.FileName}' error", exception); } else { Log.Error($"Configuration source '{source.GetType().Name}' error", exception); } if (_haltOnConfigError) { Environment.Exit(1); } }
public static IConfigurationSource Create(IConfigurationSource decorated, IList <IInterceptor> interceptors = null) { if (typeof(ConfigurationSourceProxy).IsAssignableFrom(decorated.GetType())) { if (interceptors != null) { ConfigurationSourceProxy interceptProxy = (ConfigurationSourceProxy)decorated; foreach (IInterceptor i in interceptors) { interceptProxy.AddInterceptor(i); } } return(decorated); } var proxy = Create <IConfigurationSource, ConfigurationSourceProxy>(); ((ConfigurationSourceProxy)proxy).decoratedSource = decorated; ((ConfigurationSourceProxy)proxy).interceptors = interceptors; return(proxy); }
public void CanCreateAConfigurationSourceThatExistsInConfig() { IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource"); Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType()); }
public void DefaultConfigurationSourceIsSystemSource() { IConfigurationSource defaultSource = ConfigurationSourceFactory.Create(); Assert.AreEqual(typeof(SystemConfigurationSource), defaultSource.GetType()); }