Exemple #1
0
        static FeedSegment LoadFeed(Uri feedUrl, XElement item)
        {
            var rf = new FeedSegment(feedUrl: feedUrl);

            foreach (XElement xe in item.Elements())
            {
                Func <FeedSegment, XElement, FeedSegment> action;
                if (FeedElements.TryGetValue(xe.Name, out action))
                {
                    rf = action(rf, xe);
                }
            }
            if (String.IsNullOrWhiteSpace(rf.FeedTitle))
            {
                string title = null;
                if (!String.IsNullOrWhiteSpace(rf.FeedDescription))
                {
                    title = rf.FeedDescription;
                }
                else if (!String.IsNullOrWhiteSpace(rf.WebsiteUrl))
                {
                    title = rf.WebsiteUrl;
                }
                else if (rf.FeedUrl != null)
                {
                    title = rf.FeedUrl.AbsoluteUri;
                }

                rf = rf.With(feedTitle: title);
            }
            return(rf);
        }
Exemple #2
0
        static FeedSegment HandleAtomLink(FeedSegment feed, XElement link)
        {
            string rel  = link.Attribute(XNames.Atom.Rel)?.Value ?? "alternate";
            string type = link.Attribute(XNames.Atom.Type)?.Value ?? "text/html";
            string href = link.Attribute(XNames.Atom.Href)?.Value;

            if (String.Equals(rel, "alternate", StringComparison.OrdinalIgnoreCase) &&
                type.StartsWith("text/html", StringComparison.OrdinalIgnoreCase))
            {
                feed = feed.With(websiteUrl: link.Attribute(XNames.Atom.Href)?.Value);
            }

            return(feed);
        }