📄 form1.cs
字号:
namespace Codematic
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class Form1 : Form
{
private IContainer components;
private Label lblTip;
private ListView listView1;
private string RssPath = "http://blog.csdn.net/litp/rss.aspx";
private string temphtml = (Application.StartupPath + "~temp.html");
private string tempOpmlfile = (Application.StartupPath + "~tempopml.xml");
private string tempRssfile = (Application.StartupPath + "~temprss.xml");
private Thread thread;
public Form1()
{
this.InitializeComponent();
}
private void CreatListview()
{
this.listView1.Columns.Clear();
this.listView1.Items.Clear();
this.listView1.View = View.LargeIcon;
this.listView1.View = View.Details;
this.listView1.FullRowSelect = true;
this.listView1.Columns.Add("", 300, HorizontalAlignment.Left);
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
this.CreatListview();
this.thread = new Thread(new ThreadStart(this.LoadRss));
this.thread.Start();
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show(exception.ToString());
}
}
private void InitializeComponent()
{
this.listView1 = new ListView();
this.lblTip = new Label();
base.SuspendLayout();
this.listView1.Location = new Point(0x26, 40);
this.listView1.Name = "listView1";
this.listView1.Size = new Size(270, 0xcc);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.DoubleClick += new EventHandler(this.listView1_DoubleClick);
this.lblTip.AutoSize = true;
this.lblTip.Location = new Point(0x3a, 280);
this.lblTip.Name = "lblTip";
this.lblTip.Size = new Size(0, 12);
this.lblTip.TabIndex = 1;
base.AutoScaleDimensions = new SizeF(6f, 12f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(590, 0x152);
base.Controls.Add(this.lblTip);
base.Controls.Add(this.listView1);
base.Name = "Form1";
this.Text = "Form1";
base.Load += new EventHandler(this.Form1_Load);
base.ResumeLayout(false);
base.PerformLayout();
}
private void listView1_DoubleClick(object sender, EventArgs e)
{
if (this.listView1.SelectedItems.Count > 0)
{
string text = this.listView1.SelectedItems[0].Text;
string url = this.listView1.SelectedItems[0].SubItems[2].Text;
new IEView(this, url).Show();
}
}
private void LoadItem()
{
XmlDocument document = new XmlDocument();
document.Load(this.tempRssfile);
XmlNodeList list = document.SelectNodes("/rss/channel/item");
new XmlNamespaceManager(document.NameTable).AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
this.listView1.Items.Clear();
try
{
foreach (XmlNode node in list)
{
if (node.HasChildNodes)
{
string text = "";
string str2 = "";
string s = DateTime.Now.ToString();
foreach (XmlNode node2 in node.ChildNodes)
{
string name = node2.Name;
if (name != null)
{
if (!(name == "title"))
{
if (name == "link")
{
goto Label_0119;
}
if (name == "dc:creator")
{
goto Label_0124;
}
if (name == "author")
{
goto Label_012E;
}
if (name == "pubDate")
{
goto Label_0138;
}
}
else
{
text = node2.InnerText;
}
}
continue;
Label_0119:
str2 = node2.InnerText;
continue;
Label_0124:
string text1 = node2.InnerText;
continue;
Label_012E:
string text2 = node2.InnerText;
continue;
Label_0138:
s = node2.InnerText;
s = DateTime.Parse(s).ToString();
}
ListViewItem item = new ListViewItem(text, 0);
item.SubItems.Add(s);
item.SubItems.Add(str2);
this.listView1.Items.AddRange(new ListViewItem[] { item });
}
}
this.listView1.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
}
}
private void LoadRss()
{
this.LoadRss(this.RssPath);
}
private void LoadRss(string RssPath)
{
this.SetText("正在读取" + RssPath + "并校验…");
this.LoadXml2Coach(RssPath, this.tempRssfile);
this.SetText("正在读取RSS内容信息…");
this.SetListText();
this.SetText("完成");
}
private void LoadXml2Coach(string url, string tempfile)
{
try
{
XmlDocument document = new XmlDocument();
document.Load(url);
document.Save(tempfile);
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show("连接失败,请重试!");
}
}
private void SetListText()
{
if (this.listView1.InvokeRequired)
{
SetListCallback method = new SetListCallback(this.SetListText);
base.Invoke(method, null);
}
else
{
this.LoadItem();
}
}
private void SetText(string text)
{
if (this.lblTip.InvokeRequired)
{
SetTextCallback method = new SetTextCallback(this.SetText);
base.Invoke(method, new object[] { text });
}
else
{
this.lblTip.Text = text;
}
}
private delegate void SetListCallback();
private delegate void SetTextCallback(string text);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -