⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topic.cs

📁 定义社区节点
💻 CS
📖 第 1 页 / 共 2 页
字号:
                if (strHTML.Length == 0)
                {
                    OnShowTopics(this.Id, mblnCheckPosted);
                    return;
                }
                this.Html = TransformHtml(strHTML);

                if (mblnCheckPosted)
                {
                    DelegateFunc.OnCheckTopicExist(this);
                    Room r = TreeviewFunc.FindRoom(Variant.MainForm.TreeRoom.Nodes[0], this.RoomId);
                    if (r != null )
                    {
                        r.RefreshRoom();
                    }
                }


                OnShowTopics(this.Id, mblnCheckPosted);

                
            }
            finally
            {
                this.blnInShow = false;
            }
        }
        #endregion Show Topic

        #region Post Topic
        private bool blnInPost;
        private string _PostData;
        /// <summary>
        /// 回帖
        /// </summary>
        /// <param name="strPostData"></param>
        /// <param name="blnUseSign"></param>
        /// <returns></returns>
        public void Post(string strPostData, bool blnUseSign)
        {
            if (this.blnInPost)
            {
                return;
            }
            
            if (blnUseSign && Setting.Signature.Length != 0)
            {
                strPostData = strPostData + "\r\n  \r\n" + Setting.Signature;
            }
            _PostData = strPostData;

            DelegateFunc.OnRefreshInfo("正在发出回复");

            if (StartPostEvent != null)
            {
                StartPostEvent();
            }

            blnInPost = true;            
            WEBFunc.Get(new RequestInfo("http://topic.csdn.net/" + this.Id), new RequestCompleteCallback(this.StartPostRequestComplete), new ExceptionCallback(this.PostRequestException), new StartDownloadCallback(StartPost), RequestStatePriority.PostTopic);
        }
        private bool  StartPost()
        {
            

            return true;
        }
        private void StartPostRequestComplete(byte[] dataBuffer)
        {
            WorkerFunc.AddWorkerTask(new LoadHtmlDelegate(this.StartPostProc),WorkPriority.PostTopic, new object[] {   dataBuffer });
        }

        private void StartPostProc(byte[] dataBuffer)
        {

            string strHTML = Variant.encoding.GetString(dataBuffer);
            string strURL = String.Format("http://forum.csdn.net/PointForum/Forum/ReplyTopic.aspx?forumID={0}&topicID={1}&postDate={2}"
                            , this.forumID, this.topicID, this.topicdate.IndexOf("%3a") > 0 ? this.topicdate : HttpUtility.UrlEncode(this.topicdate)
                            );            
            if (strHTML.IndexOf("请登录或者注册") > 0)
            {
                Variant.CurrentUser.Name = string.Empty;
                PostedEvent(false );
                return ;
            }

            string __VIEWSTATE = System.Web.HttpUtility.UrlEncode(RegexFunc.GetMatch(strHTML, "id=\"__VIEWSTATE\" value=\"(?<VIEWSTATE>.*?)\""));
            string __EVENTVALIDATION = System.Web.HttpUtility.UrlEncode(RegexFunc.GetMatch(strHTML, "id=\"__EVENTVALIDATION\" value=\"(?<VIEWSTATE>.*?)\""));


            //回复的格式
            _PostData = String.Format("__VIEWSTATE={0}&tb_ReplyBody%24_%24Editor={1}&bt_Submit=%E6%8F%90%E4%BA%A4%E5%9B%9E%E5%A4%8D"
                                        , __VIEWSTATE
                                        , HttpUtility.UrlEncode(_PostData, Variant.encoding)

                                        );
            
            WEBFunc.Get(new RequestInfo(strURL, strURL, _PostData,null), new RequestCompleteCallback(this.PostRequestComplete), new ExceptionCallback(this.PostRequestException), null, RequestStatePriority.PostTopic );
                        

        }
        private void PostRequestComplete(byte[] dataBuffer)
        {
            WorkerFunc.AddWorkerTask(new LoadHtmlDelegate(this.PostProc),WorkPriority.PostTopic, new object[] {   dataBuffer });
        }
        private void PostRequestException(Exception e)
        {
            try
            {
                ShowWarningEvent(e.Message );
            }
            finally
            {
                if (PostedEvent != null)
                {
                    PostedEvent(false);
                }
                this.blnInPost = false;
            }
        }
        private void PostProc(byte[] dataBuffer)
        {
            bool blnPosted = false;
            try
            {
                CommonFunc.Addlog(string.Format("PostProc {0}",this));

                string strHTML = Variant.encoding.GetString(dataBuffer);
                string strAlert = RegexFunc.GetMatch(strHTML, "<span class=\"error\">(.*)</span>");

                if (strAlert.Length != 0)
                {

                    ShowWarningEvent(strAlert);
                    PostedEvent(blnPosted);
                    return ;
                }

                this.HaveReplied = true;

                this.PostedId = "";

                int intSleep;
                int.TryParse(RegexFunc.GetMatch(strHTML, @"(\d+)秒钟后"), out intSleep);
                if (intSleep <= 0)
                {
                    
                    intSleep = 3;
                }
                else
                {
                    //刷新数据
                    string strRegex = @"setTimeout\(""window.open\('http://topic.csdn.net/(?<ID>[^']*)'";
                    string strTopicId=RegexFunc.GetMatch(strHTML, strRegex);
                    if (!strTopicId.Equals(string.Empty))
                    {
                        this.PostedId = strTopicId;
                    }

                }

                CommonFunc.Addlog(string.Format("PostedId {1},{0}",PostedId,this));

                Thread.Sleep(1000 * (intSleep +1));

                
                
                OnOpenedTopic(this.topicID,true );

                

                blnPosted = true;
            }
            finally
            {
                if (PostedEvent != null)
                {
                    PostedEvent(blnPosted);
                }
                this.blnInPost = false;
            }
        }
        #endregion Post Topic

        /// <summary>
        /// 过滤帖子
        /// </summary>
        /// <returns></returns>
        public bool Filter()
        {
            //总显示本人回复的
            if (Setting.ShowRepliedTopic && (this.HaveReplied || (Variant.CurrentUser != null && this.Name.IndexOf(Variant.CurrentUser.Name) > 0)))
            {
                return true;
            }
            //显示新贴
            if (Setting.ShowNewTopic && Convert.ToInt32(this.Replies) == 0 && Convert.ToInt32(this.Point) > 0)
            {
                return true;
            }

            //总是显示大分贴
            ////if (Setting.ShowMaxPoint && ((Convert.ToInt32(this.Replies) <= 10 && Convert.ToInt32(this.Point) >= 100) || this.Room.Name.IndexOf("已解决")>0 ))
            ////{
            ////    return true;
            ////}

            //已解决
            Room r = TreeviewFunc.FindRoom(Variant.MainForm.TreeRoom.Nodes[0],this.RoomId);            
            if (r!=null && r.Name.IndexOf("已解决") > 0)
            {
                return true;
            }

            //最小分数
            if (Setting.MinTopicPoint > 0 && Convert.ToInt32(this.Point) < Setting.MinTopicPoint)
            {
                return false;
            }


            //最大回复次数
            if (Setting.MaxTopicReplies > 0 && Convert.ToInt32(this.Replies) > Setting.MaxTopicReplies)
            {
                return false;
            }
            return true;
        }

        public string RoomName()
        {
            Room r = TreeviewFunc.FindRoom(Variant.MainForm.TreeRoom.Nodes[0], this.RoomId);
            if (r != null )
            {
                return r.Name;
            }
            return string.Empty;
        }

        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="Topics"></param>
        /// <returns></returns>
        public Topic Contains(IList<Topic> Topics)
        {
            foreach (Topic t in Topics)
            {
                if (this.Id == t.Id)
                {
                    return t;
                }
            }
            return null;
        }

        /// <summary>
        /// 更新帖子的信息
        /// </summary>
        /// <param name="newTopic"></param>
        /// <returns></returns>
        public bool UpdateTopic(Topic newTopic)
        {
            this.ReplyTime = newTopic.ReplyTime;
            this.ReplyUser = newTopic.ReplyUser;
            this.Replies = newTopic.Replies;
            if (this.HaveRead) this.ReadAgain = true;
            this.HaveRead = false;

            return true;
        }



        
        private static string TransformHtml(string strOrgHtml)
        {
            string strHTML = RegexFunc.Replace(strOrgHtml, "href=\"/", "href=\"http://topic.csdn.net/");
            strHTML = RegexFunc.Replace(strHTML, "href='/", "href='http://topic.csdn.net/");
            strHTML = RegexFunc.Replace(strHTML, "src=\"/", "src=\"http://topic.csdn.net/");
            strHTML = RegexFunc.Replace(strHTML, "src='/", "src='http://topic.csdn.net/");
            strHTML = RegexFunc.Replace(strHTML, "onmouseover=\"[^<]*\"", "");
            strHTML = RegexFunc.Replace(strHTML, "<div[^<]*id=\"CSDNPHL\">.*?</div[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<div[^<]*id=\"navbar\"[^<]*>.*?</div[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<div[^<]*id=\"pagefunc\"[^<]*>.*?</div[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<div[^<]*class=\"float_left\"[^<]*>.*?</div[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<select[^<]*>.*?</select[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<input[^<]*type=\"button\"[^<]*>", " ");
            strHTML = RegexFunc.Replace(strHTML, "<span[^<]*csdnid=\"EndOfReplyList\".*?</body", "</body");

            int i = strHTML.IndexOf("<body", StringComparison.CurrentCultureIgnoreCase);
            if (i > 0)
            {
                i = strHTML.IndexOf(">", i);
                if (i > 0)
                {
                    int j = strHTML.IndexOf("UserCard.ashx", i, StringComparison.CurrentCultureIgnoreCase);
                    if (j > 0)
                    {
                        j = strHTML.IndexOf(">", j);
                        if (j > 0)
                        {
                            strHTML = strHTML.Substring(0, i + 1) + strHTML.Substring(j + 1);
                        }
                    }
                }
            }

            return strHTML;
        }


       
        public Topic Clone()
        {
            Topic t = new Topic(this.RoomId, this.Id, this.Name, this.User, this.Point, this.Replies, this.ReplyUser, this.ReplyTime, this.forumID, this.topicID, this.topicdate);
            t.HaveRead = this.HaveRead;
            t.HaveReplied = this.HaveReplied;
            t.Html = this.Html;
            t.Id = this.Id;
            t.Name = this.Name;
            t.Point = this.Point;
            t.ReadAgain = this.ReadAgain;
            t.RecID = this.RecID;
            t.Replies = this.Replies;
            t.ReplyUser = this.ReplyUser;
            t.ReplyTime = this.ReplyTime;
            //t.Room  = this.Room ;
            t.TabPage = this.TabPage;            
            t.User = this.User;

            return t;
        }

        public override string ToString()
        {
            return this.URL;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -