Esempio n. 1
0
        public static FeedViewModel LoadFeed(string url, int limit)
        {
            FeedViewModel viewModel = new FeedViewModel();

            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.DtdProcessing = DtdProcessing.Parse;

                using (var reader = XmlReader.Create(url, xmlSettings))
                {
                    var feed = SyndicationFeed.Load(reader);
                    foreach (var post in feed.Items.Take(limit))
                    {
                        viewModel.Posts.Add(post);
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("Error: " + exc.Message);
                if (exc.InnerException != null)
                {
                    Console.WriteLine("Inner Error: " + exc.InnerException.Message);
                    if (exc.InnerException.InnerException != null)
                    {
                        Console.WriteLine("Inner Error (2): " + exc.InnerException.InnerException.Message);
                    }
                }
            }

            return viewModel;
        }
Esempio n. 2
0
        public static void TestFeed()
        {
            string url = "http://d3webpresence.com/?feed=rss2";
            int limit = 15;

            FeedViewModel viewModel = new FeedViewModel();

            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.DtdProcessing = DtdProcessing.Parse;

                using (var reader = XmlReader.Create(url, xmlSettings))
                {
                    var feed = SyndicationFeed.Load(reader);
                    foreach (var post in feed.Items.Take(limit))
                    {
                        Console.WriteLine("--- {0} ---", post.Title.Text);
                        Console.WriteLine(post.Summary.Text);
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("Error: " + exc.Message);
                if (exc.InnerException != null)
                {
                    Console.WriteLine("Inner Error: " + exc.InnerException.Message);
                    if (exc.InnerException.InnerException != null)
                    {
                        Console.WriteLine("Inner Error (2): " + exc.InnerException.InnerException.Message);
                    }
                }
            }
        }