コード例 #1
0
ファイル: TagBR.cs プロジェクト: bsimser/dotnetkicks
        public static WeightedTagList AddUserStoryTags(string tagString, User user, int storyID, int hostID)
        {
            WeightedTagList tags = GetOrInsertTags(tagString, user.IsAdministrator);

            StoryUserHostTagCollection storyUserHostTags = new StoryUserHostTagCollection();

            foreach (WeightedTag tag in tags)
            {
                StoryUserHostTag storyUserHostTag = new StoryUserHostTag(); //TODO: GJ: move to WeightedTag.ToStoryUserHostTag()
                storyUserHostTag.StoryID = storyID;
                storyUserHostTag.HostID  = hostID;
                storyUserHostTag.UserID  = user.UserID;
                storyUserHostTag.TagID   = tag.TagID;
                storyUserHostTags.Add(storyUserHostTag);
                StoryCache.ClearUserTaggedStories(tag.TagName, user.UserID, storyID);
            }

            storyUserHostTags.BatchSave();

            UserAction.RecordTag(hostID, user, Story.FetchByID(storyID), tags);

            //when a user adds a tag, we need to mark the story as updated
            //so update the index during the incremental crawl
            Story story = Story.FetchByID(storyID);

            story.UpdatedOn = DateTime.Now;
            story.Save();

            return(tags);
        }
コード例 #2
0
        public void GetTagFontSizeTests_Exceptions(double minTagSize, double maxTagSize, double totalTagUsageCount, double tagUsageCount)
        {
            //double result = WeightedTagList.GetTagFontSize(-11, 2, 25, 25);
            double result = WeightedTagList.GetTagFontSize(minTagSize, maxTagSize, totalTagUsageCount, tagUsageCount);

            Assert.Fail("Exception not thrown");
        }
コード例 #3
0
ファイル: TagBR.cs プロジェクト: bsimser/dotnetkicks
        public static WeightedTagList GetOrInsertTags(string tagString, bool isAdministrator)
        {
            List <string> rawTags = TagHelper.DistillTagInput(tagString, isAdministrator);

            WeightedTagList tags    = new WeightedTagList();
            TagCollection   newTags = new TagCollection();

            foreach (string tagIdentifier in rawTags)
            {
                //TODO: GJ: get from cache
                Tag tag = Tag.FetchTagByIdentifier(tagIdentifier);

                if (tag == null)
                {
                    tag = new Tag();
                    tag.TagIdentifier = tagIdentifier;
                    newTags.Add(tag);
                }
                else
                {
                    tags.Add(new WeightedTag(tag.TagID, tag.TagIdentifier, 1));
                }
            }

            // newTags.BatchSave(); //TODO: GJ: does BatchSave update identity colums after save?

            foreach (Tag newTag in newTags)
            {
                newTag.Save(); //TODO: GJ: does BatchSave update identity colums after save?
                tags.Add(new WeightedTag(newTag.TagID, newTag.TagIdentifier, 1));
            }

            return(tags);
        }
コード例 #4
0
ファイル: TagBR.cs プロジェクト: Letractively/dotnetkicks
        public static WeightedTagList GetOrInsertTags(string tagString, bool isAdministrator)
        {
            List<string> rawTags = TagHelper.DistillTagInput(tagString, isAdministrator);

            WeightedTagList tags = new WeightedTagList();
            TagCollection newTags = new TagCollection();
            foreach (string tagIdentifier in rawTags) {
                //TODO: GJ: get from cache
                Tag tag = Tag.FetchTagByIdentifier(tagIdentifier);

                if (tag == null) {
                    tag = new Tag();
                    tag.TagIdentifier = tagIdentifier;
                    newTags.Add(tag);
                } else {
                    tags.Add(new WeightedTag(tag.TagID, tag.TagIdentifier, 1));
                }
            }

            // newTags.BatchSave(); //TODO: GJ: does BatchSave update identity colums after save?

            foreach (Tag newTag in newTags) {
                newTag.Save(); //TODO: GJ: does BatchSave update identity colums after save?
                tags.Add(new WeightedTag(newTag.TagID, newTag.TagIdentifier, 1));
            }

            return tags;
        }
