void InitCustomEvaluator(RuleInfo ruleInfo) { string customEvaluator = ruleInfo._customEvaluator; if (customEvaluator == null || customEvaluator.Trim().Length == 0) { ruleInfo._customEvaluatorType = null; return; } ruleInfo._customEvaluatorType = ConfigUtil.GetType(ruleInfo._customEvaluator, "custom", ruleInfo._customEvaluatorConfig); // Make sure the type support WebBaseEvent HandlerBase.CheckAssignableType(ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].Source, ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].LineNumber, typeof(System.Web.Management.IWebEventCustomEvaluator), ruleInfo._customEvaluatorType); // Create a public instance of the custom evaluator if (_customEvaluatorInstances[ruleInfo._customEvaluatorType] == null) { _customEvaluatorInstances[ruleInfo._customEvaluatorType] = HttpRuntime.CreatePublicInstanceByWebObjectActivator(ruleInfo._customEvaluatorType); } }
private static HttpEncoder GetCustomEncoderFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string encoderTypeName = runtimeSection.EncoderType; // validate the type Type encoderType = ConfigUtil.GetType(encoderTypeName, "encoderType", runtimeSection); ConfigUtil.CheckBaseType(typeof(HttpEncoder) /* expectedBaseType */, encoderType, "encoderType", runtimeSection); // instantiate HttpEncoder encoder = (HttpEncoder)HttpRuntime.CreatePublicInstanceByWebObjectActivator(encoderType); return(encoder); }
private static RequestValidator GetCustomValidatorFromConfig() { // App since this is static per AppDomain RuntimeConfig config = RuntimeConfig.GetAppConfig(); HttpRuntimeSection runtimeSection = config.HttpRuntime; string validatorTypeName = runtimeSection.RequestValidationType; // validate the type Type validatorType = ConfigUtil.GetType(validatorTypeName, "requestValidationType", runtimeSection); ConfigUtil.CheckBaseType(typeof(RequestValidator) /* expectedBaseType */, validatorType, "requestValidationType", runtimeSection); // instantiate RequestValidator validator = (RequestValidator)HttpRuntime.CreatePublicInstanceByWebObjectActivator(validatorType); return(validator); }
private static void EnsureResourceProviderFactory() { if (s_resourceProviderFactory != null) { return; } Type t = null; GlobalizationSection globConfig = RuntimeConfig.GetAppConfig().Globalization; t = globConfig.ResourceProviderFactoryTypeInternal; // If we got a type from config, use it. Otherwise, use default factory if (t == null) { s_resourceProviderFactory = new ResXResourceProviderFactory(); } else { s_resourceProviderFactory = (ResourceProviderFactory)HttpRuntime.CreatePublicInstanceByWebObjectActivator(t); } }
internal static ProviderBase InstantiateProvider(NameValueCollection providerSettings, Type providerType) { ProviderBase provider = null; try { string pnName = GetAndRemoveStringValue(providerSettings, "name"); string pnType = GetAndRemoveStringValue(providerSettings, "type"); if (string.IsNullOrEmpty(pnType)) { throw new ArgumentException(SR.GetString(SR.Provider_no_type_name)); } Type t = ConfigUtil.GetType(pnType, "type", null, null, true, true); if (!providerType.IsAssignableFrom(t)) { throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString())); } provider = (ProviderBase)HttpRuntime.CreatePublicInstanceByWebObjectActivator(t); // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection NameValueCollection cloneParams = new NameValueCollection(providerSettings.Count, StringComparer.Ordinal); foreach (string key in providerSettings) { cloneParams[key] = providerSettings[key]; } provider.Initialize(pnName, cloneParams); TelemetryLogger.LogProvider(t); } catch (Exception e) { if (e is ConfigurationException) { throw; } throw new ConfigurationErrorsException(e.Message, e); } return(provider); }
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.CreatePublicInstanceByWebObjectActivator(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); TelemetryLogger.LogProvider(t); } 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); }
WebEventProvider GetProviderInstance(string providerName) { WebEventProvider provider; object o; o = _instances[providerName]; if (o == null) { return(null); } ProviderSettings providerSettings = o as ProviderSettings; if (providerSettings != null) { // If what we got is still a ProviderSettings, it means we haven't created an instance // of it yet. Type type; string typeName = providerSettings.Type; type = BuildManager.GetType(typeName, false); Debug.Assert(type != null, "type != null"); if (typeof(IInternalWebEventProvider).IsAssignableFrom(type)) { provider = (WebEventProvider)HttpRuntime.CreateNonPublicInstance(type); } else { provider = (WebEventProvider)HttpRuntime.CreatePublicInstanceByWebObjectActivator(type); } using (new ProcessImpersonationContext()) { try { provider.Initialize(providerSettings.Name, providerSettings.Parameters); } catch (ConfigurationErrorsException) { throw; } catch (ConfigurationException e) { throw new ConfigurationErrorsException(e.Message, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber); } catch { throw; } } Debug.Trace("ProviderInstances", "Create a provider instance: " + "name=" + providerSettings.Name + ";type=" + typeName); _instances[providerName] = provider; } else { provider = o as WebEventProvider; Debug.Assert(provider != null, "provider != null"); } return(provider); }