protected string FireRuleOnTag(RuleBase ruleToFire, Tag tagToReplace, Namespace data) { ruleToFire.TagWillBeReplaced(tagToReplace, data); tagToReplace.TagWillBeReplaced(tagToReplace, data); // Recursively generate any content. Content content = ruleToFire.Fire(tagToReplace, data); StringBuilder builder = new StringBuilder(); foreach (ContentItem item in content) { if (item.IsTag) { TagBase tagItem = item as TagBase; builder.Append(Run(tagItem, data)); } else { builder.Append(item.ToString()); } } string result = builder.ToString(); // Filter back through tag and root result = tagToReplace.TagHasBeenReplaced(result, tagToReplace, data); result = ruleToFire.TagHasBeenReplaced(result, tagToReplace, data); return(result); }
public void Add(RuleBase rule) { Tag tag = rule.Tag; if (!rules.ContainsKey(tag)) { rules[tag] = new SortedSet <RuleBase>(); } rules[tag].Add(rule); }
public string Run(TagBase tag, Namespace data = null) { if (!tag.IsRecursive) { return(RunNonRecursiveTag(tag as NonRecursiveTag, data)); } else { Tag tagToReplace = tag as Tag; MatchingRules matchingRules = FindRulesThatCanFire(tagToReplace, data); if (matchingRules.Count == 0) { return(tagToReplace.ToString()); } else { RuleBase ruleToFire = matchingRules.ChooseRuleToFire(random); return(FireRuleOnTag(ruleToFire, tagToReplace, data)); } } }