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); }
// IReplacementWatcher // ........................................................................ public override void TagWillBeReplaced(TagBase tag, Namespace data) { if (watchers != null) { watchers.TagWillBeReplaced(tag, data); } }
public void TagWillBeReplaced(TagBase tag, Namespace data) { foreach (ITagReplacementWatcher watcher in this) { watcher.TagWillBeReplaced(tag, data); } }
public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { if (replacement.Length <= 0) { return(replacement); } bool replaceLast = false; bool addPeriod = true; switch (replacement[replacement.Length - 1]) { case ';': case ':': case ',': case '-': replaceLast = true; break; case '?': case '.': case '!': addPeriod = false; break; } return(string.Format("{0}{1}{2}", replacement[0].ToString().ToUpper(), replacement.Substring(1, replacement.Length - (replaceLast ? 2 : 1)), addPeriod ? "." : "" )); }
public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { try { float number = float.Parse(replacement); return(GenerateTextFromNumber(number)); } catch (FormatException) { return(replacement); } }
public string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { for (int i = Count - 1; i >= 0; --i) { ITagReplacementWatcher watcher = this[i]; replacement = watcher.TagHasBeenReplaced(replacement, tag, data); } return(replacement); }
public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { if (watchers != null) { return(watchers.TagHasBeenReplaced(replacement, tag, data)); } else { return(replacement); } }
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)); } } }
// IReplacementWatcher // ........................................................................ public void TagWillBeReplaced(TagBase tag, Namespace data) { if (watchers != null) watchers.TagWillBeReplaced(tag, data); }
public string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { if (watchers != null) return watchers.TagHasBeenReplaced(replacement, tag, data); else return replacement; }
public virtual void TagWillBeReplaced(TagBase tag, Namespace data) { Datum valueToSet = (expression != null) ? expression.Evaluate(data) : new NumericDatum(1); data.Set(dataName, valueToSet); }
public virtual string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { return(string.Empty); }
public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { data.Set(dataName, (Datum)oldValue); oldValue = null; return(replacement); }
public override void TagWillBeReplaced(TagBase tag, Namespace data) { oldValue = data.Get(dataName); base.TagWillBeReplaced(tag, data); }
// IReplacementWatcher // ........................................................................ public abstract void TagWillBeReplaced(TagBase tag, Namespace data);
public virtual void TagWillBeReplaced(TagBase tag, Namespace data) { }
public abstract string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data);
public virtual string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data) { data.Set(dataName, replacement); return(replacement); }