public static RssChannel Create( String rssUrl ) { RssChannel feed = new RssChannel(); RssImage img = new RssImage(); XmlTextReader reader = new XmlTextReader( rssUrl ); Boolean isNewItem = false; Boolean isImage = false; RssItem rssItem = new RssItem(); reader.MoveToContent(); while (reader.Read()) { if (!reader.Name.Equals( "channel" ) && ((reader.NodeType != XmlNodeType.Whitespace) && (reader.NodeType != XmlNodeType.Comment))) { if (((reader.NodeType == XmlNodeType.EndElement) && reader.Name.Equals( "item" )) && strUtil.HasText( rssItem.Title )) { feed.RssItems.Add( rssItem ); rssItem = new RssItem(); isNewItem = false; } else { if ((reader.NodeType == XmlNodeType.EndElement) && reader.Name.Equals( "image" )) { isImage = false; continue; } if (equal( reader, "image" )) { isImage = true; isNewItem = false; continue; } if (equal( reader, "item" )) { isNewItem = true; isImage = false; continue; } if (reader.NodeType == XmlNodeType.Element) { if (!(isNewItem || isImage)) { readRssChannel( feed, reader ); } else if (isNewItem) { readRssItem( rssItem, reader ); } else if (isImage) { readRssImage( img, reader ); } } } } } feed.RssImage = img; reader.Close(); return feed; }
public virtual RssChannel getRssByApp(long appId, int count) { List<BlogPost> newListAll = null; if (appId > 0) newListAll = this.GetNewBlog( appId, count ); else newListAll = this.GetNewListAll( count ); BlogApp app = BlogApp.findById( appId ); User user = User.findById( app.OwnerId ); IMemberApp uapp = new UserAppService().GetByApp( app ); RssChannel channel = new RssChannel(); channel.Title = uapp.Name + " -- " + user.Name + "'s blog"; channel.Link = Link.ToMember( user ); foreach (BlogPost post in newListAll) { RssItem rssItem = new RssItem(); rssItem.Title = post.Title; rssItem.Description = post.Content; rssItem.Category = post.Category.Name; rssItem.PubDate = post.Created; rssItem.Author = post.Creator.Name; rssItem["CreatorLink"] = channel.Link; rssItem["CreatorFace"] = post.Creator.PicSmall; rssItem.Link = alink.ToAppData( post ); channel.RssItems.Add( rssItem ); } return channel; }
private static void readRssChannel( RssChannel feed, XmlReader reader ) { if (equal( reader, "title" )) { feed.Title = reader.ReadString(); } else if (equal( reader, "link" )) { feed.Link = reader.ReadString(); } else if (equal( reader, "description" )) { feed.Description = reader.ReadString(); } else if (equal( reader, "pubdate" )) { feed.PubDate = parseTime( reader.ReadString() ); } else if (equal( reader, "language" )) { feed.Language = reader.ReadString(); } else if (equal( reader, "generator" )) { feed.Generator = reader.ReadString(); } else if (equal( reader, "lastbuilddate" )) { feed.LastBuildDate = parseTime( reader.ReadString() ); } }
private void downalodFeed( object arg ) { FeedSource f = arg as FeedSource; RssItemList articles; try { logger.Info( "RssChannel.Create=>" + f.FeedLink ); articles = RssChannel.Create( f.FeedLink ).RssItems; } catch (Exception ex) { logger.Error( "download rss:" + f.FeedLink ); logger.Error( ex.Message ); return; } //最后更新时间 f.LastRefreshTime = DateTime.Now; db.update( f, "LastRefreshTime" ); logger.Info( "download feed ok" ); RssChannel c = new RssChannel(); c.RssItems = articles; f.RssChannel = c; saveFeedItems( f ); }
public static RssChannel Create(String rssUrl) { RssChannel feed = new RssChannel(); RssImage img = new RssImage(); XmlTextReader reader = new XmlTextReader(rssUrl); Boolean isNewItem = false; Boolean isImage = false; RssItem rssItem = new RssItem(); reader.MoveToContent(); while (reader.Read()) { if (!reader.Name.Equals("channel") && ((reader.NodeType != XmlNodeType.Whitespace) && (reader.NodeType != XmlNodeType.Comment))) { if (((reader.NodeType == XmlNodeType.EndElement) && reader.Name.Equals("item")) && strUtil.HasText(rssItem.Title)) { feed.RssItems.Add(rssItem); rssItem = new RssItem(); isNewItem = false; } else { if ((reader.NodeType == XmlNodeType.EndElement) && reader.Name.Equals("image")) { isImage = false; continue; } if (equal(reader, "image")) { isImage = true; isNewItem = false; continue; } if (equal(reader, "item")) { isNewItem = true; isImage = false; continue; } if (reader.NodeType == XmlNodeType.Element) { if (!(isNewItem || isImage)) { readRssChannel(feed, reader); } else if (isNewItem) { readRssItem(rssItem, reader); } else if (isImage) { readRssImage(img, reader); } } } } } feed.RssImage = img; reader.Close(); return(feed); }