/// <summary> /// Splits the rule flags. /// </summary> /// <param name="flags">The flags.</param> /// <returns></returns> protected IRuleFlagProcessor SplitRuleFlags(string flags) { RuleFlagProcessor dictionary = new RuleFlagProcessor(); List<string> temporaryHolding = new List<string>(); dictionary.BeginAdd(); foreach (string flag in flags.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string temp = flag; if (flag.Contains("\"") || temporaryHolding.Count > 0) { temporaryHolding.Add(flag.Replace("\"", String.Empty)); if (flag.Contains("\"") && temporaryHolding.Count > 1) { temp = String.Join(",", temporaryHolding.ToArray()); temporaryHolding.Clear(); } else continue; } IRuleFlag ruleFlag = AddRuleFlag(temp); if (ruleFlag != null) dictionary.Add(ruleFlag); } dictionary.EndAdd(); return dictionary; }
/// <summary> /// Gets the rule. /// </summary> /// <param name="ruleElement">The rule element.</param> /// <returns></returns> private IRule GetRule(XmlNode ruleElement) { if (ruleElement == null) throw new ArgumentNullException("ruleElement"); if (ruleElement.Name != "rule") throw new RuleSetException("The node is not a \"rule\"."); bool enabled = true; // from schema definition if (ruleElement.Attributes["enabled"] != null) enabled = XmlConvert.ToBoolean(ruleElement.Attributes["enabled"].Value); // if it is not enabled there is no reason to continue processing if (!enabled) return null; string name = String.Empty; bool stopProcessing = false; // from schema definition string patternSyntax = "ECMAScript"; // from schema definiton if (ruleElement.Attributes["name"] != null) name = ruleElement.Attributes["name"].Value; if (ruleElement.Attributes["stopProcessing"] != null) stopProcessing = XmlConvert.ToBoolean(ruleElement.Attributes["stopProcessing"].Value); if (ruleElement.Attributes["patternSyntax"] != null) patternSyntax = ruleElement.Attributes["patternSyntax"].Value; XmlNode matchElement = ruleElement.SelectSingleNode("match"); XmlNode conditionsElement = ruleElement.SelectSingleNode("conditions"); XmlNode serverVariablesElement = ruleElement.SelectSingleNode("serverVariables"); XmlNode actionElement = ruleElement.SelectSingleNode("action"); IRuleFlagProcessor ruleFlags = new RuleFlagProcessor(); IRule rule = new DefaultRule(); rule.Name = name; // <match /> Pattern match = GetMatch(matchElement, ref ruleFlags); // <condition /> IEnumerable<ICondition> conditions = GetConditions(conditionsElement); // <serverVariables /> foreach (var flag in GetServerVariables(serverVariablesElement)) ruleFlags.Add(flag); // <action /> IRuleAction action = GetAction(actionElement, match, ref ruleFlags); // <rule /> rule.Init(conditions, action, ruleFlags); return rule; }