Exemple #1
0
        public int getRssFeeds(object url)
        {
            try
               {
               //Fetch the subscribed RSS Feed
               XmlDocument RSSXml = new XmlDocument();
               RSSXml.Load(url.ToString());

               XmlNodeList RSSNodeList = RSSXml.SelectNodes("rss/channel/item");
               XmlNode RSSDesc = RSSXml.SelectSingleNode("rss/channel/title");
               RssReaderRepository rssReaderRepo = new RssReaderRepository();
               StringBuilder sb = new StringBuilder();

               foreach (XmlNode RSSNode in RSSNodeList)
               {
                   RssReader rssReader = new RssReader();

                   XmlNode RSSSubNode;
                   RSSSubNode = RSSNode.SelectSingleNode("title");
                   string title = RSSSubNode != null ? RSSSubNode.InnerText : "";

                   RSSSubNode = RSSNode.SelectSingleNode("link");
                   string link = RSSSubNode != null ? RSSSubNode.InnerText : "";

                   RSSSubNode = RSSNode.SelectSingleNode("description");
                   string desc = RSSSubNode != null ? RSSSubNode.InnerText : "";

                   RSSSubNode = RSSNode.SelectSingleNode("pubDate");
                   string publishDate = RSSSubNode != null ? RSSSubNode.InnerText : "";

                   rssReader.Id = Guid.NewGuid();
                   rssReader.Description = desc;
                   rssReader.Link = link;
                   rssReader.PublishedDate = publishDate;
                   rssReader.Title = title;
                   rssReader.FeedsUrl = url.ToString();
                   rssReader.CreatedDate = DateTime.Now;
                   rssReader.Status = false;

                   if (!rssReaderRepo.CheckFeedExists(url.ToString(), desc, publishDate))
                   {
                       rssReaderRepo.AddRssReader(rssReader);
                   }
               }
               return 0;
               }
               catch (Exception ex)
               {
               Console.WriteLine(ex.StackTrace);
               return 0;
               }
        }