public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { ProviderBase base2 = null; try { string str = (providerSettings.Type == null) ? null : providerSettings.Type.Trim(); if (string.IsNullOrEmpty(str)) { throw new ArgumentException(System.Web.SR.GetString("Provider_no_type_name")); } Type c = ConfigUtil.GetType(str, "type", providerSettings, true, true); if (!providerType.IsAssignableFrom(c)) { throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { providerType.ToString() })); } base2 = (ProviderBase) HttpRuntime.CreatePublicInstance(c); NameValueCollection parameters = providerSettings.Parameters; NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal); foreach (string str2 in parameters) { config[str2] = parameters[str2]; } base2.Initialize(providerSettings.Name, config); } catch (Exception exception) { if (exception is ConfigurationException) { throw; } throw new ConfigurationErrorsException(exception.Message, exception, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } return base2; }
public void Add(ProviderSettings provider) { if (provider != null) { BaseAdd(provider); } }
/// <summary> /// Instantiates the provider. /// </summary> /// <param name="providerSettings"> /// The provider settings. /// </param> /// <param name="provType"> /// Type of the prov. /// </param> /// <returns> /// A Provider Base. /// </returns> /// <remarks> /// </remarks> public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type provType) { if (string.IsNullOrEmpty(providerSettings.Type)) { throw new ConfigurationErrorsException( "Provider could not be instantiated. The Type parameter cannot be null."); } var providerType = Type.GetType(providerSettings.Type); if (providerType == null) { throw new ConfigurationErrorsException( "Provider could not be instantiated. The Type could not be found."); } if (!provType.IsAssignableFrom(providerType)) { throw new ConfigurationErrorsException("Provider must implement type \'" + provType + "\'."); } var providerObj = Activator.CreateInstance(providerType); if (providerObj == null) { throw new ConfigurationErrorsException("Provider could not be instantiated."); } var providerBase = (ProviderBase)providerObj; providerBase.Initialize(providerSettings.Name, providerSettings.Parameters); return providerBase; }
/// <summary> /// The add. /// </summary> /// <param name="Message"> /// The Message. /// </param> public void Add(ProviderSettings Message) { if (Message != null) { BaseAdd(Message); } }
/// <summary> /// Initializes the provider and ensures that all configuration can be read /// </summary> /// <param name="builderContext"></param> public override void Initialise(IBuilderContext builderContext) { Mandate.ParameterNotNull(builderContext, "builderContext"); var configMain = builderContext.ConfigurationResolver.GetConfigSection(HiveConfigSection.ConfigXmlKey) as HiveConfigSection; if (configMain == null) throw new ConfigurationErrorsException( string.Format("Configuration section '{0}' not found when building packaging provider '{1}'", HiveConfigSection.ConfigXmlKey, ProviderKey)); var config2Rw = RegistryConfigElement ?? configMain.Providers.ReadWriters[ProviderKey] ?? configMain.Providers.Readers[ProviderKey]; if (config2Rw == null) throw new ConfigurationErrorsException( string.Format("No configuration found for persistence provider '{0}'", ProviderKey)); //get the Hive provider config section _localConfig = DeepConfigManager.Default.GetFirstPluginSection<ProviderConfigurationSection>(config2Rw.ConfigSectionKey); if (!ValidateProviderConfigSection<ExamineDemandBuilder>(_localConfig, config2Rw)) { CanBuild = false; return; } var configMgr = DeepConfigManager.Default; //get the internal indexer provider _internalIndexer = configMgr.GetFirstPluginSetting<ExamineSettings, ProviderSettings>("examine/examine.settings", x => x.IndexProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalIndexer)); if (_internalIndexer == null) { LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalIndexer, the configuration section could not be read."); CanBuild = false; return; } //get the internal searcher provider _internalSearcher = configMgr.GetFirstPluginSetting<ExamineSettings, ProviderSettings>("examine/examine.settings", x => x.SearchProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalSearcher)); if (_internalSearcher == null) { LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalSearcher, the configuration section could not be read."); CanBuild = false; return; } //get the internal index set to use for the searcher/indexer _internalIndexSet = configMgr.GetFirstPluginSetting<IndexSets, IndexSet>("examine/examine.indexes", x => x.SingleOrDefault(set => set.SetName == _localConfig.InternalIndexSet)); if (_internalIndexSet == null) { LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalIndexSet, the configuration section could not be read."); CanBuild = false; return; } CanBuild = true; }
public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { ProviderBase provider = null; try { string pnType = (providerSettings.Type == null) ? null : providerSettings.Type.Trim(); if (string.IsNullOrEmpty(pnType)) throw new ArgumentException(SR.GetString(SR.Provider_no_type_name)); Type t = ConfigUtil.GetType(pnType, "type", providerSettings, true, true); if (!providerType.IsAssignableFrom(t)) throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString())); provider = (ProviderBase)HttpRuntime.CreatePublicInstance(t); // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection NameValueCollection pars = providerSettings.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal); foreach (string key in pars) cloneParams[key] = pars[key]; provider.Initialize(providerSettings.Name, cloneParams); } catch (Exception e) { if (e is ConfigurationException) throw; throw new ConfigurationErrorsException(e.Message, e, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } return provider; }
public static string GetVirtualPath(ProviderSettings providerSettings) { string virtualPath = providerSettings.Parameters["virtualPath"]; virtualPath = VirtualPathUtility.ToAbsolute(virtualPath); return virtualPath; }
public void Add(ProviderSettings provider) { if (provider != null) { provider.UpdatePropertyCollection(); BaseAdd(provider); } }
public static string GetBaseUrl(ProviderSettings providerSettings) { string hostName = GetHostName(providerSettings); string scheme = GetScheme(providerSettings); return VirtualPathUtility.AppendTrailingSlash(scheme + hostName); }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type t = TypeUtil.GetType(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) throw new Exception(SR.WrongType_of_Protected_provider); return CreateAndInitializeProviderWithAssert(t, pn); }
public void TestMethod1() { var settings = new ProviderSettings("sqlProvider", typeof(SqlMembershipProvider).AssemblyQualifiedName); settings.Parameters.Add( "connectionStringName","localserver"); var membershipProvider = ProviderActivator.InstanciateProvider(settings, typeof (MembershipProvider)); Assert.IsNotNull(membershipProvider); Assert.AreEqual("sqlProvider", membershipProvider.Name); }
public static void CacheTests_Initialize(TestContext testContext) { _SessionIdManager = new System.Web.SessionState.SessionIDManager(); _SessionStateSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState"); _ProviderSettings = (ProviderSettings)_SessionStateSection.Providers[_SessionStateSection.CustomProvider]; _TimeoutInSeconds = (int)_SessionStateSection.Timeout.TotalSeconds; UpdateHostingEnvironment(); }
public MemberShipService() { _membershipSection = (MembershipSection)ConfigurationManager.GetSection("system.web/membership"); _memberShipSettingsProvider = _membershipSection.Providers[_membershipSection.DefaultProvider]; _roleManagerSection = (RoleManagerSection)ConfigurationManager.GetSection("system.web/roleManager"); _roleProviderSettings = _roleManagerSection.Providers[_roleManagerSection.DefaultProvider]; _membershipParameters = _memberShipSettingsProvider.Parameters; _rolemanagerParameters = _roleProviderSettings.Parameters; }
private ProtectedConfigurationProvider CreateAndInitializeProviderWithAssert(Type t, ProviderSettings pn) { ProtectedConfigurationProvider provider = (ProtectedConfigurationProvider)TypeUtil.CreateInstanceWithReflectionPermission(t); NameValueCollection pars = pn.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count); foreach (string key in pars) { cloneParams[key] = pars[key]; } provider.Initialize(pn.Name, cloneParams); return provider; }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) { throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider)); } if (!TypeUtil.IsTypeAllowedInConfig(t)) { throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName)); } return CreateAndInitializeProviderWithAssert(t, pn); }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type typeWithReflectionPermission = System.Configuration.TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(typeWithReflectionPermission)) { throw new Exception(System.Configuration.SR.GetString("WrongType_of_Protected_provider")); } if (!System.Configuration.TypeUtil.IsTypeAllowedInConfig(typeWithReflectionPermission)) { throw new Exception(System.Configuration.SR.GetString("Type_from_untrusted_assembly", new object[] { typeWithReflectionPermission.FullName })); } return this.CreateAndInitializeProviderWithAssert(typeWithReflectionPermission, pn); }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type typeWithReflectionPermission = System.Configuration.TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(typeWithReflectionPermission)) { throw new Exception(System.Configuration.SR.GetString("WrongType_of_Protected_provider")); } if (!System.Configuration.TypeUtil.IsTypeAllowedInConfig(typeWithReflectionPermission)) { throw new Exception(System.Configuration.SR.GetString("Type_from_untrusted_assembly", new object[] { typeWithReflectionPermission.FullName })); } return(this.CreateAndInitializeProviderWithAssert(typeWithReflectionPermission, pn)); }
ProtectedConfigurationProvider InstantiateProvider(ProviderSettings ps) { Type t = Type.GetType(ps.Type, true); ProtectedConfigurationProvider prov = Activator.CreateInstance(t) as ProtectedConfigurationProvider; if (prov == null) { throw new Exception("The type specified does not extend ProtectedConfigurationProvider class."); } prov.Initialize(ps.Name, ps.Parameters); return(prov); }
private ConfigurationBuilder CreateAndInitializeBuilderWithAssert(Type t, ProviderSettings ps) { ConfigurationBuilder builder = (ConfigurationBuilder)TypeUtil.CreateInstanceWithReflectionPermission(t); NameValueCollection pars = ps.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count); foreach (string key in pars) { cloneParams[key] = pars[key]; } builder.Initialize(ps.Name, cloneParams); return(builder); }
protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode) { ProviderSettings parentProviders = parentElement as ProviderSettings; parentProviders?.UpdatePropertyCollection(); // before reseting make sure the bag is filled in ProviderSettings sourceProviders = sourceElement as ProviderSettings; sourceProviders?.UpdatePropertyCollection(); // before reseting make sure the bag is filled in base.Unmerge(sourceElement, parentElement, saveMode); UpdatePropertyCollection(); }
protected internal override void Reset(ConfigurationElement parentElement) { base.Reset(parentElement); ProviderSettings sec = parentElement as ProviderSettings; if (sec != null && sec.parameters != null) { parameters = new ConfigNameValueCollection(sec.parameters); } else { parameters = null; } }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) { throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider)); } // Needs to check APTCA bit. See VSWhidbey 429996. if (!TypeUtil.IsTypeAllowedInConfig(t)) { throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName)); } // Needs to check Assert Fulltrust in order for runtime to work. See VSWhidbey 429996. return CreateAndInitializeProviderWithAssert(t, pn); }
public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { Type settingsType = Type.GetType(providerSettings.Type); if (settingsType == null) throw new ConfigurationErrorsException(String.Format("Could not find type: {0}", providerSettings.Type)); if (!providerType.IsAssignableFrom(settingsType)) throw new ConfigurationErrorsException(String.Format("Provider '{0}' must subclass from '{1}'", providerSettings.Name, providerType)); ProviderBase provider = Activator.CreateInstance(settingsType) as ProviderBase; provider.Initialize(providerSettings.Name, providerSettings.Parameters); return provider; }
protected override void LoadStaticConfiguration() { base.LoadStaticConfiguration(); ConnectionStringSettings css = new ConnectionStringSettings(); css.ConnectionString = String.Format( "server={0};uid={1};password={2};database={3};pooling=false", BaseTest.host, BaseTest.user, BaseTest.password, BaseTest.database0); css.Name = "LocalMySqlServer"; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.ConnectionStrings.ConnectionStrings.Add(css); MembershipSection ms = (MembershipSection)config.SectionGroups["system.web"].Sections["membership"]; ms.DefaultProvider = "MySQLMembershipProvider"; ProviderSettings ps = new ProviderSettings(); ps.Name = "MySQLMembershipProvider"; Assembly a = Assembly.GetAssembly(typeof(MySQLMembershipProvider)); ps.Type = "MySql.Web.Security.MySQLMembershipProvider, " + a.FullName; ps.Parameters.Add("connectionStringName", "LocalMySqlServer"); ps.Parameters.Add("enablePasswordRetrieval", "false"); ps.Parameters.Add("enablePasswordReset", "true"); ps.Parameters.Add("requiresQuestionAndAnswer", "true"); ps.Parameters.Add("applicationName", "/"); ps.Parameters.Add("requiresUniqueEmail", "false"); ps.Parameters.Add("passwordFormat", "Hashed"); ps.Parameters.Add("maxInvalidPasswordAttempts", "5"); ps.Parameters.Add("minRequiredPasswordLength", "7"); ps.Parameters.Add("minRequiredNonalphanumericCharacters", "1"); ps.Parameters.Add("passwordAttemptWindow", "10"); ps.Parameters.Add("passwordStrengthRegularExpression", ""); ms.Providers.Add(ps); RoleManagerSection rs = (RoleManagerSection)config.SectionGroups["system.web"].Sections["roleManager"]; rs.DefaultProvider = "MySQLRoleProvider"; rs.Enabled = true; ps = new ProviderSettings(); ps.Name = "MySQLRoleProvider"; a = Assembly.GetAssembly(typeof(MySQLRoleProvider)); ps.Type = "MySql.Web.Security.MySQLRoleProvider, " + a.FullName; ps.Parameters.Add("connectionStringName", "LocalMySqlServer"); ps.Parameters.Add("applicationName", "/"); rs.Providers.Add(ps); config.Save(); ConfigurationManager.RefreshSection("connectionStrings"); ConfigurationManager.RefreshSection("system.web/membership"); ConfigurationManager.RefreshSection("system.web/roleManager"); }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) { throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider)); } if (!TypeUtil.IsTypeAllowedInConfig(t)) { throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName)); } return(CreateAndInitializeProviderWithAssert(t, pn)); }
protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode) { ProviderSettings settings = parentElement as ProviderSettings; if (settings != null) { settings.UpdatePropertyCollection(); } ProviderSettings settings2 = sourceElement as ProviderSettings; if (settings2 != null) { settings2.UpdatePropertyCollection(); } base.Unmerge(sourceElement, parentElement, saveMode); this.UpdatePropertyCollection(); }
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn) { Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true); if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) { throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider)); } // Needs to check APTCA bit. See VSWhidbey 429996. if (!TypeUtil.IsTypeAllowedInConfig(t)) { throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName)); } // Needs to check Assert Fulltrust in order for runtime to work. See VSWhidbey 429996. return(CreateAndInitializeProviderWithAssert(t, pn)); }
private ConfigurationBuilder InstantiateBuilder(ProviderSettings ps) { Type t = TypeUtil.GetTypeWithReflectionPermission(ps.Type, true); if (!typeof(ConfigurationBuilder).IsAssignableFrom(t)) { throw new ConfigurationErrorsException("[" + ps.Name + "] - " + SR.GetString(SR.WrongType_of_config_builder)); } // Needs to check APTCA bit. See VSWhidbey 429996. if (!TypeUtil.IsTypeAllowedInConfig(t)) { throw new ConfigurationErrorsException("[" + ps.Name + "] - " + SR.GetString(SR.Type_from_untrusted_assembly, t.FullName)); } // Needs to check Assert Fulltrust in order for runtime to work. See VSWhidbey 429996. return(CreateAndInitializeBuilderWithAssert(t, ps)); }
private ConfigurationBuilder CreateAndInitializeBuilderWithAssert(Type t, ProviderSettings ps) { ConfigurationBuilder builder = (ConfigurationBuilder)TypeUtil.CreateInstanceWithReflectionPermission(t); NameValueCollection pars = ps.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count); foreach (string key in pars) { cloneParams[key] = pars[key]; } try { builder.Initialize(ps.Name, cloneParams); } catch (Exception e) { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.ConfigBuilder_init_error, ps.Name), e, null); } return(builder); }
public void Add(ProviderSettings provider) { }
/// <summary> /// Update the web.config membership related config sections, membership, profile, and roleManager. /// And also set the roleManager Enabled property to true. /// </summary> /// <param name="configSection"></param> /// <param name="config"></param> private void UpdateMembershipProviders(Configuration configSection, InstallerConfig config) { if (config.Membership.Create) { MembershipSection membership = configSection.GetSection("system.web/membership") as MembershipSection; ProfileSection profile = configSection.GetSection("system.web/profile") as ProfileSection; RoleManagerSection roleManager = configSection.GetSection("system.web/roleManager") as RoleManagerSection; string connString = config.Database.ConnectionStringName; if (!string.IsNullOrEmpty(config.Database.EntityFrameworkEntitiesName)) { connString = "MembershipConnection"; } // Update the membership section. bool isCustomMembershipProvider = (config.Membership.ProviderName == "AspNetSqlMembershipProvider") ? false : true; membership.DefaultProvider = config.Membership.ProviderName; for (int i = 0; i < membership.Providers.Count; i++) { if (membership.Providers[i].Name == "AspNetSqlMembershipProvider") { membership.Providers[i].Parameters["connectionStringName"] = connString; membership.Providers[i].Parameters["name"] = "AspNetSqlMembershipProvider"; membership.Providers[i].Parameters["type"] = "System.Web.Security.SqlMembershipProvider"; membership.Providers[i].Parameters["applicationName"] = config.ApplicationName; } } if (isCustomMembershipProvider) { // Create a new provider. ProviderSettings p = new ProviderSettings(); p.Parameters["connectionStringName"] = connString; p.Parameters["name"] = config.Membership.ProviderName; p.Parameters["type"] = config.Membership.type; p.Parameters["applicationName"] = config.ApplicationName; membership.Providers.Add(p); } // Update the profile section. bool isCustomProfileProvider = (config.Profile.ProviderName == "AspNetSqlProfileProvider") ? false : true; profile.DefaultProvider = config.Profile.ProviderName; for (int i = 0; i < profile.Providers.Count; i++) { if (profile.Providers[i].Name == "AspNetSqlProfileProvider") { profile.Providers[i].Parameters["connectionStringName"] = connString; profile.Providers[i].Parameters["name"] = "AspNetSqlProfileProvider"; profile.Providers[i].Parameters["type"] = "System.Web.Profile.SqlProfileProvider"; profile.Providers[i].Parameters["applicationName"] = config.ApplicationName; } } if (isCustomProfileProvider) { ProviderSettings p = new ProviderSettings(); p.Parameters["connectionStringName"] = connString; p.Parameters["name"] = config.Profile.ProviderName; p.Parameters["type"] = config.Profile.type; p.Parameters["applicationName"] = config.ApplicationName; profile.Providers.Add(p); } // Update the roleManager section. bool isCustomRoleProvider = (config.RoleManager.ProviderName == "AspNetSqlRoleProvider") ? false : true; roleManager.DefaultProvider = config.RoleManager.ProviderName; for (int i = 0; i < roleManager.Providers.Count; i++) { if (roleManager.Providers[i].Name == "AspNetSqlRoleProvider") { roleManager.Providers[i].Parameters["connectionStringName"] = connString; roleManager.Providers[i].Parameters["name"] = "AspNetSqlRoleProvider"; roleManager.Providers[i].Parameters["type"] = "System.Web.Security.SqlRoleProvider"; roleManager.Providers[i].Parameters["applicationName"] = config.ApplicationName; } } if (isCustomRoleProvider) { ProviderSettings p = new ProviderSettings(); p.Parameters["connectionStringName"] = connString; p.Parameters["name"] = config.RoleManager.ProviderName; p.Parameters["type"] = config.RoleManager.type; p.Parameters["applicationName"] = config.ApplicationName; roleManager.Providers.Add(p); } roleManager.Enabled = true; } }
public static string GetScheme(ProviderSettings providerSettings) { return providerSettings.Parameters["scheme"] ?? "http://"; }
/// <summary> /// 加载提供者的设置 /// </summary> /// <returns></returns> private static ProviderSettings CreateProviderSettings(string name,Type type,params KeyValuePair<string,string>[] parameters ) { ProviderSettings settings = new ProviderSettings(name,type.AssemblyQualifiedName); foreach (KeyValuePair<string,string> parameter in parameters) { settings.Parameters.Add(parameter.Key,parameter.Value); } return settings; }
public static void SetFileToPublic(ProviderSettings providerSettings, string file) { new Repository.AmazonS3Repository(providerSettings.Parameters["awsAccessKey"], providerSettings.Parameters["awsSecretKey"], providerSettings.Parameters["bucketName"]).SetFileToPublic(file); }
/// <summary> /// Instantiates the provider. /// </summary> /// <param name="providerSettings">The settings.</param> /// <param name="providerType">Type of the provider to be instantiated.</param> /// <returns></returns> public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType) { ProviderBase base2 = null; try { string str = (providerSettings.Type == null) ? null : providerSettings.Type.Trim(); if (string.IsNullOrEmpty(str)) { throw new ArgumentException("Provider type name is invalid"); } string appDir = null; // Unified way to get Application Path // if RelativeSearchPath is null or empty, check in normal way if (string.IsNullOrEmpty(AppDomain.CurrentDomain.RelativeSearchPath)) appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // otherwise check for web application else appDir = AppDomain.CurrentDomain.RelativeSearchPath; NameValueCollection parameters = providerSettings.Parameters; NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal); foreach (string str2 in parameters) { config[str2] = parameters[str2]; } string dll = config["assembly"].ToString(); Assembly assembly = Assembly.LoadFile(appDir + "\\" + dll); Type type = assembly.GetType(str, true, true); if (!providerType.IsAssignableFrom(type)) { throw new ArgumentException(String.Format("Provider must implement type {0}.", providerType.ToString())); } base2 = (ProviderBase)Activator.CreateInstance(type); base2.Initialize(providerSettings.Name, config); } catch (Exception exception) { if (exception is ConfigurationException) { throw; } throw new ConfigurationErrorsException(exception.Message, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } return base2; }
public void Add(ProviderSettings provider) { BaseAdd(provider); }
ProtectedConfigurationProvider InstantiateProvider (ProviderSettings ps) { Type t = Type.GetType (ps.Type, true); ProtectedConfigurationProvider prov = Activator.CreateInstance (t) as ProtectedConfigurationProvider; if (prov == null) throw new Exception ("The type specified does not extend ProtectedConfigurationProvider class."); prov.Initialize (ps.Name, ps.Parameters); return prov; }
private static ProviderBase CreateProvider(ProviderSettings providerSettings) { var providerType = providerSettings.Type?.Trim(); if (String.IsNullOrEmpty(providerType)) { throw new ArgumentException(nameof(providerType)); } var type = Type.GetType(providerType, true, true); if (!typeof(SiteSettingsProvider).IsAssignableFrom(type)) { throw new ArgumentException(nameof(type)); } var providerInstance = (SiteSettingsProvider)Activator.CreateInstance(type); var parameters = new NameValueCollection(providerSettings.Parameters.Count, StringComparer.Ordinal); foreach (string name in providerSettings.Parameters) { parameters[name] = providerSettings.Parameters[name]; } providerInstance.Initialize(providerSettings.Name, parameters); return providerInstance; }
private ProtectedConfigurationProvider CreateAndInitializeProviderWithAssert(Type t, ProviderSettings pn) { ProtectedConfigurationProvider provider = (ProtectedConfigurationProvider)System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(t); NameValueCollection parameters = pn.Parameters; NameValueCollection config = new NameValueCollection(parameters.Count); foreach (string str in parameters) { config[str] = parameters[str]; } provider.Initialize(pn.Name, config); return(provider); }
public void LoadValuesFromConfigurationXml(XmlNode node) { foreach (XmlNode child in node.ChildNodes) { if (child.Name == "providers") { foreach (XmlNode providerNode in child.ChildNodes) { if ( (providerNode.NodeType == XmlNodeType.Element) && (providerNode.Name == "add") ) { if ( (providerNode.Attributes["name"] != null) && (providerNode.Attributes["type"] != null) ) { ProviderSettings providerSettings = new ProviderSettings( providerNode.Attributes["name"].Value, providerNode.Attributes["type"].Value); providerSettingsCollection.Add(providerSettings); } } } } } }
private const string _ignoreLoadFailuresSwitch = "ConfigurationBuilders.IgnoreLoadFailure"; // Keep in sync with System.Web.Hosting.ApplicationManager public ConfigurationBuilder GetBuilderFromName(string builderName) { string[] builderChain = builderName.Split(new char[] { ',' }); bool throwOnLoadError = (AppDomain.CurrentDomain.GetData(_ignoreLoadFailuresSwitch) == null); // If only one builder is specified, just use it directly if (builderChain.Length == 1) { ProviderSettings ps = Builders[builderName]; if (ps == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_builder_not_found, builderName)); } try { return(InstantiateBuilder(ps)); } catch (FileNotFoundException) { if (throwOnLoadError) { throw; } } catch (TypeLoadException) { if (throwOnLoadError) { throw; } } return(null); } // Otherwise, build a chain ConfigurationBuilderChain chain = new ConfigurationBuilderChain(); chain.Initialize(builderName, null); foreach (string name in builderChain) { ProviderSettings ps = Builders[name.Trim()]; if (ps == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_builder_not_found, name)); } try { chain.Builders.Add(InstantiateBuilder(ps)); } catch (FileNotFoundException) { if (throwOnLoadError) { throw; } } catch (TypeLoadException) { if (throwOnLoadError) { throw; } } } if (chain.Builders.Count == 0) { return(null); } return(chain); }
public static void Main() { // Process the // System.Web.Configuration.HealthMonitoringSectionobject. try { // Get the Web application configuration. System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet"); // Get the section. System.Web.Configuration.HealthMonitoringSection healthMonitoringSection = (System.Web.Configuration.HealthMonitoringSection)configuration.GetSection("system.web/healthmonitoring"); // <Snippet2> // Get the current Enabled property value. Boolean enabledValue = healthMonitoringSection.Enabled; // Set the Enabled property to false. healthMonitoringSection.Enabled = false; // </Snippet2> // <Snippet3> // Get the current HeartBeatInterval property value. TimeSpan heartBeatIntervalValue = healthMonitoringSection.HeartbeatInterval; // Set the HeartBeatInterval property to // TimeSpan.Parse("00:10:00"). healthMonitoringSection.HeartbeatInterval = TimeSpan.Parse("00:10:00"); // </Snippet3> // <Snippet4> // <Snippet9> // Add a BufferModeSettings object to the BufferModes collection property. BufferModeSettings bufferModeSetting = new BufferModeSettings("Error Log", 1024, 256, 512, new TimeSpan(0, 30, 0), new TimeSpan(0, 5, 0), 2); // <Snippet15> bufferModeSetting.Name = "Operations Notification"; // </Snippet15> // <Snippet16> bufferModeSetting.MaxBufferSize = 128; // </Snippet16> // <Snippet17> bufferModeSetting.MaxBufferThreads = 1; // </Snippet17> // <Snippet18> bufferModeSetting.MaxFlushSize = 24; // </Snippet18> // <Snippet19> bufferModeSetting.RegularFlushInterval = TimeSpan.MaxValue; // </Snippet19> // <Snippet20> bufferModeSetting.UrgentFlushInterval = TimeSpan.Parse("00:01:00"); // </Snippet20> // <Snippet21> bufferModeSetting.UrgentFlushThreshold = 1; // </Snippet21> healthMonitoringSection.BufferModes.Add(bufferModeSetting); // </Snippet9> // <Snippet10> // Add a BufferModeSettings object to the BufferModes collection property. healthMonitoringSection.BufferModes.Add(new BufferModeSettings("Error Log", 1024, 256, 512, new TimeSpan(0, 30, 0), new TimeSpan(0, 5, 0), 2)); // </Snippet10> // <Snippet11> // Display contents of the BufferModes collection property Console.WriteLine("BufferModes Collection contains {0} values:", healthMonitoringSection.BufferModes.Count); // Display all elements. for (System.Int32 i = 0; i < healthMonitoringSection.BufferModes.Count; i++) { // <Snippet22> bufferModeSetting = healthMonitoringSection.BufferModes[i]; // </Snippet22> // <Snippet23> string name = bufferModeSetting.Name; // </Snippet23> // <Snippet24> int maxBufferSize = bufferModeSetting.MaxBufferSize; // </Snippet24> // <Snippet25> int maxBufferThreads = bufferModeSetting.MaxBufferThreads; // </Snippet25> // <Snippet26> int maxFlushSize = bufferModeSetting.MaxFlushSize; // </Snippet26> // <Snippet27> TimeSpan regularFlushInterval = bufferModeSetting.RegularFlushInterval; // </Snippet27> // <Snippet28> TimeSpan urgentFlushInterval = bufferModeSetting.UrgentFlushInterval; // </Snippet28> // <Snippet29> int urgentFlushThreshold = bufferModeSetting.UrgentFlushThreshold; // </Snippet29> string item = "Name='" + name + "', MaxBufferSize = '" + maxBufferSize + "', MaxBufferThreads = '" + maxBufferThreads + "', MaxFlushSize = '" + maxFlushSize + "', RegularFlushInterval = '" + regularFlushInterval + "', UrgentFlushInterval = '" + urgentFlushInterval + "', UrgentFlushThreshold = '" + urgentFlushThreshold + "'"; Console.WriteLine(" Item {0}: {1}", i, item); } // </Snippet11> // <Snippet12> // Get a named BufferMode bufferModeSetting = healthMonitoringSection.BufferModes["Error Log"]; // </Snippet12> // <Snippet13> // Remove a BufferModeSettings object from the BufferModes collection property. healthMonitoringSection.BufferModes.Remove("Error Log"); // </Snippet13> // <Snippet14> // Clear all BufferModeSettings object from the BufferModes collection property. healthMonitoringSection.BufferModes.Clear(); // </Snippet14> // </Snippet4> // <Snippet5> // <Snippet30> // Add a EventMappingsSettings object to the EventMappings collection property. EventMappingSettings eventMappingSetting = new EventMappingSettings( "Failure Audits", "System.Web.Management.WebAuditEvent, System.Web"); // <Snippet41> eventMappingSetting.Name = "All Errors"; // </Snippet41> // <Snippet42> eventMappingSetting.Type = "System.Web.Management.WebErrorEvent, System.Web"; // </Snippet42> // <Snippet43> eventMappingSetting.StartEventCode = 0; // </Snippet43> // <Snippet44> eventMappingSetting.EndEventCode = 4096; // </Snippet44> healthMonitoringSection.EventMappings.Add(eventMappingSetting); // </Snippet30> // <Snippet31> // Add an EventMappingsSettings object to the EventMappings collection property. healthMonitoringSection.EventMappings.Add(new EventMappingSettings( "Failure Audits", "System.Web.Management.WebAuditEvent, System.Web")); // </Snippet31> // <Snippet32> // Add an EventMappingsSettings object to the EventMappings collection property. healthMonitoringSection.EventMappings.Add(new EventMappingSettings( "Success Audits", "System.Web.Management.WebAuditEvent, System.Web", 512, Int32.MaxValue)); // </Snippet32> // <Snippet33> // Insert an EventMappingsSettings object into the EventMappings collection property. healthMonitoringSection.EventMappings.Insert(1, new EventMappingSettings("HeartBeats", "", 1, 2)); // </Snippet33> // <Snippet34> // Display contents of the EventMappings collection property Console.WriteLine( "EventMappings Collection contains {0} values:", healthMonitoringSection.EventMappings.Count); // Display all elements. for (System.Int32 i = 0; i < healthMonitoringSection.EventMappings.Count; i++) { // <Snippet45> eventMappingSetting = healthMonitoringSection.EventMappings[i]; // </Snippet45> // <Snippet46> string name = eventMappingSetting.Name; // </Snippet46> // <Snippet47> string type = eventMappingSetting.Type; // </Snippet47> // <Snippet48> int startCd = eventMappingSetting.StartEventCode; // </Snippet48> // <Snippet49> int endCd = eventMappingSetting.EndEventCode; // </Snippet49> string item = "Name='" + name + "', Type='" + type + "', StartEventCode = '" + startCd.ToString() + "', EndEventCode = '" + endCd.ToString() + "'"; Console.WriteLine(" Item {0}: {1}", i, item); } // </Snippet34> // <Snippet35> // See if the EventMappings collection property contains the event 'HeartBeats'. Console.WriteLine("EventMappings contains 'HeartBeats': {0}.", healthMonitoringSection.EventMappings.Contains("HeartBeats")); // </Snippet35> // <Snippet36> // Get the index of the 'HeartBeats' event in the EventMappings collection property. Console.WriteLine("EventMappings index for 'HeartBeats': {0}.", healthMonitoringSection.EventMappings.IndexOf("HeartBeats")); // </Snippet36> // <Snippet37> // Get a named EventMappings eventMappingSetting = healthMonitoringSection.EventMappings["HeartBeats"]; // </Snippet37> // <Snippet38> // Remove an EventMappingsSettings object from the EventMappings collection property. healthMonitoringSection.EventMappings.Remove("HeartBeats"); // </Snippet38> // <Snippet39> // Remove an EventMappingsSettings object from the EventMappings collection property. healthMonitoringSection.EventMappings.RemoveAt(0); // </Snippet39> // <Snippet40> // Clear all EventMappingsSettings object from the EventMappings collection property. healthMonitoringSection.EventMappings.Clear(); // </Snippet40> // </Snippet5> // <Snippet6> // <Snippet50> // Add a ProfileSettings object to the Profiles collection property. ProfileSettings profileSetting = new ProfileSettings("Default"); // <Snippet62> profileSetting.Name = "Custom"; // </Snippet62> // <Snippet63> profileSetting.MaxLimit = Int32.MaxValue; // </Snippet63> // <Snippet64> profileSetting.MinInstances = 1; // </Snippet64> // <Snippet65> profileSetting.MinInterval = TimeSpan.Parse("00:01:00"); // </Snippet65> // <Snippet66> profileSetting.Custom = "MyEvaluators.MyCustomeEvaluator, MyCustom.dll"; // </Snippet66> healthMonitoringSection.Profiles.Add(profileSetting); // </Snippet50> // <Snippet51> // Add a ProfileSettings object to the Profiles collection property. healthMonitoringSection.Profiles.Add(new ProfileSettings("Default")); // </Snippet51> // <Snippet52> // Add a ProfileSettings object to the Profiles collection property. healthMonitoringSection.Profiles.Add(new ProfileSettings("Critical", 1, 1024, new TimeSpan(0, 0, 00))); // </Snippet52> // <Snippet53> // Add a ProfileSettings object to the Profiles collection property. healthMonitoringSection.Profiles.Add(new ProfileSettings("Targeted", 1, Int32.MaxValue, new TimeSpan(0, 0, 10), "MyEvaluators.MyTargetedEvaluator, MyCustom.dll")); // </Snippet53> // <Snippet54> // Insert an ProfileSettings object into the Profiles collection property. healthMonitoringSection.Profiles.Insert(1, new ProfileSettings("Default2")); // </Snippet54> // <Snippet55> // Display contents of the Profiles collection property Console.WriteLine( "Profiles Collection contains {0} values:", healthMonitoringSection.Profiles.Count); // Display all elements. for (System.Int32 i = 0; i < healthMonitoringSection.Profiles.Count; i++) { // <Snippet67> profileSetting = healthMonitoringSection.Profiles[i]; // </Snippet67> // <Snippet68> string name = profileSetting.Name; // </Snippet68> // <Snippet69> int minInstances = profileSetting.MinInstances; // </Snippet69> // <Snippet70> int maxLimit = profileSetting.MaxLimit; // </Snippet70> // <Snippet71> TimeSpan minInterval = profileSetting.MinInterval; // </Snippet71> // <Snippet72> string custom = profileSetting.Custom; // </Snippet72> string item = "Name='" + name + "', MinInstances = '" + minInstances + "', MaxLimit = '" + maxLimit + "', MinInterval = '" + minInterval + "', Custom = '" + custom + "'"; Console.WriteLine(" Item {0}: {1}", i, item); } // </Snippet55> // <Snippet56> // See if the ProfileSettings collection property contains the event 'Default'. Console.WriteLine("Profiles contains 'Default': {0}.", healthMonitoringSection.Profiles.Contains("Default")); // </Snippet56> // <Snippet57> // Get the index of the 'Default' ProfileSettings in the Profiles collection property. Console.WriteLine("Profiles index for 'Default': {0}.", healthMonitoringSection.Profiles.IndexOf("Default")); // </Snippet57> // <Snippet58> // Get a named ProfileSettings profileSetting = healthMonitoringSection.Profiles["Default"]; // </Snippet58> // <Snippet59> // Remove a ProfileSettings object from the Profiles collection property. healthMonitoringSection.Profiles.Remove("Default"); // </Snippet59> // <Snippet60> // Remove a ProfileSettings object from the Profiles collection property. healthMonitoringSection.Profiles.RemoveAt(0); // </Snippet60> // <Snippet61> // Clear all ProfileSettings object from the Profiles collection property. healthMonitoringSection.Profiles.Clear(); // </Snippet61> // </Snippet6> // <Snippet7> // Display contents of the Providers collection property Console.WriteLine("Providers Collection contains {0} values:", healthMonitoringSection.Providers.Count); // Display all elements. for (System.Int32 i = 0; i < healthMonitoringSection.Providers.Count; i++) { System.Configuration.ProviderSettings provider = healthMonitoringSection.Providers[i]; Console.WriteLine(" Item {0}: Name = '{1}' Type = '{2}'", i, provider.Name, provider.Type); } // </Snippet7> // <Snippet8> // <Snippet73> // Add a RuleSettings object to the Rules collection property. RuleSettings ruleSetting = new RuleSettings("All Errors Default", "All Errors", "EventLogProvider"); // <Snippet85> ruleSetting.Name = "All Errors Custom"; // </Snippet85> // <Snippet86> ruleSetting.EventName = "All Errors"; // </Snippet86> // <Snippet87> ruleSetting.Provider = "EventLogProvider"; // </Snippet87> // <Snippet88> ruleSetting.Profile = "Custom"; // </Snippet88> // <Snippet89> ruleSetting.MaxLimit = Int32.MaxValue; // </Snippet89> // <Snippet90> ruleSetting.MinInstances = 1; // </Snippet90> // <Snippet91> ruleSetting.MinInterval = TimeSpan.Parse("00:00:30"); // </Snippet91> // <Snippet92> ruleSetting.Custom = "MyEvaluators.MyCustomeEvaluator2, MyCustom.dll"; // </Snippet92> healthMonitoringSection.Rules.Add(ruleSetting); // </Snippet73> // <Snippet74> // Add a RuleSettings object to the Rules collection property. healthMonitoringSection.Rules.Add(new RuleSettings("All Errors Default", "All Errors", "EventLogProvider")); // </Snippet74> // <Snippet75> // Add a RuleSettings object to the Rules collection property. healthMonitoringSection.Rules.Add(new RuleSettings("Failure Audits Default", "Failure Audits", "EventLogProvider", "Default", 1, Int32.MaxValue, new TimeSpan(0, 1, 0))); // </Snippet75> // <Snippet76> // Add a RuleSettings object to the Rules collection property. healthMonitoringSection.Rules.Add(new RuleSettings("Failure Audits Custom", "Failure Audits", "EventLogProvider", "Custom", 1, Int32.MaxValue, new TimeSpan(0, 1, 0), "MyEvaluators.MyCustomeEvaluator2, MyCustom.dll")); // </Snippet76> // <Snippet77> // Insert an RuleSettings object into the Rules collection property. healthMonitoringSection.Rules.Insert(1, new RuleSettings("All Errors Default2", "All Errors", "EventLogProvider")); // </Snippet77> // <Snippet78> // Display contents of the Rules collection property Console.WriteLine( "Rules Collection contains {0} values:", healthMonitoringSection.Rules.Count); // Display all elements. for (System.Int32 i = 0; i < healthMonitoringSection.Rules.Count; i++) { // <Snippet93> ruleSetting = healthMonitoringSection.Rules[i]; // </Snippet93> // <Snippet94> string name = ruleSetting.Name; // </Snippet94> // <Snippet95> string eventName = ruleSetting.EventName; // </Snippet95> // <Snippet96> string provider = ruleSetting.Provider; // </Snippet96> // <Snippet97> string profile = ruleSetting.Profile; // </Snippet97> // <Snippet98> int minInstances = ruleSetting.MinInstances; // </Snippet98> // <Snippet99> int maxLimit = ruleSetting.MaxLimit; // </Snippet99> // <Snippet100> TimeSpan minInterval = ruleSetting.MinInterval; // </Snippet100> // <Snippet101> string custom = ruleSetting.Custom; // </Snippet101> string item = "Name='" + name + "', EventName='" + eventName + "', Provider = '" + provider + "', Profile = '" + profile + "', MinInstances = '" + minInstances + "', MaxLimit = '" + maxLimit + "', MinInterval = '" + minInterval + "', Custom = '" + custom + "'"; Console.WriteLine(" Item {0}: {1}", i, item); } // </Snippet78> // <Snippet79> // See if the Rules collection property contains the RuleSettings 'All Errors Default'. Console.WriteLine("EventMappings contains 'All Errors Default': {0}.", healthMonitoringSection.Rules.Contains("All Errors Default")); // </Snippet79> // <Snippet80> // Get the index of the 'All Errors Default' RuleSettings in the Rules collection property. Console.WriteLine("EventMappings index for 'All Errors Default': {0}.", healthMonitoringSection.Rules.IndexOf("All Errors Default")); // </Snippet80> // <Snippet81> // Get a named RuleSettings ruleSetting = healthMonitoringSection.Rules["All Errors Default"]; // </Snippet81> // <Snippet82> // Remove a RuleSettings object from the Rules collection property. healthMonitoringSection.Rules.Remove("All Errors Default"); // </Snippet82> // <Snippet83> // Remove a RuleSettings object from the Rules collection property. healthMonitoringSection.Rules.RemoveAt(0); // </Snippet83> // <Snippet84> // Clear all RuleSettings object from the Rules collection property. healthMonitoringSection.Rules.Clear(); // </Snippet84> // </Snippet8> // Update if not locked. if (!healthMonitoringSection.SectionInformation.IsLocked) { configuration.Save(); Console.WriteLine("** Configuration updated."); } else { Console.WriteLine("** Could not update, section is locked."); } } catch (System.ArgumentException e) { // Unknown error. Console.WriteLine( "A invalid argument exception detected in UsingHealthMonitoringSection Main."); Console.WriteLine("Check your command line for errors."); } }
public void Init (HttpApplication app) { config = (SessionStateSection) WebConfigurationManager.GetSection ("system.web/sessionState"); ProviderSettings settings; switch (config.Mode) { case SessionStateMode.Custom: settings = config.Providers [config.CustomProvider]; if (settings == null) throw new HttpException (String.Format ("Cannot find '{0}' provider.", config.CustomProvider)); break; case SessionStateMode.Off: return; case SessionStateMode.InProc: settings = new ProviderSettings (null, typeof (SessionInProcHandler).AssemblyQualifiedName); break; case SessionStateMode.SQLServer: settings = new ProviderSettings (null, typeof (SessionSQLServerHandler).AssemblyQualifiedName); break; case SessionStateMode.StateServer: settings = new ProviderSettings (null, typeof (SessionStateServerHandler).AssemblyQualifiedName); break; default: throw new NotImplementedException (String.Format ("The mode '{0}' is not implemented.", config.Mode)); } handler = (SessionStateStoreProviderBase) ProvidersHelper.InstantiateProvider (settings, typeof (SessionStateStoreProviderBase)); if (String.IsNullOrEmpty(config.SessionIDManagerType)) { idManager = new SessionIDManager (); } else { Type idManagerType = HttpApplication.LoadType (config.SessionIDManagerType, true); idManager = (ISessionIDManager)Activator.CreateInstance (idManagerType); } try { idManager.Initialize (); } catch (Exception ex) { throw new HttpException ("Failed to initialize session ID manager.", ex); } supportsExpiration = handler.SetItemExpireCallback (OnSessionExpired); HttpRuntimeSection runtime = HttpRuntime.Section; executionTimeout = runtime.ExecutionTimeout; //executionTimeoutMS = executionTimeout.Milliseconds; this.app = app; app.BeginRequest += new EventHandler (OnBeginRequest); app.AcquireRequestState += new EventHandler (OnAcquireRequestState); app.ReleaseRequestState += new EventHandler (OnReleaseRequestState); app.EndRequest += new EventHandler (OnEndRequest); }
public static string GetHostName(ProviderSettings providerSettings) { return providerSettings.Parameters["hostName"]; }
private ProtectedConfigurationProvider CreateAndInitializeProviderWithAssert(Type t, ProviderSettings pn) { ProtectedConfigurationProvider provider = (ProtectedConfigurationProvider)TypeUtil.CreateInstance(t); NameValueCollection pars = pn.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count); foreach (string key in pars) { cloneParams[key] = pars[key]; } provider.Initialize(pn.Name, cloneParams); return(provider); }