private static void CleanHistory(FeedItem feedItem, Rss.RssFeed feed) { if (feed != null) { if (feed.Channels.Count > 0) { ArrayList arrayHistoryList = Settings.Default.History.GetItemsByFeedGUID(feedItem.GUID); foreach (HistoryItem historyItem in arrayHistoryList) { bool boolFound = false; foreach (Rss.RssItem rssItem in feed.Channels[0].Items) { if (rssItem.GetHashCode() == historyItem.Hashcode) { boolFound = true; break; } } if (boolFound == false) { //remove the entry from the historylist Settings.Default.History.Remove(historyItem); } } } } }
static void Main(string[] args) { #region Write Update RSS Feed #region 101 RssItem item = new RssItem(); item.Title = "105"; item.Comments = "1.0.0.105"; item.Description = "Freies Funknetz Switcher Version 1.0.0.105\n\n" + "* \"Bake wiederholen\" Text in \"Bake aktiviert\" geändert\n" + "* Fehler gefixt der dazu geführt hat dass eine Bake ununterbrochen wiederholt wurde\n"+ "* Voice Schaltung nocheinmal überarbeitet jetzt erfolgt nurnoch eine Deaktiviert/Aktiviert\n"+ " Meldung und sonst keine Änderung im Verhalten des Switchers\n"; item.PubDate = DateTime.Now.ToUniversalTime(); item.Link = new System.Uri("http://dropbox.schrankmonster.de/dropped/FFN-Switcher-105.zip"); #endregion RssChannel channel = new RssChannel(); channel.Items.Add(item); channel.Title = "Freies Funknetz Switcher Tool Update Channel"; channel.Description = "Updates for FFN Switcher"; channel.Link = new System.Uri("http://dropbox.schrankmonster.de/FFNSwitcher.xml"); channel.Generator = "FFN Switcher Update Tool"; channel.LastBuildDate = DateTime.Now; RssFeed feed = new RssFeed(); feed.Channels.Add(channel); feed.Write("FFNSwitcher.xml"); #endregion }
protected override void Render(HtmlTextWriter writer) { RssChannel channel = new RssChannel(); TopicCollection topics = RepositoryRegistry.TopicRepository.FindByForumId(forumID); foreach (Topic topic in topics) { RssItem item = new RssItem(); item.Title = topic.Name; item.Description = topic.Name; item.PubDate = DateTime.Now.ToUniversalTime(); item.Author = topic.Author.Name; item.Link = new Uri(ForumApplication.Instance.GetLink(SharePointForumControls.ViewMessages, "topic={0}", topic.Id)); channel.Items.Add(item); } channel.Title = ForumApplication.Instance.Title; channel.Description = ForumApplication.Instance.Title; channel.LastBuildDate = channel.Items.LatestPubDate(); channel.Link = new Uri(ForumApplication.Instance.BasePath); RssFeed feed = new RssFeed(); feed.Channels.Add(channel); Page.Response.Clear(); Page.Response.ContentType = "text/xml"; feed.Write(Page.Response.OutputStream); Page.Response.End(); }
private void btnRetrieveFeed_Click(object sender, EventArgs e) { RSSServiceClient client = new RSSServiceClient(); Rss.RssFeed feed = client.GetFeed(); DisplayChannel(feed.Channels[0]); }
public void BuildIssue() { var data = Proxy.Repository<Issue>() .GetAll(p=>!p.IsDeleted) .OrderByDescending(p => p.CreateDate) .Take(50); var channel = new RssChannel { Title = string.Format("{0} - Issues", Config.Literal.SITE_NAME), Link = new Uri(Config.URL.Domain), Description = string.Format("{0} - Issues", Config.Literal.SITE_NAME), PubDate = DateTime.Now, LastBuildDate = DateTime.Now, Language = "zh-cn", Copyright = Config.Literal.COPYRIGHT }; var template = File.ReadAllText(Config.Path.PHYSICAL_ROOT_PATH + "bin/RSS/issue.cshtml"); foreach (var item in data) { channel.Items.Add(BuildIssueItem(item, template)); } var feed = new RssFeed(Encoding.UTF8); feed.Channels.Add(channel); feed.Write(Config.Path.PHYSICAL_ROOT_PATH + Config.Path.ISSUES_RSS_PATH); }
/// <summary> /// On update, update items. /// </summary> protected override void OnUpdate() { try { if (_feed == null) { _feed = RssFeed.Read(base.Address); if (_feed.Channels.Count == 1) { // Some feeds have those symbols in their names. _name = _feed.Channels[0].Title.Replace("\r", "").Replace("\n", "").Trim(); } else { _name = _feed.Url.ToString(); } List<string> names = new List<string>(); foreach (RssChannel channel in _feed.Channels) { names.Add(channel.Title); } foreach (string name in names) { if (ChannelsNames.Contains(name) == false) { EventSourceChannel channel = new EventSourceChannel(name, true); channel.Initialize(this); base.AddChannel(channel); } } } else { _feed = RssFeed.Read(_feed); } //OperationalStateEnum newState = OperationalStateEnum.Operational; } catch (WebException we) {// Feed not found or some other problem. SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + we.Message + "]"); ChangeOperationalState(OperationalStateEnum.NotOperational); } catch (Exception ex) {// RssFeed class launches IOExceptions too, so get safe here. SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + ex.Message + "]"); ChangeOperationalState(OperationalStateEnum.NotOperational); } DoUpdateItems(); //RaisePersistenceDataUpdatedEvent(); }
public void RenderRssChannel(RssChannel rssChannel) { RssFeed rssFeed = new RssFeed(); rssFeed.Channels.Add(rssChannel); this.Response.ContentType = "text/xml"; rssFeed.Write(this.Response.OutputStream); this.Response.End(); }
private void BuildComment() { var data = _commentRepository.GetAll(p => !p.IsDeleted).OrderByDescending(p => p.CreateDate).Take(50); var feed = new RssFeed(Encoding.UTF8); var channel = BuildCommentRssChannel(); foreach (var item in data) { channel.Items.Add(BuildCommentRssItem(item)); } feed.Channels.Add(channel); feed.Write(AppDomain.CurrentDomain.BaseDirectory+Config.Path.COMMENTS_RSS_PATH); }
/// <summary> /// Deserializes the feed. /// </summary> /// <param name="feedItem">The feed item.</param> /// <returns></returns> public static Rss.RssFeed DeserializeFeed(FeedItem feedItem) { Rss.RssFeed rssExistingFeed = null; try { //XmlSerializer ser = new XmlSerializer(typeof(Rss.RssFeed)); string fileToOpen = String.Format("{0}\\{1}.bin", DataFolder, feedItem.FeedHashCode); if (File.Exists(fileToOpen)) { BinaryFormatter ser = new BinaryFormatter(); FileStream stream = File.Open(fileToOpen, FileMode.Open, FileAccess.Read); rssExistingFeed = (Rss.RssFeed)ser.Deserialize(stream); stream.Close(); } } catch { } return(rssExistingFeed); }
/// <summary> /// Serializes the feed. /// </summary> /// <param name="rssFeed">The RSS feed.</param> public static void SerializeFeed(Rss.RssFeed rssFeed) { try { BinaryFormatter ser = new BinaryFormatter(); // XmlSerializer ser = new XmlSerializer(typeof(Rss.RssFeed)); if (rssFeed != null) { FileStream stream = File.Create(DataFolder + "\\" + rssFeed.GetHashCode().ToString("X") + ".bin"); ser.Serialize(stream, rssFeed); stream.Close(); } } catch (Exception) { //MessageBox.Show("An error occurred while saving the feed to the local cache:\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public void CheckRss() { //RSS try{ CBO_TitleNews.Model=modelFlux; rssFeed =RssFeed.Read(MainClass.UrlPlanet); RssChannel rssChannel = (RssChannel)rssFeed.Channels[0]; int i = 0; string latest=""; foreach (RssItem item in rssChannel.Items) { string titre=item.Title; modelFlux.AppendValues(titre,i); if(latest =="")latest=item.Link.AbsoluteUri.ToString(); i++; } InformNewFlux(latest); } catch{} }
private void dgvOPML_CellContentClick(object sender, DataGridViewCellEventArgs e) { switch (e.ColumnIndex) { case 0: //Check break; case 1: //Text //The following line would return the URL for the feed //dgvOPML.Rows[e.RowIndex].Cells[4].Value.ToString(); //In Part I of this chapter, we use a fixed feed RSSServiceClient client = new RSSServiceClient(); Rss.RssFeed feed = client.GetFeed(); DisplayChannel(feed.Channels[0]); //Display the feed in the secondary data grid break; case 2: //Categories break; case 3: //Description break; case 4: //xmlUrl break; case 5: // type break; case 6: //version break; default: break; } }
/// <summary>Copies the entire RssFeedCollection to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array.</summary> /// <param name="array">The one-dimensional RssFeed Array that is the destination of the elements copied from RssFeedCollection. The Array must have zero-based indexing.</param> /// <param name="index">The zero-based index in array at which copying begins.</param> /// <exception cref="ArgumentNullException">array is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentOutOfRangeException">index is less than zero.</exception> /// <exception cref="ArgumentException">array is multidimensional. -or- index is equal to or greater than the length of array.-or-The number of elements in the source RssFeedCollection is greater than the available space from index to the end of the destination array.</exception> public void CopyTo(RssFeed[] array, int index) { List.CopyTo(array, index); }
static void Main(string[] args) { RssFeed r = new RssFeed(); r.Version = RssVersion.RSS20; RssItem ri1a = new RssItem(); ri1a.Author = "Test Author 1a"; ri1a.Title = "Test Title 1a"; ri1a.Description = "Test Description 1a"; ri1a.Link = new Uri("http://www.yourserver.com/"); ri1a.PubDate = DateTime.Now; RssItem ri1b = new RssItem(); ri1b.Author = "Test Author 1b"; ri1b.Title = "Test Title 1b"; ri1b.Description = "Test Description 1b"; ri1b.Link = new Uri("http://www.yourserver.com/"); ri1b.PubDate = DateTime.Now; RssChannel rc1 = new RssChannel(); rc1.Items.Add(ri1a); rc1.Items.Add(ri1b); rc1.Title = "Test Channel Title 1"; rc1.Description = "Test Channel Description 1"; rc1.Link = new Uri("http://www.yourserver.com/channel.html"); rc1.PubDate = DateTime.Now; r.Channels.Add(rc1); RssPhotoAlbumCategoryPhotoPeople pacpp = new RssPhotoAlbumCategoryPhotoPeople("John Doe"); RssPhotoAlbumCategoryPhoto pacp1 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 12, 0, 0)), "Test Photo Description 1", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=123"), pacpp); RssPhotoAlbumCategoryPhoto pacp2 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=124")); RssPhotoAlbumCategoryPhoto pacp3 = new RssPhotoAlbumCategoryPhoto(DateTime.Now.Subtract(new TimeSpan(2, 10, 0, 0)), "Test Photo Description 2", new Uri("http://www.yourserver.com/PhotoAlbumWeb/GetPhoto.aspx?PhotoID=125")); RssPhotoAlbumCategoryPhotos pacps = new RssPhotoAlbumCategoryPhotos(); pacps.Add(pacp1); pacps.Add(pacp2); RssPhotoAlbumCategory pac1 = new RssPhotoAlbumCategory("Test Photo Album Category 1", "Test Photo Album Category Description 1", DateTime.Now.Subtract(new TimeSpan(5, 10, 0, 0)), DateTime.Now, pacps); RssPhotoAlbumCategory pac2 = new RssPhotoAlbumCategory("Test Photo Album Category 2", "Test Photo Album Category Description 2", DateTime.Now.Subtract(new TimeSpan(9, 10, 0, 0)), DateTime.Now, pacp3); RssPhotoAlbumCategories pacs = new RssPhotoAlbumCategories(); pac1.BindTo(ri1a.GetHashCode()); pac2.BindTo(ri1b.GetHashCode()); pacs.Add(pac1); pacs.Add(pac2); RssPhotoAlbum pa = new RssPhotoAlbum(new Uri("http://your.web.server/PhotoAlbumWeb"), pacs); pa.BindTo(rc1.GetHashCode()); r.Modules.Add(pa); RssItem ri2 = new RssItem(); ri2.Author = "Test Author 2"; ri2.Title = "Test Title 2"; ri2.Description = "Test Description 2"; ri2.Link = new Uri("http://www.yourotherserver.com/"); ri2.PubDate = DateTime.Now; RssChannel rc2 = new RssChannel(); rc2.Items.Add(ri2); rc2.Title = "Test Channel Title 2"; rc2.Description = "Test Channel Description 2"; rc2.Link = new Uri("http://www.yourotherserver.com/channel.html"); rc2.PubDate = DateTime.Now; r.Channels.Add(rc2); r.Write("out.xml"); RssBlogChannel rbc = new RssBlogChannel(new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com"), new Uri("http://www.google.com")); }
/// <summary> /// Gets the RSS feed. /// </summary> /// <param name="feedItem">The feed item.</param> /// <returns></returns> public static Rss.RssFeed GetFeed(FeedItem feedItem, bool OnlyCache) { Rss.RssFeed rssFeed = null; Rss.RssFeed rssExistingFeed = null; if (feedItem.FeedHashCode != "" && feedItem.FeedHashCode != null && File.Exists(DataFolder + "\\" + feedItem.FeedHashCode + ".bin")) { try { //XmlSerializer ser = new XmlSerializer(typeof(Rss.RssFeed)); BinaryFormatter ser = new BinaryFormatter(); FileStream stream = File.Open(DataFolder + "\\" + feedItem.FeedHashCode + ".bin", FileMode.Open, FileAccess.Read); rssExistingFeed = (Rss.RssFeed)ser.Deserialize(stream); stream.Close(); if (OnlyCache == false) { if (feedItem.Authenticate == true) { rssFeed = Rss.RssFeed.Read(rssExistingFeed, feedItem.Username, feedItem.Password); } else { rssFeed = Rss.RssFeed.Read(rssExistingFeed); } SerializeFeed(rssFeed); } else { rssFeed = rssExistingFeed; } } catch { // something went wrong try { if (feedItem.Authenticate == true) { rssFeed = Rss.RssFeed.Read(feedItem.Url, feedItem.Username, feedItem.Password); } else { rssFeed = Rss.RssFeed.Read(feedItem.Url); } } catch (ApplicationException ex) { if (Settings.Default.LogLevel > 0) { log.Error("GetFeed", ex); } } SerializeFeed(rssFeed); } } else { try { rssFeed = Rss.RssFeed.Read(feedItem.Url); SerializeFeed(rssFeed); } catch (ApplicationException ex) { if (Settings.Default.LogLevel > 0) { log.Error("GetFeed", ex); } } try { if (rssFeed != null && !File.Exists(Path.Combine(Utils.DataFolder, rssFeed.GetHashCode().ToString("X") + ".ico"))) { GetFavIcon(new Uri(rssFeed.Channels[0].Link), rssFeed.GetHashCode().ToString("X")); } } catch { } try { if (rssFeed != null && !File.Exists(Path.Combine(Utils.DataFolder, rssFeed.GetHashCode().ToString("X") + ".jpg"))) { GetFeedImage(new Uri(rssFeed.Channels[0].Image.Url), rssFeed.GetHashCode().ToString("X")); } } catch { } } if (rssFeed != null) { Settings.Default.Feeds[feedItem].FeedHashCode = rssFeed.GetHashCode().ToString("X"); } return(rssFeed); }
private static RssFeed read(Stream stream) { RssFeed feed = new RssFeed(); RssElement element = null; if (stream != null) { RssReader reader = null; try { reader = new RssReader(stream); do { element = reader.Read(); if (element is RssChannel) feed.Channels.Add((RssChannel)element); } while (element != null); feed.rssVersion = reader.Version; } finally { feed.exceptions = reader.Exceptions; reader.Close(); } } else throw new ApplicationException("Not a valid Url"); return feed; }
/// <summary>Determines whether the RssFeedCollection contains a specific element.</summary> /// <param name="rssFeed">The RssFeed to locate in the RssFeedCollection.</param> /// <returns>true if the RssFeedCollection contains the specified value; otherwise, false.</returns> public bool Contains(RssFeed rssFeed) { return List.Contains(rssFeed); }
private void ParseRss(FeedItem feedItem, string strDownloadlocation) { log4net.NDC.Push("ParseRss"); try { //RssReader rssReader = new RssReader(feedItem,false,null); //rssReader.RdfMode = false; if (SetFeedStatus != null) { SetFeedStatus(lvi, 1, feedItem.Pubdate, FormStrings.RetrievingRSS); } //RssFeed feed = rssReader.Retrieve(); try { Rss.RssFeed feed = Utils.GetFeed(feedItem); if (feed != null) { // first clean up the history CleanHistory(feedItem, feed); // set the description of the feed //if ( feed.ErrorMessage == null || feed.ErrorMessage == "" ) //{ if (feed.Exceptions.Count == 0) { //RssItems items = feed.Items; //int intItems = items.Count; int intItemCount = 0; //for(int q=0;q<intItems;q++) //{ feed.Channels[0].Items.Sort(); foreach (Rss.RssItem rssItem in feed.Channels[0].Items) { if (SetFeedStatus != null) { SetFeedStatus(lvi, 1, feedItem.Pubdate, "Parsing items"); } //hist.ReRead(); //Application.DoEvents(); //RssItem rssItem = items[q]; #region // Default : Enclosures //if(rssItem.Enclosures != null) //{ if (rssItem.Enclosure != null) { if (intItemCount < feedItem.RetrieveNumberOfFiles || feedItem.RetrieveNumberOfFiles == 0) { intItemCount++; // EnclosureItem enc = rssItem.Enclosures[y]; bool validUri = false; System.Uri uri = null; try { uri = new Uri(rssItem.Enclosure.Url); validUri = true; } catch (UriFormatException ex) { boolError = true; if (Settings.Default.LogLevel > 0) { log.Error(String.Format("Invalid enclosure url for {0} ({1})", feedItem.Title, rssItem.Enclosure.Url), ex); } } if (validUri) { // check if the enclosure is already in the history if (Settings.Default.History[rssItem.GetHashCode().ToString()] == null) { string strPath = GetValidFilename(uri.LocalPath.Substring(uri.LocalPath.LastIndexOf("/") + 1)); string strFilename = Path.Combine(strDownloadlocation, strPath); if (!Directory.Exists(strDownloadlocation)) { try { Directory.CreateDirectory(strDownloadlocation); } catch (DirectoryNotFoundException ex) { if (Settings.Default.LogLevel > 1) { log.Error("Error creating directory", ex); } boolError = true; return; } } DownloadPackage downloadPackage = GetDownloadPackage(rssItem, feedItem, strDownloadlocation); long longDownloadsize = downloadPackage.DownloadSize; if (downloadPackage.strFilename != null) { strFilename = downloadPackage.strFilename; } if (longDownloadsize > 0) { if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging); } else { FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging); } } // update the FeedItem with an last update date and the description feedItem.Pubdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (feed.Channels[0].Description != null) { feedItem.Description = feed.Channels[0].Description; } Settings.Default.Feeds[feedItem.GUID] = feedItem; } } } } #endregion } } } } catch (WebException wex) { if (Settings.Default.LogLevel > 0) { log.Error("Retriever", wex); } } } catch (ThreadAbortException) { //MessageBox.Show("TA"); } log4net.NDC.Pop(); }
/// <summary>Removes a specified category from this collection.</summary> /// <param name="feed">The category to remove.</param> public void Remove(RssFeed feed) { List.Remove(feed); }
/// <summary>Inserts a feed into this collection at a specified index.</summary> /// <param name="index">The zero-based index of the collection at which to insert the feed.</param> /// <param name="feed">The feed to insert into this collection.</param> public void Insert(int index, RssFeed feed) { List.Insert(index, feed); }
public override void OnUpdate() { OperationalStateEnum newState; try { if (_feed == null) { _feed = RssFeed.Read(base.Address); if (_feed.Channels.Count == 1) { // Some feeds have those symbols in their names. _name = _feed.Channels[0].Title.Replace("\r", "").Replace("\n", "").Trim(); } else { _name = _feed.Url.ToString(); } List<string> names = new List<string>(); foreach (RssChannel channel in _feed.Channels) { names.Add(channel.Title); } foreach (string name in names) { if (ChannelsNames.Contains(name) == false) { base.AddChannel(name, true); } } // Retrieve web site shortcut icon. //if (_icon == null) //{ // _icon = GeneralHelper.GetWebSiteShortcutIcon(new Uri(Address)); //} } else { _feed = RssFeed.Read(_feed); } newState = OperationalStateEnum.Operational; } catch (WebException we) {// Feed not found or some other problem. SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + we.Message + "]"); newState = OperationalStateEnum.NotOperational; } catch (Exception ex) {// RssFeed class launches IOExceptions too, so get safe here. SystemMonitor.OperationWarning("Failed to initialize feed [" + Address + ", " + ex.Message + "]"); newState = OperationalStateEnum.NotOperational; } OperationalStateEnum oldState = _operationalState; _operationalState = newState; if (newState != _operationalState) { RaiseOperationalStatusChangedEvent(oldState); } UpdateItems(); RaisePersistenceDataUpdatedEvent(); }
private void RenderRss(int moduleId) { Response.ContentType = "text/xml"; Response.ContentEncoding = System.Text.Encoding.UTF8; //Cynthia.Business.RssFeed feed = new Cynthia.Business.RssFeed(moduleId); Module module = GetModule(); Hashtable moduleSettings = ModuleSettings.GetModuleSettings(moduleId); feedListCacheTimeout = WebUtils.ParseInt32FromHashtable( moduleSettings, "RSSFeedFeedListCacheTimeoutSetting", 3660); entryCacheTimeout = WebUtils.ParseInt32FromHashtable( moduleSettings, "RSSFeedEntryCacheTimeoutSetting", 3620); maxDaysOld = WebUtils.ParseInt32FromHashtable( moduleSettings, "RSSFeedMaxDayCountSetting", 90); maxEntriesPerFeed = WebUtils.ParseInt32FromHashtable( moduleSettings, "RSSFeedMaxPostsPerFeedSetting", 90); EnableSelectivePublishing = WebUtils.ParseBoolFromHashtable( moduleSettings, "EnableSelectivePublishing", EnableSelectivePublishing); DataView dv = FeedCache.GetRssFeedEntries( module.ModuleId, module.ModuleGuid, entryCacheTimeout, maxDaysOld, maxEntriesPerFeed, EnableSelectivePublishing).DefaultView; dv.Sort = "PubDate DESC"; //if (EnableSelectivePublishing) //{ // dv.RowFilter = "Confirmed = true"; //} RssChannel channel = new RssChannel(); object value = GetModule(); Module m; if (value != null) { m = (Module)value; channel.Title = m.ModuleTitle; channel.Description = m.ModuleTitle; channel.LastBuildDate = channel.Items.LatestPubDate(); channel.Link = new System.Uri(SiteUtils.GetCurrentPageUrl()); } else { // this prevents an error: Can't close RssWriter without first writing a channel. channel.Title = "Not Found"; channel.Description = "Not Found"; channel.LastBuildDate = DateTime.UtcNow; //channel.Link = new System.Uri(SiteUtils.GetCurrentPageUrl()); } foreach (DataRowView row in dv) { bool confirmed = Convert.ToBoolean(row["Confirmed"]); if (!EnableSelectivePublishing) { confirmed = true; } if (confirmed) { RssItem item = new RssItem(); item.Title = row["Title"].ToString(); item.Description = row["Description"].ToString(); item.PubDate = Convert.ToDateTime(row["PubDate"]); item.Link = new System.Uri(row["Link"].ToString()); Trace.Write(item.Link.ToString()); item.Author = row["Author"].ToString(); channel.Items.Add(item); } } Rss.RssFeed rss = new Rss.RssFeed(); rss.Encoding = System.Text.Encoding.UTF8; rss.Channels.Add(channel); rss.Write(Response.OutputStream); //Response.End(); }
/// <summary>Adds a specified feed to this collection.</summary> /// <param name="feed">The feed to add.</param> /// <returns>The zero-based index of the added feed.</returns> public int Add(RssFeed feed) { return(List.Add(feed)); }
/// <summary>Searches for the specified RssFeed and returns the zero-based index of the first occurrence within the entire RssFeedCollection.</summary> /// <param name="rssFeed">The RssFeed to locate in the RssFeedCollection.</param> /// <returns>The zero-based index of the first occurrence of RssFeed within the entire RssFeedCollection, if found; otherwise, -1.</returns> public int IndexOf(RssFeed rssFeed) { return List.IndexOf(rssFeed); }
/// <summary>Searches for the specified RssFeed and returns the zero-based index of the first occurrence within the entire RssFeedCollection.</summary> /// <param name="rssFeed">The RssFeed to locate in the RssFeedCollection.</param> /// <returns>The zero-based index of the first occurrence of RssFeed within the entire RssFeedCollection, if found; otherwise, -1.</returns> public int IndexOf(RssFeed rssFeed) { return(List.IndexOf(rssFeed)); }
private static RssFeed read(string url, HttpWebRequest request, RssFeed oldFeed) { // ***** Marked for substantial improvement RssFeed feed = new RssFeed(); RssElement element = null; Stream stream = null; Uri uri = new Uri(url); feed.url = url; switch (uri.Scheme) { case "file": feed.lastModified = File.GetLastWriteTime(url); if ((oldFeed != null) && (feed.LastModified == oldFeed.LastModified)) { oldFeed.cached = true; return oldFeed; } stream = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); break; case "https": goto case "http"; case "http": if (request == null) request = (HttpWebRequest)WebRequest.Create(uri); if (oldFeed != null) { request.IfModifiedSince = oldFeed.LastModified; request.Headers.Add("If-None-Match", oldFeed.ETag); } try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); feed.lastModified = response.LastModified; feed.etag = response.Headers["ETag"]; try { if (response.ContentEncoding != "") feed.encoding = Encoding.GetEncoding(response.ContentEncoding); } catch {} stream = response.GetResponseStream(); } catch (WebException we) { if (oldFeed != null) { oldFeed.cached = true; return oldFeed; } else throw we; // bad } break; } if (stream != null) { RssReader reader = null; try { reader = new RssReader(stream); do { element = reader.Read(); if (element is RssChannel) feed.Channels.Add((RssChannel)element); } while (element != null); feed.rssVersion = reader.Version; } finally { feed.exceptions = reader.Exceptions; reader.Close(); } } else throw new ApplicationException("Not a valid Url"); return feed; }
/// <summary>Adds a specified feed to this collection.</summary> /// <param name="feed">The feed to add.</param> /// <returns>The zero-based index of the added feed.</returns> public int Add(RssFeed feed) { return List.Add(feed); }
/// <summary>Reads the specified RSS feed</summary> /// <param name="Request">The specified way to connect to the web server</param> /// <param name="oldFeed">The cached version of the feed</param> /// <returns>The current contents of the feed</returns> /// <remarks>Will not download the feed if it has not been modified</remarks> public static RssFeed Read(HttpWebRequest Request, RssFeed oldFeed) { return read(oldFeed.url, Request, oldFeed); }
public void Setup() { SUT = RssFeed.Read(XmlResourceLoader.Load("rss.xml")); }
/// <summary>Determines whether the RssFeedCollection contains a specific element.</summary> /// <param name="rssFeed">The RssFeed to locate in the RssFeedCollection.</param> /// <returns>true if the RssFeedCollection contains the specified value; otherwise, false.</returns> public bool Contains(RssFeed rssFeed) { return(List.Contains(rssFeed)); }
/// <summary>Reads the specified RSS feed</summary> /// <param name="oldFeed">The cached version of the feed</param> /// <returns>The current contents of the feed</returns> /// <remarks>Will not download the feed if it has not been modified</remarks> public static RssFeed Read(RssFeed oldFeed) { return read(oldFeed.url, null, oldFeed); }
/// <summary>Reads the specified RSS feed</summary> /// <param name="oldFeed">The cached version of the feed</param> /// <returns>The current contents of the feed</returns> /// <remarks>Will not download the feed if it has not been modified</remarks> public static RssFeed Read(RssFeed oldFeed) { return(read(oldFeed.url, null, oldFeed, null, null)); }
private static RssFeed read(string url, HttpWebRequest request, RssFeed oldFeed) { // ***** Marked for substantial improvement RssFeed feed = new RssFeed(); Stream stream = null; Uri uri = new Uri(url); feed.url = url; switch (uri.Scheme) { case "file": feed.lastModified = File.GetLastWriteTime(url); if ((oldFeed != null) && (feed.LastModified == oldFeed.LastModified)) { oldFeed.cached = true; return oldFeed; } stream = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); break; case "https": goto case "http"; case "http": if (request == null) request = (HttpWebRequest)WebRequest.Create(uri); if (oldFeed != null) { request.IfModifiedSince = oldFeed.LastModified; request.Headers.Add("If-None-Match", oldFeed.ETag); } try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); feed.lastModified = response.LastModified; feed.etag = response.Headers["ETag"]; try { if (response.ContentEncoding != "") feed.encoding = Encoding.GetEncoding(response.ContentEncoding); } catch { } stream = response.GetResponseStream(); } catch (WebException we) { if (oldFeed != null) { oldFeed.cached = true; return oldFeed; } else throw we; // bad } break; } return read(stream); }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { //get project id if (Request.QueryString["pid"] != null) projectId = Convert.ToInt32(Request.Params["pid"]); //get feed id if (Request.QueryString["channel"] != null) channelId = Convert.ToInt32(Request.Params["channel"]); if (projectId != 0) { //Security Checks if (!User.Identity.IsAuthenticated && Project.GetProjectById(projectId).AccessType == Globals.ProjectAccessType.Private) Response.Redirect("~/Errors/AccessDenied.aspx", true); else if (User.Identity.IsAuthenticated && Project.GetProjectById(projectId).AccessType == Globals.ProjectAccessType.Private && !Project.IsUserProjectMember(User.Identity.Name, projectId)) Response.Redirect("~/Errors/AccessDenied.aspx", true); projectName = Project.GetProjectById(projectId).Name; } else { if(!User.Identity.IsAuthenticated) Response.Redirect("~/Errors/AccessDenied.aspx", true); } channel = new RssChannel(); feed = new RssFeed(); switch (channelId) { case 1: MilestoneFeed(); break; case 2: CategoryFeed(); break; case 3: StatusFeed(); break; case 4: PriorityFeed(); break; case 5: TypeFeed(); break; case 6: AssigneeFeed(); break; case 7: FilteredIssuesFeed(); break; case 8: RelevantFeed(); break; case 9: AssignedFeed(); break; case 10: OwnedFeed(); break; case 11: CreatedFeed(); break; case 12: AllFeed(); break; case 13: QueryFeed(); break; case 14: OpenIssuesFeed(); break; case 15: MonitoredIssuesFeed(); break; case 16: MyIssuesAssignedFeed(); break; case 17: MyIssuesClosedFeed(); break; case 18: MyIssuesOwnedFeed(); break; case 19: MyIssuesCreatedFeed(); break; } channel.PubDate = DateTime.Now; channel.LastBuildDate = channel.Items.LatestPubDate(); channel.Link = new System.Uri(HostSetting.GetHostSetting("DefaultUrl") + "Rss.aspx?" + Request.QueryString.ToString()); try { feed.Channels.Add(channel); //feed.Encoding = System.Text.Encoding.UTF8; Response.ContentType = "text/xml"; feed.Write(Response.OutputStream); Response.End(); } catch { //exception } }
/// <summary>Reads the specified RSS feed</summary> /// <param name="Request">The specified way to connect to the web server</param> /// <param name="oldFeed">The cached version of the feed</param> /// <param name="username">Username associated with the feed, null if none</param> /// <param name="password">Password associated with the username, null if none</param> /// <returns>The current contents of the feed</returns> /// <remarks>Will not download the feed if it has not been modified</remarks> public static RssFeed Read(HttpWebRequest Request, RssFeed oldFeed, string username, string password) { return(read(oldFeed.url, Request, oldFeed, username, password)); }
private static RssFeed read(string url, HttpWebRequest request, RssFeed oldFeed, string username, string password) { // ***** Marked for substantial improvement RssFeed feed = new RssFeed(); RssElement element = null; Stream stream = null; Uri uri = new Uri(url); feed.url = url; string ErrorMessage = null; switch (uri.Scheme) { case "file": feed.lastModified = File.GetLastWriteTime(url); if ((oldFeed != null) && (feed.LastModified == oldFeed.LastModified)) { oldFeed.cached = true; return(oldFeed); } stream = new FileStream(url, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); break; case "https": goto case "http"; case "http": if (request == null) { request = (HttpWebRequest)WebRequest.Create(uri); } if (oldFeed != null) { request.IfModifiedSince = oldFeed.LastModified; request.Headers.Add("If-None-Match", oldFeed.ETag); request.Headers.Add("Accept-Encoding", "gzip, deflate"); } try { if (username != null && password != null) { request.Credentials = new System.Net.NetworkCredential(username, password); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); feed.lastModified = response.LastModified; feed.etag = response.Headers["ETag"]; try { if (response.ContentEncoding != "") { feed.encoding = Encoding.GetEncoding(response.ContentEncoding); } } catch {} //stream = response.GetResponseStream(); stream = GetResponseStream(response); } catch (WebException we) { if (oldFeed != null) { oldFeed.cached = true; return(oldFeed); } else { ErrorMessage = we.Message; } //else throw we; // bad } break; } if (ErrorMessage == null) { if (stream != null) { RssReader reader = null; try { reader = new RssReader(stream); //do //{ element = reader.ReadXPath(); //element = reader.Read(); if (element is RssChannel) { feed.Channels.Add((RssChannel)element); } //} //while (element != null); feed.rssVersion = reader.Version; } finally { feed.exceptions = reader.Exceptions; reader.Close(); } } else if (ErrorMessage != null) { throw new ApplicationException(ErrorMessage); } else { throw new ApplicationException("Invalid Url"); } } else { throw new ApplicationException(ErrorMessage); } return(feed); }
private void BuildPost() { var data = _postRepository.GetAll(p => p.PostStatus == (int)PostStatusEnum.Publish).OrderByDescending(p => p.CreateDate).Take(50); var feed = new RssFeed(Encoding.UTF8); var channel = BuildPostRssChannel(); foreach (var item in data) { channel.Items.Add(BuildPostRssItem(item)); } feed.Channels.Add(channel); feed.Write(AppDomain.CurrentDomain.BaseDirectory + Config.Path.ARTICLES_RSS_PATH); }
public void BuildPost() { var data = Proxy.Repository<Post>() .GetAll(p => p.PostStatus == (int) PostStatusEnum.Publish) .OrderByDescending(p => p.CreateDate) .Take(10); var channel = new RssChannel { Title = string.Format("{0} - 文章", Config.Literal.SITE_NAME), Link = new Uri(Config.URL.Domain), Description = string.Format("{0} - 文章", Config.Literal.SITE_NAME), PubDate = DateTime.Now, LastBuildDate = DateTime.Now, Language = "zh-cn", Copyright = Config.Literal.COPYRIGHT }; foreach (var item in data) { channel.Items.Add(CreatePostItem(item)); } var feed = new RssFeed(Encoding.UTF8); feed.Channels.Add(channel); feed.Write(Config.Path.PHYSICAL_ROOT_PATH + Config.Path.ARTICLES_RSS_PATH); }
/// <summary>Reads the specified RSS feed</summary> /// <param name="oldFeed">The cached version of the feed</param> /// <param name="username">Username associated with the feed, null if none</param> /// <param name="password">Password associated with the username, null if none</param> /// <returns>The current contents of the feed</returns> /// <remarks>Will not download the feed if it has not been modified</remarks> public static RssFeed Read(RssFeed oldFeed, string username, string password) { return(read(oldFeed.url, null, oldFeed, username, password)); }