Exemple #1
0
        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);
        }
Exemple #2
0
        // IReplacementWatcher
        // ........................................................................

        public override void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            if (watchers != null)
            {
                watchers.TagWillBeReplaced(tag, data);
            }
        }
Exemple #3
0
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     foreach (ITagReplacementWatcher watcher in this)
     {
         watcher.TagWillBeReplaced(tag, data);
     }
 }
Exemple #4
0
        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 ? "." : ""
                                 ));
        }
Exemple #5
0
 public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     try {
         float number = float.Parse(replacement);
         return(GenerateTextFromNumber(number));
     } catch (FormatException) {
         return(replacement);
     }
 }
Exemple #6
0
 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);
 }
Exemple #7
0
 public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null)
     {
         return(watchers.TagHasBeenReplaced(replacement, tag, data));
     }
     else
     {
         return(replacement);
     }
 }
Exemple #8
0
 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));
         }
     }
 }
Exemple #9
0
 // IReplacementWatcher
 // ........................................................................
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     if (watchers != null) watchers.TagWillBeReplaced(tag, data);
 }
Exemple #10
0
 public string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null) return watchers.TagHasBeenReplaced(replacement, tag, data);
       else return replacement;
 }
Exemple #11
0
        public virtual void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            Datum valueToSet = (expression != null) ? expression.Evaluate(data) : new NumericDatum(1);

            data.Set(dataName, valueToSet);
        }
Exemple #12
0
 public virtual string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     return(string.Empty);
 }
Exemple #13
0
 public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     data.Set(dataName, (Datum)oldValue);
     oldValue = null;
     return(replacement);
 }
Exemple #14
0
 public override void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     oldValue = data.Get(dataName);
     base.TagWillBeReplaced(tag, data);
 }
Exemple #15
0
        // IReplacementWatcher
        // ........................................................................

        public abstract void TagWillBeReplaced(TagBase tag, Namespace data);
Exemple #16
0
 public virtual void TagWillBeReplaced(TagBase tag, Namespace data)
 {
 }
Exemple #17
0
 public abstract string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data);
Exemple #18
0
 public virtual string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     data.Set(dataName, replacement);
     return(replacement);
 }