private BBCodeInterpreter LoadBBCodeInterpreter() { string dataKey = "BBCode"; lock (this.skinCache) { var value = (BBCodeInterpreter)this.skinCache[dataKey]; if (value == null) { Trace.WriteLine(@"Cache Miss: " + dataKey); XmlDocument doc = new XmlDocument(); using (var reader = new StreamReader(Path.Combine(this.skinsDirectory, "BBCode.xml"))) { doc.Load(reader); } value = new BBCodeInterpreter(doc); this.skinCache.Add(dataKey, value, CacheItemPriority.Normal, null, new AbsoluteTime(new TimeSpan(3, 0, 0)), new SlidingTime(new TimeSpan(1, 0, 0))); } else { Trace.WriteLine(@"Cache Hit: " + dataKey); } return(value); } }
public void Interpret_WhenClosingTagsAreOutOfOrder_ClosedAllTagsReopeningAsNecessary() { var doc = new XmlDocument(); doc.LoadXml(@"<bbcode> <tags> <tag name=""A"" type=""normal"" parameter=""false""> <open><![CDATA[A]]></open> <close><![CDATA[a]]></close> </tag> <tag name=""B"" type=""normal"" parameter=""false""> <open><![CDATA[B]]></open> <close><![CDATA[b]]></close> </tag> </tags> </bbcode>"); var bbc = new BBCodeInterpreter(doc); var output = bbc.Interpret("[A][B]c[/A][/B]"); Assert.That(output, Is.EqualTo("ABcbaBb")); }
public void Interpret_WhenChildTagIsLeftOpen_ClosedChildTag() { var doc = new XmlDocument(); doc.LoadXml(@"<bbcode> <tags> <tag name=""A"" type=""newcontext"" parameter=""false""> <open><![CDATA[A]]></open> <close><![CDATA[a]]></close> </tag> <tag name=""B"" type=""normal"" parameter=""false""> <open><![CDATA[B]]></open> <close><![CDATA[b]]></close> </tag> </tags> </bbcode>"); var bbc = new BBCodeInterpreter(doc); var output = bbc.Interpret("[A][B]c[/A]"); Assert.That(output, Is.EqualTo("ABcba")); }