private static void FillRule(RewriteRuleSettings settings, ConfigurationElement rule) { rule["name"] = settings.Name; rule["patternSyntax"] = settings.PatternSintax; rule["stopProcessing"] = settings.StopProcessing; var match = rule.ChildElements["match"]; match["url"] = settings.Pattern; match["negate"] = settings.NegatePattern; match["ignoreCase"] = settings.IgnoreCase; }
/// <summary> /// Creates a rewrite rule /// </summary> /// <param name="settings">The settings of the rewrite rule to add</param> /// <returns>If the rewrite rule was added.</returns> public void CreateRule(RewriteRuleSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (string.IsNullOrWhiteSpace(settings.Name)) { throw new ArgumentException($"{nameof(settings.Name)} cannot be null!"); } if (settings.Action == null) { throw new ArgumentException($"{nameof(settings.Action)} cannot be null!"); } if (Exists(settings.Name)) { _Log.Information($"Rewrite rule '{settings.Name}' already exists."); return; } var globalRules = GetGlobalRewriteRules(); var rule = globalRules.CreateElement("rule"); FillRule(settings, rule); if (settings.Conditions?.Any() == true) { FillConditions(settings, rule); } settings.Action.FillXmlConfig(rule.ChildElements["action"]); globalRules.Add(rule); _Server.CommitChanges(); _Log.Information($"Rewrite rule '{settings.Name}' created."); }
private static void FillConditions(RewriteRuleSettings settings, ConfigurationElement rule) { var conditions = rule.ChildElements["conditions"]; conditions["logicalGrouping"] = settings.ConditionsGrouping; var conditionsCollection = conditions.GetCollection(); foreach (var condition in settings.Conditions) { var conditionsXml = conditionsCollection.CreateElement("add"); conditionsXml["input"] = condition.ConditionInput; conditionsXml["pattern"] = condition.Pattern; conditionsXml["negate"] = condition.NegatePattern; conditionsXml["ignoreCase"] = condition.IgnoreCase; conditionsCollection.Add(conditionsXml); } }
public static void CreateRewriteRule(this ICakeContext context, string server, RewriteRuleSettings settings) { using (ServerManager manager = BaseManager.Connect(server)) { RewriteManager .Using(context.Environment, context.Log, manager) .CreateRule(settings); } }
public static void CreateRewriteRule(this ICakeContext context, RewriteRuleSettings settings) { context.CreateRewriteRule("", settings); }