当前位置: 首页>>代码示例>>C#>>正文


C# Rss20FeedFormatter.CanRead方法代码示例

本文整理汇总了C#中System.ServiceModel.Syndication.Rss20FeedFormatter.CanRead方法的典型用法代码示例。如果您正苦于以下问题:C# Rss20FeedFormatter.CanRead方法的具体用法?C# Rss20FeedFormatter.CanRead怎么用?C# Rss20FeedFormatter.CanRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.Syndication.Rss20FeedFormatter的用法示例。


在下文中一共展示了Rss20FeedFormatter.CanRead方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFeeds

        public static IList<Feed> GetFeeds()
        {
            var urls = new[]
                {
                    "http://www.simplyvinay.com/GetBlogRss.aspx", "http://www.bbc.co.uk/blogs/formula1/rss.xml",
                    "http://feeds.feedburner.com/AyendeRahien"
                };
            var list = new List<Feed>();

            foreach (var url in urls)
            {
                using (var reader = new CustomXmlReader(url))
                {
                    if (reader.ReadState == ReadState.Initial)
                        reader.MoveToContent();

                    var atom = new Atom10FeedFormatter();
                    if (atom.CanRead(reader))
                    {
                        atom.ReadFrom(reader);
                        list.AddRange(GenerateFeed(atom.Feed, true));
                    }

                    var rss = new Rss20FeedFormatter();
                    if (rss.CanRead(reader))
                    {
                        rss.ReadFrom(reader);
                        list.AddRange(GenerateFeed(rss.Feed, false));
                    }
                }
            }
            return list;
        }
开发者ID:simplyvinay,项目名称:feedreader,代码行数:33,代码来源:Program.cs

示例2: GetFeed

        /// <summary>
        /// Gets an RSS feed from a given URL and returns the resulting XML as a string.
        /// </summary>
        /// <param name="url">URL of the feed to load.</param>
        /// <param name="count">The count of postings to return.</param>
        /// <returns>The feed XML as a string.</returns>
        public SyndicationFeed GetFeed(string url, int count)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.CheckCharacters = true;
            settings.CloseInput = true;
            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.ProhibitDtd = false;

                using (XmlReader reader = XmlReader.Create(url, settings))
                {
                    SyndicationFeedFormatter formatter = null;
                    Atom10FeedFormatter atom = new Atom10FeedFormatter();
                    Rss20FeedFormatter rss = new Rss20FeedFormatter();
                    SyndicationFeed feed;

                    // Determine the format of the feed
                    if (reader.ReadState == ReadState.Initial)
                    {
                        reader.MoveToContent();
                    }

                    if (atom.CanRead(reader))
                    {
                        formatter = atom;
                    }

                    if (rss.CanRead(reader))
                    {
                        formatter = rss;
                    }

                    if (formatter == null)
                    {
                        return null;
                    }

                    formatter.ReadFrom(reader);
                    feed = formatter.Feed;

                    // Remove unwanted items
                    List<SyndicationItem> items = new List<SyndicationItem>();

                    int added = 0;

                    foreach (SyndicationItem i in feed.Items)
                    {
                        items.Add(i);

                        if (added++ == count - 1) break;
                    }

                    feed.Items = items;
                    return feed;
                }
        }
开发者ID:nectide,项目名称:mvc2inaction,代码行数:63,代码来源:RssWidgetController.cs

