FormUpdateRss.cs
资源名称:MobileRss.rar [点击查看]
上传用户:xtyqhl
上传日期:2022-06-07
资源大小:212k
文件大小:3k
源码类别:
Windows Mobile
开发平台:
Windows_Unix
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Xml;
- using System.Threading;
- namespace _3ESoft.WindowsMobile.RSS
- {
- public partial class FormUpdateRss : Form
- {
- Opml myOpml;
- Rss myRss = new Rss();
- Thread process;
- delegate void Update();
- public FormUpdateRss(Opml opml, List<RssNews> rsslist)
- {
- InitializeComponent();
- myOpml = opml;
- myRss.RssNewsList = rsslist;
- }
- public FormUpdateRss(Opml opml)
- {
- InitializeComponent();
- myOpml = opml;
- }
- private void FormUpdateRss_Load(object sender, EventArgs e)
- {
- process = new Thread(new ThreadStart(InvokeUpdate));
- process.Start();
- }
- void InvokeUpdate()
- {
- object oo = new object();
- lock (oo)
- {
- Update ExecUpdate = new Update(ExecuteUpdate);
- this.Invoke(ExecUpdate);
- }
- }
- void ExecuteUpdate()
- {
- if (myOpml.Type == RssType.Rss)
- {
- ProgBar.Maximum = 100;
- ProgBar.Value = 20;
- UpdateRss(myOpml);
- ProgBar.Value = 100;
- lblProgress.Text = "已经更新 100%";
- }
- else if (myOpml.Type == RssType.Channel)
- {
- XmlNode ChannelNode = OpmlHelper.GetChannelNode(myOpml.Title);
- ProgBar.Maximum = ChannelNode.ChildNodes.Count;
- ProgBar.Value = 0;
- foreach (XmlNode xNode in ChannelNode.ChildNodes)
- {
- Application.DoEvents();
- myOpml = new Opml();
- myOpml.Title = xNode.Attributes.GetNamedItem("title").InnerText;
- myOpml.XmlUrl = xNode.Attributes.GetNamedItem("xmlUrl").InnerText;
- myRss.GetRssNewsList(Global.FormatUrl(myOpml.XmlUrl));
- UpdateRss(myOpml);
- }
- }
- }
- void UpdateRss(Opml myOpml)
- {
- Update start = new Update(UpdateStart);
- this.Invoke(start);
- Application.DoEvents();
- myRss.UpdateRssNews(myOpml.XmlUrl);
- ProgBar.Value += 1;
- this.Invoke(start);
- lblTitle.Text = "更新完毕。";
- }
- void UpdateStart()
- {
- lblProgress.Text = "已经更新 " +Convert.ToString( Decimal.Divide(ProgBar.Value, ProgBar.Maximum) * 100) + "%";
- lblTitle.Text = "正在更新:" + myOpml.Title;
- }
- void UpdateFinished()
- {
- }
- }
- }