示例#1
0
        public string FormattedTopic(QualifiedTopicRevision topic, OutputFormat fmt)
        {
            //initial version does not handle diffs
            string wikitext = "";
            string interpreted = "";
            _mgr = _fed.NamespaceManagerForNamespace(topic.Namespace);
            _topic = topic;
            WomDocument.ResetTableOfContents();
            WomDocument.anchors = new string[25];
            _processBehaviorToText = true;
            _behaviorTopic = topic;

            //Normally get data from the cache, but when debugging Womdocument need to avoid using cached data
            string wom = _mgr.GetTopicProperty(topic.AsUnqualifiedTopicRevision(), "_Wom").LastValue;
            //string wom = "";

            if (!String.IsNullOrEmpty(wom))
            {
                WomDocument xmldoc = new WomDocument(null);
                wom = findWikiBehavior.Replace(wom, new MatchEvaluator(wikiBehaviorMatch));
                xmldoc.ParsedDocument = findWikiBehavior.Replace(wom, new MatchEvaluator(wikiBehaviorMatch));

                if (findIncludedTopic.IsMatch(xmldoc.ParsedDocument))
                {
                    string included = xmldoc.ParsedDocument;
                    included = findIncludedTopic.Replace(included, new MatchEvaluator(wikiIncludedTopic));
                    xmldoc.ParsedDocument = included;
                }

                interpreted = xmldoc.ParsedDocument;
                xmldoc = null;
            }
            else
            {
                using (TextReader sr = _mgr.TextReaderForTopic(topic.AsUnqualifiedTopicRevision()))
                {
                    wikitext = sr.ReadToEnd() + "\r\n";
                }
                wikitext = escape(wikitext);
                int size = 0;
                while (String.IsNullOrEmpty(interpreted))
                {
                    try
                    {
                        string tempsize = _mgr.GetTopicProperty(topic.AsUnqualifiedTopicRevision(), "_ProcessTextSize").LastValue;
                        Int32.TryParse(tempsize, out size);
                        if (size == 0)
                        {
                            size = _chunk;
                        }
                        WomDocument xmldoc = ProcessText(wikitext, topic, _mgr, false, size);
                        //string womdoc = xmldoc.ParsedDocument;
                        _mgr.SetWomCache(topic.AsUnqualifiedTopicRevision(), xmldoc.ParsedDocument);
                        //string firstPass = findWikiBehavior.Replace(womdoc, new MatchEvaluator(wikiBehaviorMatch));
                        //xmldoc.ParsedDocument = findWikiBehavior.Replace(firstPass, new MatchEvaluator(wikiBehaviorMatch));
                        while (findWikiBehavior.IsMatch(xmldoc.ParsedDocument))
                        {
                            xmldoc.ParsedDocument = findWikiBehavior.Replace(xmldoc.ParsedDocument, new MatchEvaluator(wikiBehaviorMatch));
                        }

                        _behaviorTopic = null;

                        if (findIncludedTopic.IsMatch(xmldoc.ParsedDocument))
                        {
                            string included = xmldoc.ParsedDocument;
                            included = findIncludedTopic.Replace(included, new MatchEvaluator(wikiIncludedTopic));
                            xmldoc.ParsedDocument = included;
                        }

                        interpreted = xmldoc.ParsedDocument;
                        xmldoc = null;
                    }
                    catch (XmlException ex)
                    {
                        _mgr.SetProcessTextSize(topic.AsUnqualifiedTopicRevision(), size * (chunkcnt + 1));
                        string error = ex.ToString();
                    }
                }
            }
            _processBehaviorToText = false;
            return interpreted;
        }