📄 topicfunc.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Threading;
using System.Windows.Forms;
using feiyun0112.cnblogs.com.CSDNReader.Model;
using System.Web;
namespace feiyun0112.cnblogs.com.CSDNReader.Functions
{
class TopicFunc
{
private Topic _topic = null;
public Model.Topic Topic
{
get { return _topic; }
set { _topic=value ; }
}
public TopicFunc(Topic t)
{
this.Topic = t;
}
/// <summary>
/// 过滤帖子
/// </summary>
/// <returns></returns>
public bool Filter()
{
//总显示本人回复的
if (Setting.ShowRepliedTopic && (this.Topic.HaveReplied || (Variant.CurrentUser!=null && this.Topic.Name.IndexOf(Variant.CurrentUser.Name) > 0)))
{
return true;
}
//显示新贴
if (Setting.ShowNewTopic && Convert.ToInt32(this.Topic.Replies) == 0 && Convert.ToInt32(this.Topic.Point) >0)
{
return true;
}
//总是显示大分贴
if (Setting.ShowMaxPoint && ((Convert.ToInt32(this.Topic.Replies) <= 10 && Convert.ToInt32(this.Topic.Point) >= 100) || this.Topic.Room.Name.IndexOf("已解决")>0 ))
{
return true;
}
//最小分数
if (Setting.MinTopicPoint > 0 && Convert.ToInt32(this.Topic.Point) < Setting.MinTopicPoint)
{
return false;
}
//最大回复次数
if (Setting.MaxTopicReplies>0 && Convert.ToInt32(this.Topic.Replies) > Setting.MaxTopicReplies)
{
return false;
}
return true;
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="Topics"></param>
/// <returns></returns>
public Topic Contains(IList<Topic> Topics)
{
foreach (Topic t in Topics)
{
if (this.Topic.Id == t.Id)
{
return t;
}
}
return null;
}
/// <summary>
/// 更新帖子的信息
/// </summary>
/// <param name="newTopic"></param>
/// <returns></returns>
public bool UpdateTopic(Topic newTopic)
{
this.Topic.ReplyTime = newTopic.ReplyTime;
this.Topic.Replies = newTopic.Replies;
if (this.Topic.HaveRead) this.Topic.ReadAgain = true;
this.Topic.HaveRead = false;
return true;
}
public void ShowTopic()
{
if (this.Topic.threadShow != null && this.Topic.threadShow.ThreadState == ThreadState.Running)
{
return;
}
this.Topic.threadShow = new Thread(new ThreadStart(ShowProc));
this.Topic.threadShow.Start();
}
/// <summary>
/// 显示帖子
/// </summary>
private void ShowProc()
{
WEBFunc wFunc = new WEBFunc();
string strHTML = "";
Encoding encoding = Variant.Encoding;
GetHtml:
try
{
strHTML = wFunc.GetHTML("http://community.csdn.net/Expert/TopicView1.asp?id=" + this.Topic.Id, encoding);
}
catch
{
strHTML = "";
}
if (strHTML == "")
{
DelegateFunc.OnShowTopics(this.Topic.Id);
return;
}
//判断编码
if (encoding == Variant.Encoding)
{
if (Variant.Encoding==Encoding.UTF8)
{
if (strHTML.StartsWith("<?xml version=\"1.0\" encoding=\"GB2312\"", StringComparison.OrdinalIgnoreCase) )
{
encoding = System.Text.Encoding.GetEncoding("gb2312");
}
}
else
{
if (strHTML.StartsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"", StringComparison.OrdinalIgnoreCase) )
{
encoding = System.Text.Encoding.UTF8 ;
}
}
if (encoding != Variant.Encoding)
goto GetHtml;
}
wFunc = null;
try
{
//帖子源文件是一个XML,使用XSL文件进行转换
XmlDocument xml = new XmlDocument();
xml.LoadXml(strHTML);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(Application.StartupPath.Replace(@"\", @"\\") + @"\\csdn.xsl");
System.IO.StringWriter writer = new System.IO.StringWriter();
xslt.Transform(xml, null, writer);
this.Topic.Html = writer.ToString();
}
catch(Exception e)
{
this.Topic.Html = e.Message;
}
DelegateFunc.OnShowTopics(this.Topic.Id);
}
/// <summary>
/// 回帖
/// </summary>
/// <param name="strPostData"></param>
/// <param name="blnUseSign"></param>
/// <returns></returns>
public bool Post(string strPostData,bool blnUseSign)
{
DelegateFunc.OnRefreshInfo("正在发出回复");
string strHTML = "";
if (blnUseSign && Setting.Signature != "")
{
strPostData = strPostData + "\r\n \r\n" + Setting.Signature;
}
//回复的格式
strPostData = String.Format("Topicid={0}&RoomID={2}&xmlReply=aaaaa&csdnname=&csdnpassword=&ReplyContent={1}"
,this.Topic.Id
, HttpUtility.UrlEncode(strPostData,Variant.Encoding)
,this.Topic.Room.RoomID
);
WEBFunc wFunc = new WEBFunc();
wFunc.Referer = "http://community.csdn.net/Expert/xsl/Reply_Xml.asp?Topicid="+this.Topic.Id;
do
{
Variant.Err = "";
strHTML = wFunc.GetHTML("http://community.csdn.net/Expert/reply.asp", strPostData, null);
} while (Variant.Err == "KeepAliveFailure");
wFunc = null;
RegexFunc rFunc = new RegexFunc();
string strAlert = rFunc.GetMatch(strHTML, "<font color=red>(.*)</font>");
if (strAlert=="" && strHTML=="" && Variant.Err != "")
{
strAlert = Variant.Err;
}
if (strAlert != "")
{
////Variant.CurrentUser = null;
MsgFunc.ShowWarning(strAlert);
return false;
}
this.Topic.HaveReplied = true;
new RoomFunc(this.Topic.Room).CheckTopicExist(this.Topic);
return true;
}
public Topic Clone()
{
Topic t = new Topic(this.Topic.Room, this.Topic.Id, this.Topic.Name, this.Topic.User, this.Topic.Point, this.Topic.Replies, this.Topic.ReplyTime );
t.HaveRead = this.Topic.HaveRead;
t.HaveReplied = this.Topic.HaveReplied ;
t.Html = this.Topic.Html ;
t.Id = this.Topic.Id ;
t.Name = this.Topic.Name ;
t.Point = this.Topic.Point ;
t.ReadAgain = this.Topic.ReadAgain ;
t.RecID = this.Topic.RecID ;
t.Replies = this.Topic.Replies ;
t.ReplyTime = this.Topic.ReplyTime ;
t.Room = this.Topic.Room ;
t.TabPage = this.Topic.TabPage ;
t.threadShow = this.Topic.threadShow ;
t.User = this.Topic.User ;
return t;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -