コード例 #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);
        }
コード例 #2
0
        // IReplacementWatcher
        // ........................................................................

        public override void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            if (watchers != null)
            {
                watchers.TagWillBeReplaced(tag, data);
            }
        }
コード例 #3
0
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     foreach (ITagReplacementWatcher watcher in this)
     {
         watcher.TagWillBeReplaced(tag, data);
     }
 }
コード例 #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 ? "." : ""
                                 ));
        }
コード例 #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);
     }
 }
コード例 #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);
 }
コード例 #7
0
 public override string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null)
     {
         return(watchers.TagHasBeenReplaced(replacement, tag, data));
     }
     else
     {
         return(replacement);
     }
 }
コード例 #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));
         }
     }
 }
コード例 #9
0
ファイル: Tag.cs プロジェクト: Mofangbao/gnoam
 // IReplacementWatcher
 // ........................................................................
 public void TagWillBeReplaced(TagBase tag, Namespace data)
 {
     if (watchers != null) watchers.TagWillBeReplaced(tag, data);
 }
コード例 #10
0
ファイル: Tag.cs プロジェクト: Mofangbao/gnoam
 public string TagHasBeenReplaced(string replacement, TagBase tag, Namespace data)
 {
     if (watchers != null) return watchers.TagHasBeenReplaced(replacement, tag, data);
       else return replacement;
 }
コード例 #11
0
        public virtual void TagWillBeReplaced(TagBase tag, Namespace data)
        {
            Datum valueToSet = (expression != null) ? expression.Evaluate(data) : new NumericDatum(1);

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

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