Represents a url routing rule.
		/// <summary>
		/// Deserializes the specified section.
		/// </summary>
		/// <param name="section">The section.</param>
		public void Deserialize(XmlNode section)
		{
			var services = section.SelectNodes("routing/rule");
			
			foreach(XmlNode node in services)
			{
				var patternNode = node.SelectSingleNode("pattern");
				var replaceNode = node.SelectSingleNode("replace");

				if (patternNode == null || patternNode.ChildNodes.Count == 0 || patternNode.ChildNodes[0] == null)
				{
					var message = "A rule node must have a pattern (child) " + 
						"node denoting the regular expression to be matched";
					throw new ConfigurationErrorsException(message);
				}
				if (replaceNode == null || replaceNode.ChildNodes.Count == 0 || replaceNode.ChildNodes[0] == null)
				{
					var message = "A rule node must have a replace (child) " + 
						"node denoting the string to be replaced";
					throw new ConfigurationErrorsException(message);
				}

				var pattern = patternNode.ChildNodes[0].Value;
				var replace = replaceNode.ChildNodes[0].Value;

				var rule = new RoutingRule(pattern.Trim(), replace.Trim());
				
				InnerList.Add(rule);
			}
		}
Example #2
0
        /// <summary>
        /// Deserializes the specified section.
        /// </summary>
        /// <param name="section">The section.</param>
        public void Deserialize(XmlNode section)
        {
            var services = section.SelectNodes("routing/rule");

            foreach (XmlNode node in services)
            {
                var patternNode = node.SelectSingleNode("pattern");
                var replaceNode = node.SelectSingleNode("replace");

                if (patternNode == null || patternNode.ChildNodes.Count == 0 || patternNode.ChildNodes[0] == null)
                {
                    var message = "A rule node must have a pattern (child) " +
                                  "node denoting the regular expression to be matched";
                    throw new ConfigurationErrorsException(message);
                }
                if (replaceNode == null || replaceNode.ChildNodes.Count == 0 || replaceNode.ChildNodes[0] == null)
                {
                    var message = "A rule node must have a replace (child) " +
                                  "node denoting the string to be replaced";
                    throw new ConfigurationErrorsException(message);
                }

                var pattern = patternNode.ChildNodes[0].Value;
                var replace = replaceNode.ChildNodes[0].Value;

                var rule = new RoutingRule(pattern.Trim(), replace.Trim());

                InnerList.Add(rule);
            }
        }