private static void ReadMapping(XmlNode node, RewriterConfiguration config) { // Name attribute. XmlNode nameNode = node.Attributes[Constants.AttrName]; // Mapper type not specified. Load in the hash map. StringDictionary map = new StringDictionary(); foreach (XmlNode mapNode in node.ChildNodes) { if (mapNode.NodeType == XmlNodeType.Element) { if (mapNode.LocalName == Constants.ElementMap) { string fromValue = XmlNodeExtensions.GetRequiredAttribute(mapNode, Constants.AttrFrom, true); string toValue = XmlNodeExtensions.GetRequiredAttribute(mapNode, Constants.AttrTo, true); map.Add(fromValue, toValue); } else { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNotAllowed, mapNode.LocalName), node); } } } config.TransformFactory.AddTransform(new StaticMappingTransform(nameNode.Value, map)); }
/// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, RewriterConfiguration config) { if (node == null) { throw new ArgumentNullException("node"); } string to = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrTo, true); bool permanent = true; XmlNode permanentNode = node.Attributes.GetNamedItem(Constants.AttrPermanent); if (permanentNode != null) { if (!bool.TryParse(permanentNode.Value, out permanent)) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidBooleanAttribute, Constants.AttrPermanent), node); } } RedirectAction action = new RedirectAction(to, permanent); ParseConditions(node, action.Conditions, false, config); return(action); }
/// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, RewriterConfiguration config) { if (node == null) { throw new ArgumentNullException("node"); } if (config == null) { throw new ArgumentNullException("config"); } string cookieName = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrCookie); string cookieValue = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrValue, true); return(new SetCookieAction(cookieName, cookieValue)); }
/// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, RewriterConfiguration config) { if (node == null) { throw new ArgumentNullException("node"); } if (config == null) { throw new ArgumentNullException("config"); } string propertyName = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrProperty); string appSettingKey = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrKey); return(new SetAppSettingPropertyAction(propertyName, appSettingKey)); }
/// <summary> /// Parses the condition. /// </summary> /// <param name="node">The node to parse.</param> /// <returns>The condition parsed, or null if nothing parsed.</returns> public IRewriteCondition Parse(XmlNode node) { if (node == null) { throw new ArgumentNullException("node"); } XmlNode propertyAttr = node.Attributes.GetNamedItem(Constants.AttrProperty); if (propertyAttr == null) { return(null); } string match = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrMatch, true); return(new PropertyMatchCondition(propertyAttr.Value, match)); }
private static void ReadRegisterLogger(XmlNode node, RewriterConfiguration config) { if (node.ChildNodes.Count > 0) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node); } string type = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrLogger); // Logger type specified. Create an instance and add it // as the mapper handler for this map. IRewriteLogger logger = TypeHelper.Activate(type, null) as IRewriteLogger; if (logger != null) { config.Logger = logger; } }
private static void ReadRegisterTransform(XmlNode node, RewriterConfiguration config) { if (node.ChildNodes.Count > 0) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node); } string type = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrTransform); // Transform type specified. // Create an instance and add it as the mapper handler for this map. IRewriteTransform transform = TypeHelper.Activate(type, null) as IRewriteTransform; if (transform == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified, type, typeof(IRewriteTransform)), node); } config.TransformFactory.AddTransform(transform); }
/// <summary> /// Parses the node. /// </summary> /// <param name="node">The node to parse.</param> /// <param name="config">The rewriter configuration.</param> /// <returns>The parsed action, or null if no action parsed.</returns> public override IRewriteAction Parse(XmlNode node, RewriterConfiguration config) { if (node == null) { throw new ArgumentNullException("node"); } if (config == null) { throw new ArgumentNullException("config"); } string to = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrTo, true); XmlNode processingNode = node.Attributes[Constants.AttrProcessing]; RewriteProcessing processing = RewriteProcessing.ContinueProcessing; if (processingNode != null) { if (processingNode.Value == Constants.AttrValueRestart) { processing = RewriteProcessing.RestartProcessing; } else if (processingNode.Value == Constants.AttrValueStop) { processing = RewriteProcessing.StopProcessing; } else if (processingNode.Value != Constants.AttrValueContinue) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ValueOfProcessingAttribute, processingNode.Value, Constants.AttrValueContinue, Constants.AttrValueRestart, Constants.AttrValueStop), node); } } RewriteAction action = new RewriteAction(to, processing); ParseConditions(node, action.Conditions, false, config); return(action); }
private static void ReadErrorHandler(XmlNode node, RewriterConfiguration config) { string code = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrCode); XmlNode typeNode = node.Attributes[Constants.AttrType]; XmlNode urlNode = node.Attributes[Constants.AttrUrl]; if (typeNode == null && urlNode == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.AttributeRequired, Constants.AttrUrl), node); } IRewriteErrorHandler handler = null; if (typeNode != null) { // <error-handler code="500" url="/oops.aspx" /> handler = TypeHelper.Activate(typeNode.Value, null) as IRewriteErrorHandler; if (handler == null) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidTypeSpecified, typeNode.Value, typeof(IRewriteErrorHandler)), node); } } else { handler = new DefaultErrorHandler(urlNode.Value); } int statusCode; if (!Int32.TryParse(code, out statusCode)) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.InvalidHttpStatusCode, code), node); } config.ErrorHandlers.Add(statusCode, handler); }
private static void ReadRegisterParser(XmlNode node, RewriterConfiguration config) { if (node.ChildNodes.Count > 0) { throw new ConfigurationErrorsException(MessageProvider.FormatString(Message.ElementNoElements, Constants.ElementRegister), node); } string type = XmlNodeExtensions.GetRequiredAttribute(node, Constants.AttrParser); object parser = TypeHelper.Activate(type, null); IRewriteActionParser actionParser = parser as IRewriteActionParser; if (actionParser != null) { config.ActionParserFactory.AddParser(actionParser); } IRewriteConditionParser conditionParser = parser as IRewriteConditionParser; if (conditionParser != null) { config.ConditionParserPipeline.AddParser(conditionParser); } }