FormUpdateRss.cs
上传用户:xtyqhl
上传日期:2022-06-07
资源大小:212k
文件大小:3k
源码类别:

Windows Mobile

开发平台:

Windows_Unix

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Xml;
  9. using System.Threading;
  10. namespace _3ESoft.WindowsMobile.RSS
  11. {
  12.     public partial class FormUpdateRss : Form
  13.     {
  14.         Opml myOpml;
  15.         Rss myRss = new Rss();
  16.         Thread process;
  17.         delegate void Update();
  18.         public FormUpdateRss(Opml opml, List<RssNews> rsslist)
  19.         {
  20.             InitializeComponent();
  21.             myOpml = opml;
  22.             myRss.RssNewsList = rsslist;
  23.         }
  24.         public FormUpdateRss(Opml opml)
  25.         {
  26.             InitializeComponent();
  27.             myOpml = opml;
  28.         }
  29.         private void FormUpdateRss_Load(object sender, EventArgs e)
  30.         {
  31.             process = new Thread(new ThreadStart(InvokeUpdate));
  32.             process.Start();
  33.         }
  34.         void InvokeUpdate()
  35.         {
  36.              object oo = new object();
  37.             lock (oo)
  38.             {
  39.                 Update ExecUpdate = new Update(ExecuteUpdate);
  40.                 this.Invoke(ExecUpdate);
  41.             }
  42.         }
  43.         void ExecuteUpdate()
  44.         {
  45.             if (myOpml.Type == RssType.Rss)
  46.             {
  47.                 ProgBar.Maximum = 100;
  48.                 ProgBar.Value = 20;
  49.                 UpdateRss(myOpml);
  50.                 ProgBar.Value = 100;
  51.                 lblProgress.Text = "已经更新 100%";
  52.             }
  53.             else if (myOpml.Type == RssType.Channel)
  54.             {
  55.                 XmlNode ChannelNode = OpmlHelper.GetChannelNode(myOpml.Title);
  56.                 ProgBar.Maximum = ChannelNode.ChildNodes.Count;
  57.                 ProgBar.Value = 0;
  58.                 foreach (XmlNode xNode in ChannelNode.ChildNodes)
  59.                 {
  60.                     Application.DoEvents();
  61.                     myOpml = new Opml();
  62.                     myOpml.Title = xNode.Attributes.GetNamedItem("title").InnerText;
  63.                     myOpml.XmlUrl = xNode.Attributes.GetNamedItem("xmlUrl").InnerText;
  64.                     myRss.GetRssNewsList(Global.FormatUrl(myOpml.XmlUrl));
  65.                     UpdateRss(myOpml);
  66.                     
  67.                 }
  68.                 
  69.             }
  70.         }
  71.         void UpdateRss(Opml myOpml)
  72.         {
  73.             Update start = new Update(UpdateStart);
  74.             this.Invoke(start);
  75.             Application.DoEvents();
  76.             myRss.UpdateRssNews(myOpml.XmlUrl);
  77.             ProgBar.Value += 1;
  78.             this.Invoke(start);
  79.             lblTitle.Text = "更新完毕。";
  80.         }
  81.         void UpdateStart()
  82.         {
  83.             lblProgress.Text = "已经更新 " +Convert.ToString( Decimal.Divide(ProgBar.Value, ProgBar.Maximum) * 100) + "%";
  84.             lblTitle.Text = "正在更新:" + myOpml.Title;
  85.         }
  86.         void UpdateFinished()
  87.         {
  88.             
  89.         }
  90.     }
  91. }