Exemple #1
0
        public static Headline[] ExtractHeadlines(NewsSource newsSource, string rawData)
        {
            switch (newsSource.DataFormat)
            {
            case DataFormat.Rss:
                var xmlDoc = XDocument.Parse(rawData);
                return((from channel in xmlDoc.Root.Elements("channel")
                        from item in channel.Elements("item")
                        select new Headline(newsSource, item.Element("title").Value)).ToArray());

            case DataFormat.TwitterJson:
                var javaScriptObject = (IEnumerable) new JavaScriptSerializer().DeserializeObject(rawData);
                return((from tweetInfo in javaScriptObject.Cast <IDictionary <string, object> >()
                        select new Headline(newsSource, (string)tweetInfo["text"])).ToArray());

            default:
                return(null);
            }
        }
        public static Headline[] ExtractHeadlines(NewsSource newsSource, string rawData)
        {
            switch (newsSource.DataFormat)
            {
                case DataFormat.Rss:
                    var xmlDoc = XDocument.Parse(rawData);
                    return (from channel in xmlDoc.Root.Elements("channel")
                            from item in channel.Elements("item")
                            select new Headline(newsSource, item.Element("title").Value)).ToArray();

                case DataFormat.TwitterJson:
                    var javaScriptObject = (IEnumerable)new JavaScriptSerializer().DeserializeObject(rawData);
                    return (from tweetInfo in javaScriptObject.Cast<IDictionary<string, object>>()
                            select new Headline(newsSource, (string)tweetInfo["text"])).ToArray();

                default:
                    return null;
            }
        }
Exemple #3
0
 public Headline(NewsSource source, string headlineText)
 {
     Source       = source;
     HeadlineText = headlineText;
 }
 public Headline(NewsSource source, string headlineText)
 {
     Source = source;
     HeadlineText = headlineText;
 }
 private async Task<Headline[]> FetchHeadlinesTaskAsync(NewsSource newsSource)
 {
     string rawData = await new WebClient().DownloadStringTaskAsync(newsSource.Url);
     return ParserUtils.ExtractHeadlines(newsSource, rawData);
 }