コード例 #1
0
        public static void updateBlogATOMPosts(Blog blog)
        {
            Argotic.Syndication.AtomFeed feed = AtomFeed.Create(new Uri(blog.FeedURL));
            try
            {
                DataStorage.LogFeedRequest(blog.BlogID, feed.CreateNavigator().OuterXml);
            }
            catch
            { }

            Jiyuu.Aggregation.Common.Data.Lite.BlogPost bp = new Jiyuu.Aggregation.Common.Data.Lite.BlogPost();
            foreach (AtomEntry item in feed.Entries)
            {
                try
                {
                    if (item.Content != null)
                        bp.Content = System.Web.HttpUtility.HtmlDecode(item.Content.Content);
                    else
                        bp.Content = System.Web.HttpUtility.HtmlDecode(item.Summary.Content);

                    if (item.Summary != null)
                        bp.Summary = getExcerpt(System.Web.HttpUtility.HtmlDecode(item.Summary.Content));
                    else
                        bp.Summary = getExcerpt(bp.Content);
                    bp.PublicationTS = item.PublishedOn;
                    AtomLink link = item.Links.SingleOrDefault(l => l.ContentType == "alternate");
                    if (link != null)
                        bp.Link = link.Uri.ToString();
                    else
                        bp.Link = item.Links[item.Links.Count - 1].Uri.ToString();

                    bp.Title = item.Title.Content;
                    bp.Guid = item.Id.Uri.ToString();

                    if (item.Authors.Count > 0 && item.Authors[0].Name != string.Empty)
                        bp.PostAuthor = item.Authors[0].Name;
                    else
                        if (feed.Authors.Count > 0 && feed.Authors[0].Name != string.Empty)
                            bp.PostAuthor = feed.Authors[0].Name;
                        else
                            bp.PostAuthor = "Anon";

                    bp.Categories = new Jiyuu.Aggregation.Common.SharedData.CategoriesCollection();

                    foreach (AtomCategory cat in item.Categories)
                    {
                        bp.Categories.AddCategory(cat.Term);
                    }

                    try
                    {
                        DataStorage.SaveBlogPost(bp, blog);
                    }
                    catch { }
                }
                catch
                {
                    throw;
                }
                //bp.PostAuthor
                //((Argotic.Extensions.Core.SiteSummaryContentSyndicationExtension)(item.Summary.ToArray()[1])).Context.Encoded;
            }
        }
コード例 #2
0
        public static void updateBlogRSS2Posts(Blog blog)
        {
            //ISyndicationResource, IExtensibleSyndicationObject
            //Argotic.Extensions.IExtensibleSyndicationObject a;
            Argotic.Syndication.RssFeed feed = RssFeed.Create(new Uri(blog.FeedURL));
            try
            {
                DataStorage.LogFeedRequest(blog.BlogID, feed.CreateNavigator().OuterXml);
            }
            catch
            { }

            Jiyuu.Aggregation.Common.Data.Lite.BlogPost bp = new Jiyuu.Aggregation.Common.Data.Lite.BlogPost();
            foreach (RssItem item in feed.Channel.Items)
            {
                bp.Summary = getExcerpt(System.Web.HttpUtility.HtmlDecode(item.Description));
                bp.PublicationTS = item.PublicationDate;
                bp.Link = item.Link.ToString();
                bp.Title = item.Title;
                bp.Guid = item.Guid.Value;

                Argotic.Extensions.ISyndicationExtension ise = item.FindExtension(p => p.XmlPrefix == "content");
                if (ise is SiteSummaryContentSyndicationExtension)
                    bp.Content = System.Web.HttpUtility.HtmlDecode(((SiteSummaryContentSyndicationExtension)ise).Context.Encoded);
                else
                    bp.Content = bp.Summary;

                if (item.Author != string.Empty)
                    bp.PostAuthor = item.Author;
                else
                {
                    ise = item.FindExtension(p => p.XmlPrefix == "dc");
                    if (ise is DublinCoreElementSetSyndicationExtension)
                        bp.PostAuthor = ((DublinCoreElementSetSyndicationExtension)ise).Context.Creator;
                }

                bp.Categories = new CategoriesCollection();
                foreach (RssCategory category in item.Categories)
                {
                    bp.Categories.AddCategory(category.Value);
                }
                try
                {
                    DataStorage.SaveBlogPost(bp, blog);
                }
                catch { }
                //bp.PostAuthor
                //((Argotic.Extensions.Core.SiteSummaryContentSyndicationExtension)(item.Summary.ToArray()[1])).Context.Encoded;
            }
        }