Esempio n. 1
0
        public override void Run()
        {
            HeadlineCollection headlines = new HeadlineCollection();

            try
            {
                //DateTime now = DateTime.Now;
                DateTime now = DateTime.FromFileTime(0);

                string strFileName = Names.FeedsFolder + m_feedNode.FileName;
                if (File.Exists(strFileName))
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(strFileName);

                    FeedManager = new FeedManager(xmlDoc.NameTable);
                    FeedManager.TransferNamespaces(xmlDoc);

                    XmlNodeList xmlNodes = xmlDoc.SelectNodes("/rss/channel//item");

                    foreach (XmlNode xmlNode in xmlNodes)
                    {
                        string    title       = FeedManager.GetNodeContent(xmlNode, "title");
                        DateTime  dtPublished = FeedManager.GetNodeDate(xmlNode, "pubDate", now);
                        DateTime  dtReceived  = FeedManager.GetNodeDate(xmlNode, "comshak:rcvDate", now);
                        string    author      = FeedManager.GetNodeContent(xmlNode, "author");
                        string    desc        = FeedManager.GetNodeContent(xmlNode, "description", NCEncoding.String, NCType.Text);
                        string    link        = FeedManager.GetNodeContent(xmlNode, "link");
                        string    categ       = FeedManager.GetNodeContent(xmlNode, "category");
                        Enclosure enc         = FeedManager.GetEnclosure(xmlNode, "enclosure");

                        Headline headline = new Headline(title, dtPublished, dtReceived, author, desc, categ, enc);
                        headline.Link = link;
                        headlines.Add(headline);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                Utils.DbgOutExc("ReadChannelThread::Run()", ex);
            }
            catch (XmlException xmlEx)
            {
                Utils.DbgOutExc("ReadChannelThread::Run()", xmlEx);
            }
            //catch (Exception ex)
            //{
            //	Utils.DbgOutExc("ReadChannelThread::Run()", ex);
            //}
            finally
            {
                m_form.Invoke(new OnEndCallback(OnEnd), new object[] { headlines });
            }
        }
Esempio n. 2
0
        public void UpdateChannel(string strXmlUrl)
        {
            try
            {
                DateTime dtLastUpdate = DateTime.MinValue;
                string   strFileName  = Names.FeedsFolder + m_feedNode.FileName;

                XmlDocument xmlResponse = null;
                if (!String.IsNullOrEmpty(m_strTempFeedFile))
                {
                    if (System.IO.File.Exists(m_strTempFeedFile))
                    {
                        dtLastUpdate = DateTime.Now;
                        xmlResponse  = new XmlDocument();
                        xmlResponse.Load(m_strTempFeedFile);
                    }
                }
                else
                {
                    dtLastUpdate = GetLastUpdate(strFileName);
#if DEBUG
                    xmlResponse = Utils.DownloadXml(strXmlUrl, strFileName + ".xml", ref dtLastUpdate);
#else
                    xmlResponse = Utils.DownloadXml(strXmlUrl, null, ref dtLastUpdate);
#endif
                }

                if (xmlResponse != null)
                {
                    FeedManager             = new FeedManager(xmlResponse.NameTable);
                    FeedManager.LastUpdated = dtLastUpdate;
                    m_feedFormat            = FeedManager.TransferNamespaces(xmlResponse);
                    Debug.WriteLine("The feed is " + m_feedFormat);

                    MergeFeeds(strFileName, xmlResponse);
                }
            }
            catch (Exception ex)
            {
                Utils.DbgOutExc("UpdateChannelThread::UpdateChannel()", ex);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_strTempFeedFile))
                {
#if DEBUG
                    Utils.MoveFile(m_strTempFeedFile, Names.FeedsFolder + m_feedNode.FileName + ".xml");
#endif
                    Utils.DeleteFile(m_strTempFeedFile);
                }
            }
        }