Ejemplo n.º 1
0
        /// <summary>
        /// Fetches rss feeds data from BBC News
        /// </summary>
        private void FetchRssFeed()
        {
            try
            {
                string rssUrl = "http://www.theguardian.com/sport/rugbyleague/rss";

                XDocument  feedXml = XDocument.Load(rssUrl);
                XNamespace media   = XNamespace.Get("http://search.yahoo.com/mrss/");

                _feeds                         = from feed in feedXml.Descendants("item")
                                     let title = feed.Element("title")
                                                 where title != null
                                                 let description = feed.Element("description")
                                                                   where description != null
                                                                   let sourceUrl = feed.Element("link")
                                                                                   where sourceUrl != null
                                                                                   let pubDateTime = feed.Element("pubDate")
                                                                                                     where pubDateTime != null
                                                                                                     let imageUrl = feed.Elements(media + "content")
                                                                                                                    .Where(i => i.Attribute("width").Value == "140")
                                                                                                                    .Select(i => i.Attribute("url").Value).FirstOrDefault()
                                                                                                                    where imageUrl != null
                                                                                                                    select new NewsItem()
                {
                    Title       = _validate.TrimNewsLength(title.Value),
                    Description = _validate.TrimNewsLength(description.Value),
                    SourceUrl   = sourceUrl.Value,
                    SourceName  = "The Guardian",
                    ImageUrl    = imageUrl,
                    PubDateTime = DateTime.Parse(pubDateTime.Value)
                };

                _feeds = _feeds.OrderBy(x => x.PubDateTime);
            }
            catch (Exception ex)
            {
                _importMessage = "Unable to fetch The Guardian feeds: " + ex;
            }
        }
Ejemplo n.º 2
0
        public void TestValidateItem()
        {
            ValidateItem validate = new ValidateItem();

            string input          = "This is a really long test string to make sure the string is trimmed correctly by the validate method. This is a really long test string to make sure the string is trimmed correctly by the validate method.";
            int    exceptedLength = 150;
            int    actualLength   = validate.TrimNewsLength(input).Length;

            Console.WriteLine("Expected: " + exceptedLength);
            Console.WriteLine("Result: " + actualLength);

            Assert.AreEqual(exceptedLength, actualLength, "String successfully trimmed to 150 characters.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetches rss feeds data from BBC News
        /// </summary>
        private void FetchRssFeed()
        {
            try
            {
                string rssUrl = "http://feeds.bbci.co.uk/sport/0/rugby-league/rss.xml?edition=int";

                XDocument  feedXml = XDocument.Load(rssUrl);
                XNamespace media   = XNamespace.Get("http://search.yahoo.com/mrss/");

                _feeds                         = from feed in feedXml.Descendants("item")
                                     let title = feed.Element("title")
                                                 where title != null
                                                 let description = feed.Element("description")
                                                                   where description != null
                                                                   let sourceUrl = feed.Element("link")
                                                                                   where sourceUrl != null
                                                                                   let pubDateTime = feed.Element("pubDate")
                                                                                                     where pubDateTime != null
                                                                                                     select new NewsItem()
                {
                    Title       = _validate.TrimNewsLength(title.Value),
                    Description = _validate.TrimNewsLength(description.Value),
                    SourceUrl   = sourceUrl.Value,
                    SourceName  = "BBC Sport",
                    ImageUrl    = feed.Elements(media + "thumbnail")
                                  .Where(i => i.Attribute("width").Value == "144" && i.Attribute("height").Value == "81")
                                  .Select(i => i.Attribute("url").Value).FirstOrDefault(),
                    PubDateTime = DateTime.Parse(pubDateTime.Value)
                };

                _feeds = _feeds.OrderBy(x => x.PubDateTime);
            }
            catch (Exception ex)
            {
                _importMessage = "Unable to fetch BBC News feeds: " + ex;
            }
        }