Exemple #1
0
        public void TestRemove()
        {
            TagList list = new TagList();

            // Test first with up to 8 tags
            for (int i = 1; i <= 8; i++)
            {
                KeyValuePair <string, object?> kvp = new KeyValuePair <string, object?>("k" + i, "v" + i);
                list.Add(kvp);
                Assert.Equal(i, list.Count);
                Assert.True(list.Contains(kvp));
                Assert.Equal(i - 1, list.IndexOf(kvp));
            }

            // Now remove items

            int count = list.Count;

            for (int i = 1; i <= 8; i++)
            {
                KeyValuePair <string, object?> kvp = new KeyValuePair <string, object?>("k" + i, "v" + i);
                Assert.True(list.Remove(kvp));
                Assert.Equal(count - i, list.Count);
                Assert.False(list.Contains(kvp));
                Assert.Equal(-1, list.IndexOf(kvp));
            }

            Assert.Equal(0, list.Count);

            // Now we want to test more than 8 tags and test RemoveAt too
            for (int i = 1; i <= 20; i++)
            {
                KeyValuePair <string, object?> kvp1 = new KeyValuePair <string, object?>("k-" + i, "v" + i);
                KeyValuePair <string, object?> kvp2 = new KeyValuePair <string, object?>("k-" + i * 100, "v" + i * 100);
                KeyValuePair <string, object?> kvp3 = new KeyValuePair <string, object?>("k-" + i * 1000, "v" + i * 1000);

                // We add 3 then remove 2.
                list.Add(kvp1);
                list.Add(kvp2);
                list.Add(kvp3);

                // Now remove 1
                Assert.True(list.Contains(kvp3));
                Assert.True(list.Remove(kvp3));
                Assert.False(list.Contains(kvp3));

                int index = list.IndexOf(kvp2);
                Assert.True(index >= 0);
                Assert.True(list.Contains(kvp2));
                list.RemoveAt(index);
                Assert.False(list.Contains(kvp2));

                Assert.True(list.Contains(kvp1));
            }

            Assert.Equal(20, list.Count);
        }
Exemple #2
0
    /// <summary>
    /// Returns whether any tags in this taglist are present in <paramref name="other"/>
    /// </summary>
    public bool Overlaps(TagList other)
    {
        for (int i = 0; i < Count; i++)
        {
            if (other.Contains(this[i]))
            {
                return(true);
            }
        }

        return(false);
    }
Exemple #3
0
 public static void ClassLikeConstructorTest()
 {
     var tagList = new TagList("foo bar qux");
     Assert.IsTrue(tagList.Contains("foo"));
     Assert.IsTrue(tagList.Contains("bar"));
     Assert.IsTrue(tagList.Contains("qux"));
     Assert.IsFalse(tagList.Contains("baz"));
     Assert.IsFalse(tagList.Contains("fo"));
     Assert.IsFalse(tagList.Contains("whatever"));
 }
Exemple #4
0
 /// <summary>
 /// Tags the exists.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="category">The category.</param>
 /// <returns></returns>
 public bool TagExists(string name, string category = "")
 {
     return(TagList.Contains(new Tag(name, category)));
 }
        protected void SummaryListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                WebModuleInfo    module = (WebModuleInfo)e.Item.DataItem;
                WebpageInfo      page   = module.Webpage;
                MasterDetailItem item   = MasterDetailItem.GetSafeResource(module.Id);

                if (item != null)
                {
                    if (item.IsFeatured)
                    {
                        HtmlControl divSummary = (HtmlControl)e.Item.FindControl("divSummary");
                        if (divSummary != null)
                        {
                            divSummary.Attributes["class"] += " MasterDetail_ListItemFeatured";
                        }

                        HtmlControl trFeaturedHeader = (HtmlControl)e.Item.FindControl("trFeaturedHeader");
                        if (trFeaturedHeader != null)
                        {
                            trFeaturedHeader.Visible = item.IsFeatured;
                        }
                    }

                    Image         imgMain    = (Image)e.Item.FindControl("imgMain");
                    HtmlTableCell tdImageCol = (HtmlTableCell)e.Item.FindControl("tdImageCol");
                    imgMain.Visible = !string.IsNullOrEmpty(item.ImagePath);
                    if (imgMain.Visible)
                    {
                        imgMain.ImageUrl = ResolveUrl(string.Format("~/Image.ashx?File={0}&Size=100", item.ImagePath));
                    }
                    else
                    {
                        if (!_itemList.ShowImageIfBlank)
                        {
                            tdImageCol.Visible = false;
                        }
                    }

                    if (_itemList.IsPostDateVisible)
                    {
                        Label postDateCtl = (Label)e.Item.FindControl("lblPostDate");
                        if (page.PostDate.HasValue)
                        {
                            postDateCtl.Text = page.PostDate.Value.ToLongDateString();
                        }
                    }

                    HyperLink hypTitle = (HyperLink)e.Item.FindControl("hypTitle");
                    hypTitle.NavigateUrl = ResolveUrl(page.Path);
                    hypTitle.Text        = MasterDetailItem.Chop(page.Text, 150, true);

                    HyperLink hypReadMore = (HyperLink)e.Item.FindControl("hypReadMore");
                    hypReadMore.NavigateUrl = ResolveUrl(page.Path);

                    Literal litSummary = (Literal)e.Item.FindControl("litSummary");
                    litSummary.Text = item.GetSummary(page);

                    if (item.Tags != null)
                    {
                        // Build unique list of tags for all articles in the summary display
                        string[] tagArray = item.Tags.Split(',');
                        foreach (var s in tagArray)
                        {
                            if (!TagList.Contains(s))
                            {
                                TagList.Add(s);
                            }
                        }
                    }
                }
                else
                {
                    e.Item.Visible = false;
                }
            }
        }
 public bool ContainsType(TagType type)
 {
     return(tags.Contains(type));
 }