Exemple #1
0
        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.CreatePublicInstance(ruleInfo._customEvaluatorType);
            }
        }
        private void ValidateTypes()
        {
            if (_typesValidated)
            {
                return;
            }

            // check process protocol handler

            Type processHandlerType;

            try {
                processHandlerType = Type.GetType(_processHandlerTypeName, true /*throwOnError*/);
            }
            catch (Exception e) {
                throw new ConfigurationErrorsException(e.Message, e, _configFileName, _configFileLine);
            }
            HandlerBase.CheckAssignableType(_configFileName, _configFileLine, typeof(ProcessProtocolHandler), processHandlerType);

            // check app domain protocol handler

            Type appDomainHandlerType;

            try {
                appDomainHandlerType = Type.GetType(_appDomainHandlerTypeName, true /*throwOnError*/);
            }
            catch (Exception e) {
                throw new ConfigurationErrorsException(e.Message, e, _configFileName, _configFileLine);
            }
            HandlerBase.CheckAssignableType(_configFileName, _configFileLine, typeof(AppDomainProtocolHandler), appDomainHandlerType);

            // remember types

            _processHandlerType   = processHandlerType;
            _appDomainHandlerType = appDomainHandlerType;
            _typesValidated       = true;
        }
Exemple #3
0
        //
        // Handle the <result> tag
        //
        static void ProcessResult(HttpCapabilitiesDefaultProvider capabilitiesEvaluator, XmlNode node)
        {
            bool inherit = true;

            HandlerBase.GetAndRemoveBooleanAttribute(node, "inherit", ref inherit);
            if (inherit == false)
            {
                capabilitiesEvaluator.ClearParent();
            }

            Type    resultType = null;
            XmlNode attribute  = HandlerBase.GetAndRemoveTypeAttribute(node, "type", ref resultType);

            if (attribute != null)
            {
                if (resultType.Equals(capabilitiesEvaluator._resultType) == false)
                {
                    // be sure the new type is assignable to the parent type
                    HandlerBase.CheckAssignableType(attribute, capabilitiesEvaluator._resultType, resultType);
                    capabilitiesEvaluator._resultType = resultType;
                }
            }

            int cacheTime = 0;

            attribute = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "cacheTime", ref cacheTime);
            //NOTE: we continue to parse the cacheTime for backwards compat
            // it has never been used.  Customer scenarios don't require this support.
            if (attribute != null)
            {
                capabilitiesEvaluator.CacheTime = TimeSpan.FromSeconds(cacheTime);
            }

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForNonCommentChildNodes(node);
        }
        //
        // Handle the <result> tag
        //
        static void ProcessResult(HttpCapabilitiesEvaluator capabilitiesEvaluator, XmlNode node)
        {
            bool inherit = true;

            HandlerBase.GetAndRemoveBooleanAttribute(node, "inherit", ref inherit);
            if (inherit == false)
            {
                capabilitiesEvaluator.ClearParent();
            }

            Type    resultType = null;
            XmlNode attribute  = HandlerBase.GetAndRemoveTypeAttribute(node, "type", ref resultType);

            if (attribute != null)
            {
                if (resultType.Equals(capabilitiesEvaluator._resultType) == false)
                {
                    // be sure the new type is assignable to the parent type
                    HandlerBase.CheckAssignableType(attribute, capabilitiesEvaluator._resultType, resultType);
                    capabilitiesEvaluator._resultType = resultType;
                }
            }

            int cacheTime = 0;

            attribute = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "cacheTime", ref cacheTime);
            if (attribute != null)
            {
                capabilitiesEvaluator.SetCacheTime(cacheTime);
            }

            HandlerBase.GetAndRemoveBooleanAttribute(node, "cache", ref capabilitiesEvaluator._useCache);

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForChildNodes(node);
        }
Exemple #5
0
        void BasicSanityCheck()
        {
            Type type;

            foreach (ProviderSettings providerSettings in _section.Providers)
            {
                // Make sure the type is valid.
                type = ConfigUtil.GetType(providerSettings.Type, "type", providerSettings);

                // Make sure the type support WebEventProvider
                HandlerBase.CheckAssignableType(providerSettings.ElementInformation.Properties["type"].Source,
                                                providerSettings.ElementInformation.Properties["type"].LineNumber,
                                                typeof(WebEventProvider), type);
            }

            foreach (EventMappingSettings eventMappingSettings in _section.EventMappings)
            {
                // Make sure the type is valid.
                type = ConfigUtil.GetType(eventMappingSettings.Type, "type", eventMappingSettings);

                // Make sure startEventCode <= endEventCode
                if (!(eventMappingSettings.StartEventCode <= eventMappingSettings.EndEventCode))
                {
                    string attribute;

                    // We don't know which one was specified unless we test it
                    attribute = "startEventCode";
                    if (eventMappingSettings.ElementInformation.Properties[attribute].LineNumber == 0)
                    {
                        attribute = "endEventCode";
                        Debug.Assert(eventMappingSettings.ElementInformation.Properties[attribute].LineNumber != 0,
                                     "eventMappingSettings.ElementInformation.Properties[attribute].LineNumber != 0");
                    }

                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Event_name_invalid_code_range),
                              eventMappingSettings.ElementInformation.Properties[attribute].Source, eventMappingSettings.ElementInformation.Properties[attribute].LineNumber);
                }

                // Make sure the type support WebBaseEvent
                HandlerBase.CheckAssignableType(eventMappingSettings.ElementInformation.Properties["type"].Source,
                                                eventMappingSettings.ElementInformation.Properties["type"].LineNumber,
                                                typeof(System.Web.Management.WebBaseEvent), type);

                // It's a valid type.  Might as well save it.
                eventMappingSettings.RealType = type;
            }

            foreach (RuleSettings rule in _section.Rules)
            {
                // Go thru all the Rules, and make sure all referenced provider, eventName
                // and profile exist.

                string provider = rule.Provider;
                if (!String.IsNullOrEmpty(provider))
                {
                    ProviderSettings providerSettings = _section.Providers[provider];
                    if (providerSettings == null)
                    {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.Health_mon_provider_not_found, provider),
                                  rule.ElementInformation.Properties["provider"].Source,
                                  rule.ElementInformation.Properties["provider"].LineNumber);
                    }
                }

                string profile = rule.Profile;
                if (!String.IsNullOrEmpty(profile))
                {
                    if (_section.Profiles[profile] == null)
                    {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.Health_mon_profile_not_found, profile),
                                  rule.ElementInformation.Properties["profile"].Source,
                                  rule.ElementInformation.Properties["profile"].LineNumber);
                    }
                }

                if (_section.EventMappings[rule.EventName] == null)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Event_name_not_found, rule.EventName),
                              rule.ElementInformation.Properties["eventName"].Source, rule.ElementInformation.Properties["eventName"].LineNumber);
                }
            }
        }