Example #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 });
            }
        }
Example #2
0
        /// <summary>
        /// Writes items from an RSS feed (rdf:RDF).
        /// </summary>
        /// <param name="xmlDocument"></param>
        /// <param name="xmlWriter"></param>
        private void WriteRdfItems(XmlDocument xmlDocument, RssChannel rssChannel)
        {
            DateTime    now      = DateTime.Now;
            XmlNodeList xmlNodes = xmlDocument.SelectNodes("/rdf:RDF//rss:item", FeedManager.NsManager);

            foreach (XmlNode xmlNode in xmlNodes)
            {
                RssItem rssItem = new RssItem();
                rssItem.Title        = FeedManager.GetNodeContent(xmlNode, "rss:title");
                rssItem.Link         = FeedManager.GetNodeContent(xmlNode, "rss:link");
                rssItem.Published    = FeedManager.GetNodeContent(xmlNode, "dc:date");
                rssItem.ReceivedDate = now;
                //localItem.Author = GetNodeText(xmlNode, "???");
                rssItem.Description = FeedManager.GetNodeContent(xmlNode, "rss:description");
                rssChannel.AddItem(rssItem);
            }
        }
Example #3
0
        /// <summary>
        /// Merges an update XML (in any format) into the older local RSS channel XML file.
        /// </summary>
        /// <param name="strFileName">File name/path of the local RSS channel XML file.</param>
        /// <param name="xmlUpdate">XML of the update with the latest entries.</param>
        private void MergeFeeds(string strFileName, XmlDocument xmlUpdate)
        {
            try
            {
                RssChannel rssChannel = new RssChannel();
                rssChannel.FileName = strFileName;
                string strDefNamespace = FeedManager.DefaultNamespace;

                if (m_feedFormat == FeedFormat.Rss || m_feedFormat == FeedFormat.Rss2)
                {
                    rssChannel.Title       = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/rss/channel/title");
                    rssChannel.Link        = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/rss/channel/link");
                    rssChannel.Description = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/rss/channel/description");
                    rssChannel.LastUpdated = FeedManager.LastUpdated;

                    WriteRssItems(xmlUpdate, rssChannel);
                }
                else if (m_feedFormat == FeedFormat.Atom)
                {
                    FeedManager.AddNamespace("atom", strDefNamespace);

                    rssChannel.Title       = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/atom:feed/atom:title");
                    rssChannel.Link        = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/atom:feed/atom:link[@rel=\"alternate\" and @type=\"text/html\"]/@href");
                    rssChannel.Description = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/atom:feed/atom:subtitle");
                    rssChannel.LastUpdated = FeedManager.LastUpdated;

                    WriteAtomItems(xmlUpdate, rssChannel);
                }
                else if (m_feedFormat == FeedFormat.Rdf)
                {
                    FeedManager.AddNamespace("rss", strDefNamespace);

                    rssChannel.Title       = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/rdf:RDF/rss:channel/rss:title");
                    rssChannel.Link        = FeedManager.GetNodeContent(xmlUpdate.DocumentElement, "/rdf:RDF/rss:channel/rss:link");
                    rssChannel.LastUpdated = FeedManager.LastUpdated;

                    WriteRdfItems(xmlUpdate, rssChannel);
                }

                rssChannel.Merge();
            }
            catch (Exception ex)
            {
                Utils.DbgOutExc("UpdateChannelThread::MergeFeeds()", ex);
            }
        }
Example #4
0
        /// <summary>
        /// Writes items from an ATOM feed.
        /// </summary>
        /// <param name="xmlDocument"></param>
        /// <param name="xmlWriter"></param>
        private void WriteAtomItems(XmlDocument xmlDocument, RssChannel rssChannel)
        {
            NCEncoding  encoding = NCEncoding.String;
            DateTime    now      = DateTime.Now;
            XmlNodeList xmlNodes = xmlDocument.SelectNodes("/atom:feed//atom:entry", FeedManager.NsManager);

            foreach (XmlNode xmlNode in xmlNodes)
            {
                RssItem rssItem = new RssItem();
                rssItem.Title        = FeedManager.GetNodeContent(xmlNode, "atom:title");
                rssItem.Link         = FeedManager.GetNodeContent(xmlNode, "atom:link[@rel=\"alternate\" and @type=\"text/html\"]/@href");
                rssItem.Published    = FeedManager.GetNodeContentFrom(xmlNode, s_arrAtomPubDate, ref encoding);
                rssItem.ReceivedDate = now;
                rssItem.Author       = FeedManager.GetNodeContent(xmlNode, "atom:author/atom:name");
                rssItem.Description  = FeedManager.GetNodeContentFrom(xmlNode, s_arrAtomDesc, ref encoding);
                rssItem.Encoding     = encoding;
                rssChannel.AddItem(rssItem);
            }
        }
Example #5
0
        /// <summary>
        /// Writes items from an RSS feed.
        /// </summary>
        /// <param name="xmlDocument"></param>
        /// <param name="xmlWriter"></param>
        private void WriteRssItems(XmlDocument xmlDocument, RssChannel rssChannel)
        {
            NCEncoding  encoding = NCEncoding.String;
            DateTime    now      = DateTime.Now;
            XmlNodeList xmlNodes = xmlDocument.SelectNodes("/rss/channel//item", FeedManager.NsManager);

            foreach (XmlNode xmlNode in xmlNodes)
            {
                RssItem rssItem = new RssItem();
                rssItem.Title        = FeedManager.GetNodeContent(xmlNode, "title");
                rssItem.Link         = FeedManager.GetNodeContent(xmlNode, "link");
                rssItem.Published    = FeedManager.GetNodeContentFrom(xmlNode, s_arrRssPubDate, ref encoding);
                rssItem.ReceivedDate = now;
                rssItem.Author       = FeedManager.GetNodeContentFrom(xmlNode, s_arrRssAuthor, ref encoding);
                rssItem.Description  = FeedManager.GetNodeContentFrom(xmlNode, s_arrRssDesc, ref encoding);
                rssItem.Category     = FeedManager.GetNodeContent(xmlNode, "category");
                rssItem.Encoding     = encoding;
                rssItem.Enclosure    = FeedManager.GetEnclosure(xmlNode, "enclosure");
                rssChannel.AddItem(rssItem);
            }
        }