Ejemplo n.º 1
0
        public string ProcessContent(string text, string flavor)
        {
            if (!string.IsNullOrEmpty(text))
            {
                _rules = _service.GetRewriteRules();
                if (_rules.Enabled)
                {
                    switch (flavor)
                    {
                        case "html":
                            text = ProcessHtml(text);
                            break;
                        case "text":
                            text = ProcessText(text);
                            break;
                    }

                }
            }
            return text;
        }
Ejemplo n.º 2
0
 private LinkRewriteRuleCollection ParseRewriteRules()
 {
     var settings = _context.CurrentSite.As<LinkRewriteSettingsPart>();
     LinkRewriteRuleCollection rules = new LinkRewriteRuleCollection(settings == null ? false : settings.Enabled);
     if (rules.Enabled)
     {
         string[] rawRules = settings.Rules.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
         char[] delimiter = { '=', '>' };
         foreach (string rawRule in rawRules)
         {
             string[] tokens = rawRule.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
             if (tokens.Length == 2)
             {
                 LinkRewriteRule rule = new LinkRewriteRule(tokens[0].Trim(), tokens[1].Trim());
                 if (ValidateRegEx(rule.Pattern))
                 {
                     rules.Add(rule);
                 }
                 else
                 {
                     rules.Clear();
                     throw new ArgumentException(T("The rewrite rule '{0}' is not a valid regular expression.", rule.Pattern).Text, "Pattern");
                 }
             }
             else
             {
                 rules.Clear();
                 throw new ArgumentException(T("The rewrite rule '{0}' is not in the expected format of 'regex=>target'.", rawRule).Text, "Rule");
             }
         }
     }
     return rules;
 }