Esempio n. 1
0
        public override void CopyFrom(BasicThread thread)
        {
            base.CopyFrom(thread);

            QuestionThread question = (QuestionThread)thread;

            //if (question.BestPost != null)
            this.BestPost = question.BestPost;

            this.Rewards       = question.Rewards;
            this.Reward        = question.Reward;
            this.RewardCount   = question.RewardCount;
            this.AlwaysEyeable = question.AlwaysEyeable;
            this.ExpiresDate   = question.ExpiresDate;
            this.BestPostID    = question.BestPostID;
            this.UnusefulCount = question.UnusefulCount;
            this.UsefulCount   = question.UsefulCount;
        }
Esempio n. 2
0
        public ThreadCollectionV5(DataReaderWrap readerWrap)
        {
            while (readerWrap.Next)
            {
                BasicThread thread;
                ThreadType  threadType = readerWrap.Get <ThreadType>("ThreadType");
                switch (threadType)
                {
                case ThreadType.Poll:
                    PollThreadV5 poll = new PollThreadV5(readerWrap);
                    poll.IsClosed = poll.ExpiresDate <= DateTimeUtil.Now;
                    thread        = (BasicThread)poll;
                    break;

                case ThreadType.Polemize:
                    PolemizeThreadV5 polemize = new PolemizeThreadV5(readerWrap);
                    polemize.IsClosed = polemize.ExpiresDate <= DateTimeUtil.Now;
                    thread            = (BasicThread)polemize;
                    break;

                case ThreadType.Question:
                    QuestionThread question = new QuestionThread(readerWrap);
                    if (question.IsClosed == false)
                    {
                        question.IsClosed = question.ExpiresDate <= DateTimeUtil.Now;
                    }
                    thread = (BasicThread)question;
                    break;

                default:
                    thread = new BasicThread(readerWrap);
                    break;
                }

                this.Add(thread);
            }
        }
Esempio n. 3
0
        protected override void GetThread()
        {
            if (IsOnlyLookOneUser)
            {
                Response.Redirect(BbsUrlHelper.GetThreadUrl(CodeName, ThreadID, 1, LookUserID, PostBOV5.Instance.GetThreadTypeString(ThreadType.Normal), ForumListPage));
            }


            if (IsUnapprovePosts)
            {
                BbsRouter.JumpToUrl(BbsUrlHelper.GetThreadUrl(CodeName, ThreadID, PostBOV5.Instance.GetThreadTypeString(ThreadType.Normal)), "type=" + Type);
            }

            if (string.IsNullOrEmpty(Type))
            {
                ThreadType realThreadType;

                PostBOV5.Instance.GetQuestionWithReplies(ThreadID, PageNumber, PageSize, true, UpdateView, out m_QuestionThread, out m_PostList, out realThreadType);

                //如果不是 问题帖 则跳到相应的页面
                if (realThreadType != ThreadType.Question)
                {
                    Response.Redirect(BbsUrlHelper.GetThreadUrl(CodeName, ThreadID, PostBOV5.Instance.GetThreadTypeString(realThreadType)));
                }
            }
            else
            {
                BasicThread thread;
                GetPosts(ThreadType.Question, out m_TotalPosts, out thread, out m_PostList);

                m_QuestionThread = (QuestionThread)thread;

            }

            PostCollectionV5 tempPosts;
            if (m_QuestionThread!=null && m_QuestionThread.BestPost != null)
            {
                tempPosts = new PostCollectionV5(m_PostList);
                tempPosts.Add(m_QuestionThread.BestPost);
            }
            else
                tempPosts = m_PostList;

            PostBOV5.Instance.ProcessKeyword(tempPosts, ProcessKeywordMode.TryUpdateKeyword);

            //if (_Request.IsSpider == false)
            //{
                //List<int> userIDs = new List<int>();
                //foreach (PostV5 post in tempPosts)
                //{
                //    userIDs.Add(post.UserID);
                //}
                //UserBO.Instance.GetUsers(userIDs, GetUserOption.WithAll);
            UserBO.Instance.GetUsers(tempPosts.GetUserIds(), GetUserOption.WithAll);
            //}
        }
