Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rule"/> class.
        /// </summary>
        /// <param name="ruleXml">
        /// The rule xml.
        /// </param>
        public Rule(XElement ruleXml)
            : this()
        {
            this.Name       = (ruleXml.Attribute("name") ?? new XAttribute("name", "Unnamed Rule")).Value;
            this.RuleSource = ruleXml;

            // Read paths
            if (ruleXml.Descendants("match").Any())
            {
                this.Matches = (from host in ruleXml.Descendants("match") select new UriPattern(host.Value)).ToList();
            }
            else if (ruleXml.Descendants("matches").Any())
            {
                this.Matches = (from host in ruleXml.Descendants("matches").Descendants("match") select new UriPattern(host.Value)).ToList();
            }

            // Read actions
            if (ruleXml.Descendants("actions").Any())
            {
                var actionsXml = from a in ruleXml.Descendants("actions") select a;
                IList <IHttpAction>     actions;
                IList <IRequestAction>  requestActions;
                IList <IResponseAction> responseActions;
                this.Enabled         = RuleParser.GetActions(actionsXml, out actions, out requestActions, out responseActions);
                this.Actions         = actions;
                this.RequestActions  = requestActions;
                this.ResponseActions = responseActions;
            }

            bool temp;

            this.Enabled    = Boolean.TryParse((ruleXml.Attribute("enabled") ?? new XAttribute("enabled", "true")).Value, out temp) && temp;
            this.LogEnabled = Boolean.TryParse((ruleXml.Attribute("logEnabled") ?? new XAttribute("logEnabled", "true")).Value, out temp) && temp;
        }