示例3: CanRead

		public void CanRead ()
		{
			Rss20FeedFormatter f = new Rss20FeedFormatter ();
			Assert.IsTrue (f.CanRead (CreateReader ("<rss>")), "#1");
			Assert.IsFalse (f.CanRead (CreateReader ("<item>")), "#2");
			Assert.IsFalse (f.CanRead (CreateReader ("<rss xmlns='urn:foo'>")), "#3");
			Assert.IsFalse (f.CanRead (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'>")), "#4");
			Assert.IsFalse (f.CanRead (CreateReader ("<hoge>")), "#5");
			XmlReader r = CreateReader ("<rss></rss>");
			r.Read (); // element
			r.Read (); // endelement
			Assert.IsFalse (f.CanRead (r), "#6");

			r = CreateReader ("<rss><channel><title>test</title></channel></rss>");
			r.Read (); // feed
			r.Read (); // channel
			Assert.IsFalse (f.CanRead (r), "#7");
		}
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:Rss20FeedFormatterTest.cs

示例4: GetRssData

        /// <summary>
        /// Returns a <c>SyndicationFeed</c> given a valid feed url; 
        /// otherwhise it returns null.
        /// </summary>
        /// <param name="feedUrl">
        /// A string of the feed url.
        /// </param>
        /// <returns>
        /// A <c>SyndicationFeed</c> that may be null.
        /// </returns>
        private static SyndicationFeed GetRssData(string feedUrl)
        {
            SyndicationFeed feed = null;

            try
            {
                if (!string.IsNullOrEmpty(feedUrl))
                {
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreWhitespace = true;
                    settings.CheckCharacters = true;
                    settings.CloseInput = true;
                    settings.IgnoreComments = true;
                    settings.IgnoreProcessingInstructions = true;

                    using (XmlReader reader = XmlReader.Create(feedUrl, settings))
                    {
                        SyndicationFeedFormatter GenericFeedFormatter = null;
                        Atom10FeedFormatter atom = new Atom10FeedFormatter();
                        Rss20FeedFormatter rss = new Rss20FeedFormatter();

                        if (reader.ReadState == ReadState.Initial)
                        {
                            reader.MoveToContent();
                        }

                        // Try either atom or rss reading.
                        if (atom.CanRead(reader))
                        {
                            GenericFeedFormatter = atom;
                        }
                        else if (rss.CanRead(reader))
                        {
                            GenericFeedFormatter = rss;
                        }
                        if (GenericFeedFormatter == null)
                        {
                            return null;
                        }
                        GenericFeedFormatter.ReadFrom(reader);
                        feed = GenericFeedFormatter.Feed;
                    }
                }
            }
            catch (XmlException)
            {
                // Do nothing, but don't shut down
                // This will also make the function return null
            }

            return feed;
        }
开发者ID:feupeu,项目名称:NyhedsfilterP2,代码行数:62,代码来源:Aggregator.cs

示例5: GetFeed

        private SyndicationFeed GetFeed(string url)
        {
            using (XmlReader reader = XmlReader.Create(url))
            {
                Rss20FeedFormatter rss = new Rss20FeedFormatter();
                if (rss.CanRead(reader))
                {
                    rss.ReadFrom(reader);
                    return rss.Feed;
                }

                Atom10FeedFormatter atom = new Atom10FeedFormatter();
                if (atom.CanRead(reader))
                {
                    atom.ReadFrom(reader);
                    return atom.Feed;
                }
            }

            return null;
        }
开发者ID:scottmetoyer,项目名称:contingency-reader,代码行数:21,代码来源:FeedServices.cs

示例6: Read

        private void Read(Stream stream, Channel c, RssViewModel m)
        {
            var feedFormatter = new Atom10FeedFormatter();
            var rssFormater = new Rss20FeedFormatter();

            XmlReader atomReader = XmlReader.Create(stream);
            SyndicationFeedFormatter f = null;

            if (feedFormatter.CanRead(atomReader))
            {
                feedFormatter.ReadFrom(atomReader);
                atomReader.Close();
                f = feedFormatter;
            }
            else
                if (rssFormater.CanRead(atomReader))
                {
                    rssFormater.ReadFrom(atomReader);
                    atomReader.Close();
                    f = rssFormater;
                }

            if (f == null) return;

            SyndicationFeed feed = f.Feed;
            c.Title = feed.Title.Text;

            Article[] articles = feed.Items.Select(item => new Article
                {
                    PubDate = item.PublishDate.DateTime,
                    Description = item.Summary.Text,
                    Link = item.Links[0].Uri.OriginalString,
                    Title = item.Title.Text,
                }).Select(art => m.AddArticle(art, c)).ToArray();
            m.DeleteArticle(c.Articles.Where(x => !x.IsStared).Except(articles).ToArray(), c);
            c.LastUpdate = DateTime.Now;
        }
开发者ID:ozhehkovski,项目名称:RSS-Reader-WindowsPhone,代码行数:37,代码来源:ParseRSS.cs


注:本文中的System.ServiceModel.Syndication.Rss20FeedFormatter.CanRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。