コード例 #1
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Reads a specific comments by the Thread ID and siteid
        /// </summary>
        /// <param name="threadid">The threads internal id</param>
        /// <param name="site"></param>
        /// <returns>The list of comments</returns>
        public CommentsList GetCommentsListByThreadId(int threadid, ISite site)
        {
            var commentList = new CommentsList();

            commentList.comments = new List<CommentInfo>();
            commentList.TotalCount = 0;
            commentList.ItemsPerPage = ItemsPerPage;
            commentList.StartIndex = StartIndex;
            commentList.SortBy = SortBy;
            commentList.SortDirection = SortDirection;

            using (IDnaDataReader reader = CreateReader("commentsreadbythreadid"))
            {
                try
                {
                    reader.AddParameter("threadid", threadid);
                    reader.AddParameter("startindex", StartIndex);
                    reader.AddParameter("itemsperpage", ItemsPerPage);
                    reader.AddParameter("SortBy", SortBy.ToString());
                    reader.AddParameter("SortDirection", SortDirection.ToString());

                    reader.Execute();

                    if (reader.HasRows)
                    {
                        //all good - read comments
                        while (reader.Read())
                        {
                            commentList.comments.Add(CommentCreateFromReader(reader, site));
                            commentList.TotalCount = reader.GetInt32NullAsZero("totalresults");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ApiException(ex.Message, ex.InnerException);
                    //DnaApiWebProtocalException.ThrowDnaApiWebProtocalException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
                }
            }
            return commentList;
        }
コード例 #2
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Return Comments for Site and Prefix.
        /// </summary>
        /// <param name="site">The site object</param>
        /// <param name="prefix">The commentforum prefix</param>
        /// <returns>The list of comments</returns>
        public CommentsList GetCommentsListBySite(ISite site, string prefix)
        {

            var spName = "commentsreadbysitename";
            if (!String.IsNullOrEmpty(prefix))
            {
                spName += "prefix";
            }
            switch (FilterBy)
            {
                case FilterBy.EditorPicks:
                    spName += "editorpicksfilter";
                    break;
            }

            CommentsList commentList = null;
            if (GetCommentListBySiteFromCache(site, prefix, ref commentList))
            {
                return commentList;
            }
            commentList = new CommentsList();
            commentList.comments = new List<CommentInfo>();
            commentList.TotalCount = 0;
            commentList.ItemsPerPage = ItemsPerPage;
            commentList.StartIndex = StartIndex;
            commentList.SortBy = SortBy;
            commentList.SortDirection = SortDirection;
            commentList.FilterBy = FilterBy;


            using (IDnaDataReader reader = CreateReader(spName))
            {
                try
                {
                    reader.AddParameter("siteid", site.SiteID);
                    reader.AddParameter("startindex", StartIndex);
                    reader.AddParameter("itemsperpage", ItemsPerPage);
                    if (!String.IsNullOrEmpty(prefix))
                    {
                        reader.AddParameter("prefix", prefix + "%");
                    }
                    reader.AddParameter("SortBy", SortBy.ToString());
                    reader.AddParameter("SortDirection", SortDirection.ToString());

                    reader.Execute();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            commentList.comments.Add(CommentCreateFromReader(reader, site));
                            commentList.TotalCount = reader.GetInt32NullAsZero("totalresults");
                            commentList.LastUpdate = reader.GetDateTime("lastupdate");
                        }
                        AddCommentListToCache(commentList, site, prefix);
                    }
                }
                catch (Exception ex)
                {
                    throw new ApiException(ex.Message, ex.InnerException);
                    //DnaApiWebProtocalException.ThrowDnaApiWebProtocalException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
                }
            }
            return commentList;
        }
コード例 #3
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Reads a forum comments by the IDs and siteid
        /// </summary>
        /// <param name="forumid">The forums internal id</param>
        /// <param name="site"></param>
        /// <returns>The list of comments from all the forums specified</returns>
        public CommentsList GetCommentsListByForumIds(string forumuids, ISite site)
        {
            var commentList = new CommentsList();

            commentList.comments = new List<CommentInfo>();
            commentList.TotalCount = 0;
            commentList.ItemsPerPage = ItemsPerPage;
            commentList.StartIndex = StartIndex;
            commentList.SortBy = SortBy;
            commentList.SortDirection = SortDirection;
            commentList.FilterBy = FilterBy;

            String spName = "commentsreadbyforumids";
            if (FilterBy == FilterBy.EditorPicks)
            {
                spName = "commentsreadbyforumidseditorpicksfilter";
            }

            using (IDnaDataReader reader = CreateReader(spName))
            {
                try
                {
                    reader.AddParameter("forumuids", forumuids);
                    reader.AddParameter("startindex", StartIndex);
                    reader.AddParameter("itemsperpage", ItemsPerPage);
                    reader.AddParameter("SortBy", SortBy.ToString());
                    reader.AddParameter("SortDirection", SortDirection.ToString());
                    reader.AddParameter("siteurlname", site.SiteName);

                    reader.Execute();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            commentList.comments.Add(CommentCreateFromReader(reader, site));
                            commentList.TotalCount = reader.GetInt32NullAsZero("totalresults");
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ApiException(ex.Message, ex.InnerException);
                    //DnaApiWebProtocalException.ThrowDnaApiWebProtocalException(System.Net.HttpStatusCode.InternalServerError, ex.Message, ex);
                }
            }
            return commentList;
        }
コード例 #4
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Returns the comment forum uid from cache
        /// </summary>
        /// <param name="list"></param>
        /// <param name="site">the site of the forum</param>
        /// <param name="prefix"></param>
        /// <returns>true if found in cache otherwise false</returns>
        private void AddCommentListToCache(CommentsList list, ISite site, string prefix)
        {
            string cacheKey = CommentListCacheKey(site.SiteID, prefix);

            //ICacheItemExpiration expiry = SlidingTime.
            CacheManager.Add(cacheKey + CacheLastupdated, list.LastUpdate, CacheItemPriority.Normal,
                             null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes)));

            CacheManager.Add(cacheKey, list, CacheItemPriority.Normal,
                             null, new SlidingTime(TimeSpan.FromMinutes(Cacheexpiryminutes)));
        }
コード例 #5
0
ファイル: Comments.cs プロジェクト: rocketeerbkw/DNA
        /// <summary>
        /// Returns the comment forum uid from cache
        /// </summary>
        /// <param name="site">the site of the forum</param>
        /// <param name="prefix"></param>
        /// <param name="list"></param>
        /// <returns>true if found in cache otherwise false</returns>
        private bool GetCommentListBySiteFromCache(ISite site, string prefix, ref CommentsList list)
        {
            string cacheKey = CommentListCacheKey(site.SiteID, prefix);
            object tempLastUpdated = CacheManager.GetData(cacheKey + CacheLastupdated);

            if (tempLastUpdated == null)
            {
//not found
                list = null;
                Statistics.AddCacheMiss();
                return false;
            }
            var lastUpdated = (DateTime) tempLastUpdated;
            //check if cache is up to date
            if (DateTime.Compare(lastUpdated, CommentListGetLastUpdate(site.SiteID, prefix)) != 0)
            {
//cache out of date so delete
                DeleteCommentListFromCache(site, prefix);
                list = null;
                Statistics.AddCacheMiss();
                return false;
            }
            //get actual cached object
            list = (CommentsList) CacheManager.GetData(cacheKey);
            if (list == null)
            {
//cache out of date so delete
                DeleteCommentListFromCache(site, prefix);
                Statistics.AddCacheMiss();
                return false;
            }
            Statistics.AddCacheHit();

            //readd to cache to add sliding window affect
            AddCommentListToCache(list, site, prefix);
            return true;
        }
コード例 #6
0
ファイル: ForumCommentsList.cs プロジェクト: rocketeerbkw/DNA
        private XmlDocument GetViewReadOnlyCommentsXml(CommentsList commentInfoList, int forumId, string siteName)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XElement readOnlyElement = new XElement("READONLYCOMMENTS", 
                                             new XAttribute("FORUMID",forumId.ToString()),
                                             new XAttribute("SITENAME", siteName),
                                                from c in commentInfoList.comments
                                                select new XElement("COMMENTINFO", new XElement("uri",c.Uri.ToString()),
                                                    new XElement("TEXT",c.text.ToString()), new XElement("CREATED",c.Created.ToString()),
                                                    new XElement("USERID",c.User.UserId.ToString()), new XElement("USERNAME",c.User.DisplayName),
                                                    new XElement("ID", c.ID.ToString()), new XElement("POSTSTYLE", c.PostStyle.ToString()), 
                                                    new XElement("COMPLAINTURI",c.ComplaintUri.ToString()), new XElement("FORUMURI",c.ForumUri.ToString()),
                                                    new XElement("STATUS",c.hidden.ToString()), new XElement("ISEDITORPICK",c.IsEditorPick.ToString()),
                                                    new XElement("INDEX",c.Index.ToString()), new XElement("NERORATINGVALUE",c.NeroRatingValue.ToString()),
                                                    new XElement("TWEETID", c.TweetId.ToString())));

            using (XmlReader xmlReader = readOnlyElement.CreateReader())
            {
                xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlReader);
            }

            return xmlDoc;

        }