Exemplo n.º 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);
        }
Exemplo n.º 2
0
        // IReplacementWatcher
        // ........................................................................

        public override void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            if (watchers != null)
            {
                watchers.TagWillBeReplaced(tag, data);
            }
        }
Exemplo n.º 3
0
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     foreach (ITagReplacementWatcher watcher in this)
     {
         watcher.TagWillBeReplaced(tag, data);
     }
 }
Exemplo n.º 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 ? "." : ""
                                 ));
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 7
0
 public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null)
     {
         return(watchers.TagHasBeenReplaced(replacement, tag, data));
     }
     else
     {
         return(replacement);
     }
 }
Exemplo n.º 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));
         }
     }
 }
Exemplo n.º 9
0
 // IReplacementWatcher
 // ........................................................................
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     if (watchers != null) watchers.TagWillBeReplaced(tag, data);
 }
Exemplo n.º 10
0
 public string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null) return watchers.TagHasBeenReplaced(replacement, tag, data);
       else return replacement;
 }
Exemplo n.º 11
0
        public virtual void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            Datum valueToSet = (expression != null) ? expression.Evaluate(data) : new NumericDatum(1);

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

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