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

📄 rda.cs

📁 c#编的CSDN离线助手
💻 CS
字号:
/// <Copyright>
/// This Program Written By Luyan(5drush)
/// 2002/4/23
/// Email:nluyan@163.net
/// QQ:5743345
/// </Copyright>
using System;
using System.Xml;
using System.Data;
using System.Net;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Specialized;


namespace CSDN
{
	/// <summary>
	/// Remote Data Access 的摘要说明。
	/// </summary>
	public class RDA
	{

		
		public RDA()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		/// <summary>
		/// 从网上获取最新的论坛帖子列表
		/// </summary>
		/// <param name="RoomId">论坛编号</param>
		/// <param name="Block">版面:1、非技术区(新贴区),2技术区(旧帖区),3已解决 4精华区</param>
		/// <returns>列表</returns>
		public TopicItemIndex GetTopicItemIndex(int RoomId, int Block)
		{
			TopicItemIndex topicItemIndex = new TopicItemIndex();
			string topicListUrl = "http://211.157.102.21/expert/Rooms/" + RoomId.ToString() + "/Forum_" + RoomId.ToString() + "_" + Block.ToString() + ".xml";
			XmlDocument xmlDoc = new XmlDocument();
			xmlDoc.Load(topicListUrl);
			XmlNode root = xmlDoc["Forum"];
			XmlNode replys = root["Topics"];
			XmlNode topicItemNode;
			TopicItem topicItem;
			bool endstate = false;
			if(replys.HasChildNodes)
			{
				for(int i = 0; i < replys.ChildNodes.Count; i++)
				{
					topicItemNode = replys.ChildNodes[i];
					if(topicItemNode["endstate"].InnerText == "1")
						endstate = true;
					topicItem = new TopicItem(topicItemNode["TopicId"].InnerText,topicItemNode["TopicName"].InnerText,topicItemNode["PostUserName"].InnerText,Int32.Parse(topicItemNode["ReplyNum"].InnerText),DateTime.Parse(topicItemNode["ReplyDateTime"].InnerText),Int32.Parse(topicItemNode["Point"].InnerText),endstate);
					topicItemIndex[i] = topicItem;
				}
			}
			return topicItemIndex;
		}

		public Topic GetTopic(string TopicId)
		{
			Poster poster = new Poster();
			Poster topicPoster;
			string left = TopicId.Remove(3,3);
			string topicUrl = "http://211.157.102.21/expert/topic/" + left +"/" + TopicId + ".xml";
			
			
			HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(topicUrl);
			HttpWebResponse webResponse =(HttpWebResponse) webRequest.GetResponse();

			
			Stream receiveStream = webResponse.GetResponseStream();
			Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
			StreamReader readStream = new StreamReader( receiveStream, encode );
			Char[] read = new Char[256];
			int count = readStream.Read( read, 0, 256 );
			string content = "";
			while (count > 0) 
			{
				String str = new String(read, 0, count);
				content += str;
				count = readStream.Read(read, 0, 256);
			}
			webResponse.Close();
			readStream.Close();

			content = content.Replace("xml:stylesheet","xml-stylesheet");
			XmlDocument xmlDoc = new XmlDocument();

			xmlDoc.LoadXml(content);

			XmlNode root = xmlDoc["Topic"];
			XmlNode Issue = root["Issue"];

			poster.PostUserNickName = Issue["PostUserNickName"].InnerText;
			poster.Rank = Issue["rank"].InnerText;
			poster.RankNum = Issue["ranknum"].InnerText;
			poster.Credit = Int32.Parse(Issue["credit"].InnerText);
			poster.PostUserId = Issue["PostUserId"].InnerText;
			poster.PostUserName = Issue["PostUserName"].InnerText;
			topicPoster = poster;
			XmlNode Reply;
			ReplyIndex replyIndex = new ReplyIndex();
			Reply reply;
			if(root["Replys"].HasChildNodes)
			{
				for(int i = 0; i < root["Replys"].ChildNodes.Count; i++)
				{
					poster = new Poster();
					Reply = root["Replys"].ChildNodes[i];
					poster.PostUserNickName = Reply["PostUserNickName"].InnerText;
					poster.Rank = Reply["rank"].InnerText;
					poster.RankNum = Reply["ranknum"].InnerText;
					poster.Credit = Int32.Parse(Reply["credit"].InnerText);
					poster.PostUserId = Reply["PostUserId"].InnerText;
					poster.PostUserName = Reply["PostUserName"].InnerText;
					reply = new Reply(poster,Reply["ReplyID"].InnerText, Reply["TopicID"].InnerText, Int32.Parse(Reply["Point"].InnerText),DateTime.Parse(Reply["PostDateTime"].InnerText), Reply["Content"].InnerText);
					replyIndex[i] = reply;
				}
			}

			bool endstate = false;
			if(Issue["EndState"].InnerText == "1")
				endstate = true;

			return new Topic(topicPoster,
				Issue["TopicId"].InnerText,
				Issue["TopicName"].InnerText,
				Issue["RoomName"].InnerText,
				Int32.Parse(Issue["ReplyNum"].InnerText),
				DateTime.Parse(Issue["PostDateTime"].InnerText),
				Int32.Parse(Issue["Point"].InnerText),
				Int32.Parse(Issue["ReadNum"].InnerText),
				Issue["RoomId"].InnerText,
				endstate, 
				" " + Issue["Content"].InnerText,
				replyIndex
				);
		}

		public string PostData(string Url, NameValueCollection myNameValueCollection, string AspSessionId)
		{
			WebClient myWebClient = new WebClient();
			myWebClient.Headers.Add("Cookie:" + AspSessionId);
			byte[] responseArray = myWebClient.UploadValues(Url,"POST",myNameValueCollection);
                return Encoding.Default.GetString(responseArray);
		}

		public string Logon(string Url,string Name,string Password)
		{
			WebClient myWebClient = new WebClient();
			NameValueCollection myNameValueCollection = new NameValueCollection();
			myNameValueCollection.Add("name",Name);
			myNameValueCollection.Add("pass",Password);
			myNameValueCollection.Add("type","0");

			string header = "";


			byte[] responseArray = myWebClient.UploadValues(Url,"POST",myNameValueCollection);

			header = myWebClient.ResponseHeaders[4].ToString() + "\n";

			string content = Encoding.Default.GetString(responseArray);

			if(content.Length > 0)
                return null;
			else
				return header;
		}
	}
}

⌨️ 快捷键说明

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