Esempio n. 4
0
        public override void QueryForBeforeRequestIn3M(out TopicStatusCollection experiesTopicStatus, out List<int> autoFinalQuestionThreadIds, out Dictionary<int, Dictionary<int, int>> autoFinalQuestionForumIDAndRewards)
        {

            //供放置查出的已经过期的提问
            //List<Question> expiresQuestions = new List<Question>();

            List<QuestionThread> expiresQuestions = new List<QuestionThread>();

            Dictionary<int, int> threadIDAndPostUserIDs = new Dictionary<int, int>();
            Dictionary<int, int> threadIDAndForumIDs = new Dictionary<int, int>();

            autoFinalQuestionThreadIds = new List<int>();

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_QueryForBeforeRequestIn3M";
                query.CommandType = CommandType.StoredProcedure;
                query.CommandTimeout = 30;

                try
                {
                    if (IsAutoFinalQuestion == true)
                    {
                        experiesTopicStatus = new TopicStatusCollection();
                        autoFinalQuestionForumIDAndRewards = new Dictionary<int, Dictionary<int, int>>();
                        return;
                    }
                    IsAutoFinalQuestion = true;

                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        experiesTopicStatus = new TopicStatusCollection(reader);

                        reader.NextResult();

                        while (reader.Read())
                        {
                            //Question question = ConvertData.ConvertToQuestion(reader);
                            QuestionThread question = new QuestionThread();
                            question.ThreadID = reader.Get<int>(reader.GetOrdinal("ThreadID"));
                            question.FillQuestion(reader);

                            expiresQuestions.Add(question);

                            int forumID = reader.Get<int>("ForumID");

                            threadIDAndForumIDs.Add(question.ThreadID, forumID);

                            threadIDAndPostUserIDs.Add(question.ThreadID, reader.GetInt32(reader.GetOrdinal("PostUserID")));
                        }
                    }


                    query.CommandText = "bx_AutoFinalQuestion";
                    query.CommandType = CommandType.StoredProcedure;
                    query.CommandTimeout = 30;

                    autoFinalQuestionForumIDAndRewards = new Dictionary<int, Dictionary<int, int>>();
                    foreach (QuestionThread q in expiresQuestions)
                    {
                        int forumID;
                        if (threadIDAndForumIDs.ContainsKey(q.ThreadID))
                            forumID = threadIDAndForumIDs[q.ThreadID];
                        else
                            continue;

                        query.Parameters.Clear();
                        query.CreateParameter<int>("@ThreadID", q.ThreadID, SqlDbType.Int);
                        query.CreateParameter<int>("@UserID", threadIDAndPostUserIDs[q.ThreadID], SqlDbType.Int);
                        query.CreateParameter<int>("@RewardCount", q.RewardCount, SqlDbType.Int);
                        query.CreateParameter<int>("@TotalReward", q.Reward, SqlDbType.Int);

                        if (autoFinalQuestionForumIDAndRewards.ContainsKey(forumID) == false)
                            autoFinalQuestionForumIDAndRewards.Add(forumID, new Dictionary<int, int>());

                        using (XSqlDataReader reader = query.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                int userID = reader.Get<int>("UserID");
                                int reward = reader.Get<int>("Reward");

                                if (autoFinalQuestionForumIDAndRewards[forumID].ContainsKey(userID))
                                {
                                    autoFinalQuestionForumIDAndRewards[forumID][userID] = autoFinalQuestionForumIDAndRewards[forumID][userID] + reward;
                                }
                                else
                                {
                                    autoFinalQuestionForumIDAndRewards[forumID].Add(userID, reward);
                                }
                            }
                        }
                        if (!autoFinalQuestionThreadIds.Contains(q.ThreadID))
                            autoFinalQuestionThreadIds.Add(q.ThreadID);
                    }

                    IsAutoFinalQuestion = false;
                }
                catch (Exception ex)
                {
                    IsAutoFinalQuestion = false;
                    throw ex;
                }
            }


        }
Esempio n. 5
0
        public override int VoteQuestionBestPost(int threadID, int userID, bool isUseful, QuestionThread question)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_VoteQuestionBestPost";
                query.CommandType = CommandType.StoredProcedure;

                query.CreateParameter<int>("@ThreadID", threadID, SqlDbType.Int);
                query.CreateParameter<int>("@UserID", userID, SqlDbType.Int);
                query.CreateParameter<bool>("@BestPostIsUseful", isUseful, SqlDbType.Bit);
                query.CreateParameter<int>("@ErrorCode", SqlDbType.Int, ParameterDirection.ReturnValue);

                string extendData = null;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    extendData = GetExtendData(question, ThreadType.Question, reader, true);
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;

                if (returnValue == 0 && extendData != null)
                {
                    UpdateThreadExtendData(extendData, threadID, query);
                }

                return returnValue;
            }
        }
Esempio n. 6
0
        public override int FinalQuestion(int threadID, int bestPostID, Dictionary<int, int> rewards, QuestionThread question)
        {
            StringBuilder rewardsString = new StringBuilder();

            int i = 0;
            foreach (KeyValuePair<int, int> reward in rewards)
            {
                if (reward.Key != 0)
                {
                    if (i != 0)
                        rewardsString.Append(",");

                    rewardsString.Append(reward.Key);
                    rewardsString.Append(":");
                    rewardsString.Append(reward.Value);
                    i++;
                }
            }

            using (SqlQuery query = new SqlQuery())
            {
                query.CommandText = "bx_v5_FinalQuestion";
                query.CommandType = CommandType.StoredProcedure;

                query.CreateParameter<int>("@ThreadID", threadID, SqlDbType.Int);
                query.CreateParameter<int>("@BestPostID", bestPostID, SqlDbType.Int);
                query.CreateParameter<string>("@PostRewards", rewardsString.ToString(), SqlDbType.VarChar, 8000);
                query.CreateParameter<int>("@ErrorCode", SqlDbType.Int, ParameterDirection.ReturnValue);

                string extendData = null;
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    extendData = GetExtendData(question, ThreadType.Question, reader, true);
                }

                int returnValue = (int)query.Parameters["@ErrorCode"].Value;

                if (returnValue == 0 && extendData != null)
                {
                    UpdateThreadExtendData(extendData, threadID, query);
                }

                return returnValue;
            }
        }
Esempio n. 7
0
        private void SetThreadContent(BasicThread thread, QuestionThread question, PostCollectionV5 posts, bool getBestPost, int pageNumber, bool getExtendedInfo)
        {
            bool removeContent = false;
            bool removeBestPost = false;

            if (thread is QuestionThread)
                question = (QuestionThread)thread;

            foreach (PostV5 post in posts)
            {
                //if (post.PostType == PostType.ThreadContent)
                //    thread.ThreadContent = post;
                //bool isBestPost = false;
                if (question != null)
                {
                    if (question.BestPostID == post.PostID)
                    {
                        question.BestPost = post;
                        //isBestPost = true;
                        removeBestPost = true;
                    }
                }

                if (post.PostID == thread.ContentID)
                {
                    thread.ThreadContent = post;
                    removeContent = true;
                }
            }

            if (getExtendedInfo)
            {
                if (removeBestPost)
                    posts.Remove(question.BestPost);
                if (removeContent && pageNumber > 1)
                    posts.Remove(thread.ThreadContent);
            }

            if (question != null && question.BestPostID != 0 && question.BestPost == null && getBestPost)
            {
                //这种情况 可能发生在  最佳答案被删除的情况下   所以把BestPostID更新为0
                question.BestPostID = 0;
            }
        }
Esempio n. 8
0
 private BasicThread GetThread(XSqlDataReader reader, DateTime? expiresDate)
 {
     ThreadType threadType = reader.Get<ThreadType>("ThreadType");
     switch (threadType)
     {
         case ThreadType.Poll:
             PollThreadV5 poll = new PollThreadV5(reader);
             if (expiresDate != null)
                 poll.IsClosed = expiresDate.Value <= DateTimeUtil.Now;
             return (BasicThread)poll;
         case ThreadType.Polemize:
             PolemizeThreadV5 polemize = new PolemizeThreadV5(reader);
             if (expiresDate != null)
                 polemize.IsClosed = expiresDate.Value <= DateTimeUtil.Now;
             return (BasicThread)polemize;
         case ThreadType.Question:
             QuestionThread question = new QuestionThread(reader);
             if (question.IsClosed == false)
             {
                 if (expiresDate != null)
                     question.IsClosed = expiresDate.Value <= DateTimeUtil.Now;
             }
             return (BasicThread)question;
         default:
             return new BasicThread(reader);
     }
 }