コード例 #5
0
        public WeightedTagList ToWeightedTagList()
        {
            WeightedTagList weightedTagList = new WeightedTagList();
            foreach (Tag tag in this)
                weightedTagList.AddWeightedTag(new WeightedTag(tag.TagID, tag.TagIdentifier, 1));

            return weightedTagList;
        }
コード例 #6
0
        public string TagStory(int storyID, string tagString)
        {
            DemandUserAuthentication();
            WeightedTagList     tags        = TagBR.AddUserStoryTags(tagString, KickUserProfile, storyID, HostProfile.HostID);
            UserEditableTagList userTagList = new UserEditableTagList();

            userTagList.DataBind(tags, storyID, KickUserProfile.Username);
            return(ControlHelper.RenderControl(userTagList));
        }
コード例 #7
0
        public string GetUserStoryTags(int storyID)
        {
            DemandUserAuthentication();
            WeightedTagList     tags        = Tag.FetchUserStoryTags(KickUserProfile.UserID, storyID).ToWeightedTagList();
            UserEditableTagList userTagList = new UserEditableTagList();

            userTagList.DataBind(tags, storyID, KickUserProfile.Username);
            return(ControlHelper.RenderControl(userTagList));
        }
コード例 #8
0
        public void GetTagFontSizeTests_Defaults(double minTagSize, double maxTagSize, double totalTagUsageCount, double tagUsageCount)
        {
            if (minTagSize == 0.0d)
            {
                return;                     // goddamnit
            }
            double result = WeightedTagList.GetTagFontSize(minTagSize, maxTagSize, totalTagUsageCount, tagUsageCount);

            Assert.AreEqual(maxTagSize, result, "Defaults failed; expected {0} got {1}", maxTagSize, result);
        }
コード例 #9
0
ファイル: TagCollection.cs プロジェクト: bsimser/dotnetkicks
        public WeightedTagList ToWeightedTagList()
        {
            WeightedTagList weightedTagList = new WeightedTagList();

            foreach (Tag tag in this)
            {
                weightedTagList.AddWeightedTag(new WeightedTag(tag.TagID, tag.TagIdentifier, 1));
            }

            return(weightedTagList);
        }
コード例 #10
0
        public static UserAction RecordTag(int hostID, User user, Story story, WeightedTagList tags)
        {
            UserAction userAction = Create(hostID, user.UserID, story.StoryID, ActionType.Tag);

            if (tags.Count > 0)
            {
                TagCommaList tagList = new TagCommaList();
                tagList.DataBind(tags, story.StoryID, false);

                userAction.Message = String.Format("tagged {0} with {1}", GetStoryLink(story), ControlHelper.RenderControl(tagList));
                userAction.Save();
            }
            return(userAction);
        }
