/// <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>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>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); }
/// <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>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>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); }
private static RssFeed read(string url, HttpWebRequest request, RssFeed oldFeed) { // ***** Marked for substantial improvement var feed = new RssFeed(); RssElement element; Stream stream = null; var 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": 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 { var response = (HttpWebResponse) request.GetResponse(); feed.lastModified = response.LastModified; feed.etag = response.Headers["ETag"]; try { if (response.ContentEncoding != "") feed.encoding = Encoding.GetEncoding(response.ContentEncoding); } catch { feed.Encoding = Encoding.UTF8; } stream = response.GetResponseStream(); } catch (WebException) { if (oldFeed != null) { oldFeed.cached = true; return oldFeed; } throw; // 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>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); }
/// <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); }