Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // render a tag cloud

            int count;              // the number of blog entries per tag
            int min      = 0;       // the lowest count in the cloud
            int max      = 0;       // the highest count in the cloud
            int maxStyle = 6;       // the highest css style to apply to the tag links
            int loop     = 0;       // index for determining min and max


            // get the list of tags for which there is at least one blog entry
            List <Tag> usedTags = TagManager.GetListUsedTags();

            // loop through each of the tags to determine the minimum and maximum count
            foreach (Tag t in usedTags)
            {
                // get the count for the current tag
                count = TagManager.CountByTag(t.id);
                // if current count higher than max, set max to current count
                max = (count > max ? count : max);
                // if min is not initialized yet, set it to the first count
                // we need to do this because we cannot initialize min at 0
                // as no counts will be lower than 0
                if (loop == 0)
                {
                    min = count;
                }
                else
                {
                    // if current count lower than min, set min to current count
                    min = (count < min ? count : min);
                }
                loop++;
            }

            // with min and max calculated, we can now concatenate the tag cloud string
            string strCloud = "";

            foreach (Tag t in usedTags)
            {
                count = TagManager.CountByTag(t.id);

                strCloud += "<a href=\"BlogByTag.aspx?tag=" + t.id.ToString() + "\" class=\"tag" +
                            GetSizeByCount(count, min, max, maxStyle).ToString() + "\">" + t.tagname + "</a>&nbsp;";
            }

            // output the tag cloud
            LabelTagCloud.Text = strCloud;
        }