コード例 #11
0
        public static WeightedTagList GetStoryTags(int storyID)
        {
            string cacheKey = GetCacheKey("StoryTags", storyID);
            CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache();

            WeightedTagList tags = tagCache[cacheKey];

            if (tags == null)
            {
                tags = Tag.FetchStoryTags(storyID).ToWeightedTagList();
                //TODO: GJ: sort by alpha
                tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(tags);
        }
コード例 #12
0
        public static WeightedTagList GetHostTags(int hostID, DateTime createdOnLower, DateTime createdOnUpper)
        {
            string cacheKey = GetCacheKey("HostTags", hostID, createdOnLower, createdOnUpper);
            CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache();

            WeightedTagList tags = tagCache[cacheKey];

            if (tags == null)
            {
                tags = Tag.FetchTags(hostID, createdOnLower, createdOnUpper).ToWeightedTagList();
                //TODO: GJ: sort by alpha
                tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(tags);
        }
コード例 #13
0
        public static WeightedTagList GetUserHostTags(int userID, int hostID)
        {
            string cacheKey = String.Format("UserHostTags_{0}_{1}", userID, hostID);
            CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache();

            WeightedTagList tags = tagCache[cacheKey];

            if (tags == null)
            {
                tags = Tag.FetchTags(userID, hostID).ToWeightedTagList();
                //TODO: GJ: sort by alpha
                tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(tags);
        }
コード例 #14
0
        public static WeightedTagList GetTopHostTags(int hostID, int numberOfTags)
        {
            string cacheKey = String.Format("TopHostTags_{0}_{1}", hostID, numberOfTags);
            CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache();

            WeightedTagList tags = tagCache[cacheKey];

            if (tags == null)
            {
                tags = GetHostTags(hostID);
                tags.Sort(new WeightedTagList.UsageCountComparer());
                tags = tags.GetTopTags(numberOfTags);
                tags.Sort(new WeightedTagList.AlphabeticalComparer());
                tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS);
            }

            return(tags);
        }
コード例 #15
0
        /// <summary>
        /// Renders the full story summary.
        /// </summary>
        /// <param name="writer">The writer.</param>
        protected void RenderFullSummary(HtmlTextWriter writer)
        {
            Category category     = CategoryCache.GetCategory(_story.CategoryID, KickPage.HostProfile.HostID);
            string   kickStoryUrl =
                UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, _story.StoryIdentifier, category.CategoryIdentifier);

            string categoryUrl    = UrlFactory.CreateUrl(UrlFactory.PageName.ViewCategory, category.CategoryIdentifier);
            string kickCountClass = GetKickCountClass();

            bool isKicked = UserCache.HasUserKickedStory(_story.StoryID, KickPage.KickUserProfile.UserID);

            string kickItCssClass = "visible";
            string kickedCssClass = "hidden";

            if (isKicked)
            {
                kickItCssClass = "hidden";
                kickedCssClass = "visible";
            }

            string adminHtml = "";

            string tableClass = "storySummaryTable storySummaryTable";

            if (_isOddRow)
            {
                tableClass += "Odd";
            }
            else
            {
                tableClass += "Even";
            }

            //TODO: remove inline style from table
            // Render kick it side image
            writer.WriteLine(
                @"<div id =""m_{3}"" class=""u_{9}"">
                <table class=""" + tableClass +
                @"""><tr>
                    <td class=""storySummaryKickTD"">
                        <div class=""storyKickCount {2}""><a href=""{0}""><span id=""{3}_KickCount"">{1}</span></a><br /><span class=""smallText"">kicks</span></div>
                        <div class=""storyKickIt {4}"" id=""{3}_KickIt""><a href=""javascript:KickIt({3}, {6});"">
                            kick it</a></div>
                        <div class=""storyKicked {5}"" id=""{3}_UnKickIt""><a href=""javascript:UnKickIt({3});"">kicked</a></div>
                    {8}</td>
            ",
                kickStoryUrl, _story.KickCount, kickCountClass, _story.StoryID, kickItCssClass, kickedCssClass,
                KickPage.User.Identity.IsAuthenticated.ToString().ToLower(), KickPage.StaticIconRootUrl, adminHtml, _story.UserID);

            string publishedHtml  = "";
            string linkAttributes = "";

            // Create published date string
            if (_story.IsPublishedToHomepage)
            {
                publishedHtml = "published " + Dates.ReadableDiff(_story.PublishedOn, DateTime.Now) + ", ";
            }
            else
            {
                linkAttributes = "rel=\"nofollow\"";
            }

            //TODO: remove inline style from table
            // Render submitted by link
            writer.WriteLine(
                @"
                    <td class=""storySummaryMainTD xfolkentry""><table width=""100%"" class=""WideTable"" cellpadding=""0"" cellspacing=""0""><tr><td valign=""top"">
                        <div class=""storyTitle""><a class=""taggedlink"" onclick=""plusViewCount({5});"" href=""{0}"" {4}>{1}</a> <a href=""{0}""><img onclick=""plusViewCount({5});"" src=""{3}/external.png"" width=""10"" height=""10"" border=""0""/></a></div>
                        <div class=""storySubmitted"">{2} submitted by ",
                _story.Url, _story.Title, publishedHtml, KickPage.StaticIconRootUrl, linkAttributes, _story.StoryID);

            // Render user link
            UserLink userLink = new UserLink();

            userLink.DataBind(UserCache.GetUser(_story.UserID));
            userLink.RenderControl(writer);
            string hostname = GetHostName(_story.Url);
            // Render read more link
            string moreLink = "";

            if (ShowMoreLink)
            {
                moreLink = String.Format(@" <a href=""{0}"" onclick=""javascript:plusViewCount({1});"">read more...</a>", kickStoryUrl, _story.StoryID);
            }
            // Rended add comment/number of comments link
            writer.WriteLine(
                @"
                {0}</div>
        
                        <p class=""description"">{1}</p>

                        <div class=""storyActions"">
                            <a href=""{2}"" class=""commentsLink"">
            ",
                Dates.ReadableDiff(_story.CreatedOn, DateTime.Now), hostname + _story.Description + moreLink, kickStoryUrl);

            writer.WriteLine(@"<img src=""{0}/comment.png"" alt=""Add a comment"" width=""16"" height=""16"" border=""0"" /> ",
                             KickPage.StaticIconRootUrl);

            if (_story.CommentCount == 0)
            {
                writer.WriteLine(@"<a href=""{0}#comments"">add a comment</a>", kickStoryUrl);
            }
            else if (_story.CommentCount == 1)
            {
                writer.WriteLine(@"<a href=""{0}#comments"">1 comment</a>", kickStoryUrl);
            }
            else
            {
                writer.WriteLine(@"<a href=""{0}#comments"">{1} comments</a>", kickStoryUrl, _story.CommentCount);
            }

            // Render category html
            string categoryIcon = "";

            if (category.IconNameSpecified)
            {
                categoryIcon =
                    String.Format(@"<a href=""{0}""><img src=""{1}/{2}"" width=""16"" height=""16"" border=""0"" /></a>",
                                  categoryUrl, KickPage.StaticIconRootUrl, category.IconName);
            }
            writer.WriteLine(@" | 
                category: {0} <a href=""{1}"" rel=""tag"">{2}</a> | Views: {3}", categoryIcon, categoryUrl,
                             category.Name, _story.ViewCount);

            // Render Get Kick Image html
            if (_showGetKickImageCodeLink)
            {
                writer.WriteLine(@" | <a href=""javascript:;"" onclick=""$('#kickImagePersonalization').toggle();"">Get KickIt image code</a>");
            }

            // Render report as spam link
            if (KickPage.IsAuthenticated)
            {
                writer.WriteLine(
                    @" | <span class=""ReportAsSpamLink""><a href=""javascript:ReportAsSpam({0});"">report as spam</a></span>",
                    _story.StoryID);
            }


            // Render delete story link
            if (KickPage.IsHostModerator)
            {
                string deleteText = "delete";
                string banText    = "ban";
                if (_story.SpamCount > 0)
                {
                    deleteText += " (spam count is " + _story.SpamCount + ")";
                }
                if (_story.IsSpam)
                {
                    writer.WriteLine(
                        @" |
                    <span class=""ModeratorLink""><a href=""javascript:UnDelete({0});"">{1}</a></span>
                    ",
                        _story.StoryID, "un" + deleteText);
                }
                else
                {
                    writer.WriteLine(
                        @" |
                    <span class=""ModeratorLink""><a href=""javascript:Delete({0});"">{1}</a></span>
                     |
                    <span class=""BanLink""><a href=""javascript:Ban({2});"">{3}</a></span>
                    ",
                        _story.StoryID, deleteText, _story.UserID, banText);
                }
            }


            // Render story thumbnail
            //writer.WriteLine(@"</td><td width=""94""><a href=""http://{0}""><img src=""http://thumboo.com/?size=t&url={0}"" width=""92"" height=""70"" class=""Thumbnail"" /></a></td></tr></table>", this._storyRow.Url.Replace("http://", ""));
            // writer.WriteLine(@"</td><td width=""94""><a href=""{0}""><img src=""http://images.websnapr.com/?size=t&url={0}"" width=""92"" height=""70"" class=""Thumbnail"" /></a></td></tr></table>", this._story.Url);
            if (!KickPage.IsAuthenticated || KickPage.KickUserProfile.ShowStoryThumbnail)
            {
                writer.WriteLine(
                    @"</td><td width=""94""><a onclick=""javascript:plusViewCount({2});"" href=""{0}""><img src=""http://dotnetkicks.kwiboo.com/getimage.aspx?size=thumb&url={1}"" width=""92"" height=""70"" class=""Thumbnail"" /></a>",
                    _story.Url, HttpUtility.UrlEncode(_story.Url), _story.StoryID);
            }

            writer.WriteLine(@"</td></tr></table>", _story.Url);

            // Render tag list html
            writer.WriteLine(@"<span class=""TagListSummary"">");
            WeightedTagList tags = TagCache.GetStoryTags(_story.StoryID);

            tags.Sort(new WeightedTagList.UsageCountComparer());
            TagCommaList tagCommaList = new TagCommaList();

            Controls.Add(tagCommaList);
            tagCommaList.DataBind(tags.GetTopTags(5), _story.StoryID);
            tagCommaList.RenderControl(writer);
            writer.WriteLine(@"</span>");

            writer.WriteLine("</div><br /><br />");

            tags.Sort(new WeightedTagList.AlphabeticalComparer());
            StoryTagList storyTagList = new StoryTagList();

            Controls.Add(storyTagList);
            storyTagList.DataBind(tags, _story.StoryID);
            storyTagList.RenderControl(writer);

            writer.WriteLine("</td></tr></table></div>");
        }
コード例 #16
0
 public void DataBind(WeightedTagList tags, int storyID, string username)
 {
     this._tags     = tags;
     this._storyID  = storyID;
     this._username = username;
 }
コード例 #17
0
ファイル: TagCommaList.cs プロジェクト: bsimser/dotnetkicks
 public void DataBind(WeightedTagList tags, int storyID)
 {
     this.DataBind(tags, storyID, true);
 }
コード例 #18
0
 public void GetTagFontSizeTests_CorrectValues(double minTagSize, double maxTagSize, double totalTagUsageCount, double tagUsageCount, double expected)
 {
     Assert.AreEqual(expected, WeightedTagList.GetTagFontSize(minTagSize, maxTagSize, totalTagUsageCount, tagUsageCount));
 }
コード例 #19
0
ファイル: TagCommaList.cs プロジェクト: bsimser/dotnetkicks
 public void DataBind(WeightedTagList tags, int storyID, bool showTagIt)
 {
     this._tags      = tags;
     this._storyID   = storyID;
     this._showTagIt = showTagIt;
 }
コード例 #20
0
        public static UserAction RecordTag(int hostID, User user, Story story, WeightedTagList tags)
        {
            UserAction userAction = Create(hostID, user.UserID, story.StoryID, ActionType.Tag);

            if (tags.Count > 0) {
                TagCommaList tagList = new TagCommaList();
                tagList.DataBind(tags, story.StoryID, false);

                userAction.Message = String.Format("tagged {0} with {1}", GetStoryLink(story), ControlHelper.RenderControl(tagList));
                userAction.Save();
            }
            return userAction;
        }
コード例 #21
0
 public void DataBind(WeightedTagList tags, int storyID)
 {
     this._tags = tags;
     this._storyID = storyID;
 }
コード例 #22
0
ファイル: TagCloud.cs プロジェクト: Letractively/dotnetkicks
 /// <summary>
 /// Binds this tag cloud control to a list of weighted tags.
 /// </summary>
 /// <remarks>Callers can use the TagCache to retrieve a current list of tags for the current host:
 /// <code>this.TagCloud.DataBind(TagCache.GetHostTags(this.HostProfile.HohstID));</code></remarks>
 /// <param name="tags">The <seealso cref="WeightedTagList"/> to bind to.</param>
 public void DataBind(WeightedTagList tags)
 {
     this._tags = tags;
 }
コード例 #23
0
 public void DataBind(WeightedTagList tags, int storyID)
 {
     this.DataBind(tags, storyID, true);
 }
コード例 #24
0
ファイル: StoryTagList.cs プロジェクト: bsimser/dotnetkicks
 public void DataBind(WeightedTagList tags, int storyID)
 {
     this._tags    = tags;
     this._storyID = storyID;
 }
コード例 #25
0
 public void DataBind(WeightedTagList tags, int storyID, bool showTagIt)
 {
     this._tags = tags;
     this._storyID = storyID;
     this._showTagIt = showTagIt;
 }
コード例 #26
0
 /// <summary>
 /// Binds this tag cloud control to a list of weighted tags.
 /// </summary>
 /// <remarks>Callers can use the TagCache to retrieve a current list of tags for the current host:
 /// <code>this.TagCloud.DataBind(TagCache.GetHostTags(this.HostProfile.HohstID));</code></remarks>
 /// <param name="tags">The <seealso cref="WeightedTagList"/> to bind to.</param>
 public void DataBind(WeightedTagList tags)
 {
     this._tags = tags;
 }
コード例 #27
0
 public void DataBind(WeightedTagList tags, int storyID, string username)
 {
     this._tags = tags;
     this._storyID = storyID;
     this._username = username;
 }