Ejemplo n.º 1
0
        public void TestTopicTree()
        {
            //因为树节点的测试类似,树从根开始,仅测试不同部分
            //测试无节点时的树根
            TopicTree <int> topicTree = new TopicTree <int>();

            Assert.Equal(".", topicTree.rootNode.Nodevalue);
            List <int> matchlist = topicTree.CollectMatches("#");

            Assert.Empty(matchlist);

            topicTree.Add(new Topic("work"), 20);

            topicTree.Add(new Topic("sport/ball/football"), 5);
            topicTree.Add(new Topic("sport/ball/longrun"), 6);
            topicTree.Add(new Topic("sport/run/longrun"), 8);
            topicTree.Add(new Topic("sport/run/shortrun"), 10);
            matchlist = topicTree.CollectMatches("#");
            Assert.Equal(5, matchlist.Count);
            matchlist = topicTree.CollectMatches("sport/#");
            Assert.Equal(4, matchlist.Count);
            matchlist = topicTree.CollectMatches("sport/+/longrun");
            Assert.Equal(2, matchlist.Count);

            topicTree.RemoveAll();
            matchlist = topicTree.CollectMatches("#");
            Assert.Empty(matchlist);
        }
Ejemplo n.º 2
0
        public static IHtmlString RenderTree(this HtmlHelper helper, TopicTree tree)
        {
            var writer = new HtmlTextWriter(new StringWriter());

            writer.RenderBeginTag(HtmlTextWriterTag.Ul);
            foreach (var section in tree.Sections)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Li);
                writer.Write(section.Name);
                if (section.Topics.Count > 0)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                    foreach (var topic in section.Topics)
                    {
                        writer.RenderBeginTag(HtmlTextWriterTag.Li);
                        WriteLink(writer, topic);
                        writer.RenderEndTag();
                    }
                    writer.RenderEndTag();
                }
                writer.RenderEndTag();
            }
            writer.RenderEndTag();

            return(MvcHtmlString.Create(writer.InnerWriter.ToString()));
        }
Ejemplo n.º 3
0
        public void Subscribe(Subscription subscription, PublishArrivedDelegate subscriber)
        {
            if (topicTree == null)
            {
                topicTree = new TopicTree <PublishArrivedDelegate>();
            }

            topicTree.Add(subscription.Topic, subscriber);

            // TODO: Check if we're already subscribed.
            Subscribe(subscription);
        }
Ejemplo n.º 4
0
        public void Subscribe(Subscription subscription, PublishArrivedDelegate subscriber)
        {
            if (topicTree == null)
              {
            topicTree = new TopicTree<PublishArrivedDelegate>();
              }

              topicTree.Add( subscription.Topic, subscriber);

              // TODO: Check if we're already subscribed.
              Subscribe(subscription);
        }
Ejemplo n.º 5
0
 public DocsController(TopicTree tree)
 {
     _tree = tree;
 }