/// <summary> /// Creates the news feed entry that represents a user's Facebook news feed. /// </summary> /// <returns>The NewsFeed object that represents the Facebook news feed.</returns> private static NewsFeed CreateDefaultFacebookNewsFeed() { NewsFeed f = new NewsFeed(); f.link = FacebookApiUrl; f.title = ComponentsText.FacebookNewsFeedTitle; f.refreshrateSpecified = true; f.refreshrate = 1000 * 60 * 5; //refresh every five minutes f.stylesheet = ComponentsText.FacebookStyleSheet; f.markitemsreadonexit = f.markitemsreadonexitSpecified = true; return(f); }
/// <summary> /// Tests to see if two NewsFeed objects represent the same feed. /// </summary> /// <returns></returns> public override bool Equals(Object obj) { if (ReferenceEquals(this, obj)) { return(true); } NewsFeed feed = obj as NewsFeed; if (feed == null) { return(false); } if (link.Equals(feed.link)) { return(true); } return(false); }
/// <summary> /// Loads the feedlist from the FeedLocation. ///</summary> public override void LoadFeedlist() { feeds myFeeds = null; if (File.Exists(this.location.Location)) { //load Bandit subscriptions.xml document into memory XmlReader reader = XmlReader.Create(this.location.Location); XmlSerializer serializer = XmlHelper.SerializerCache.GetSerializer(typeof(feeds)); myFeeds = (feeds)serializer.Deserialize(reader); reader.Close(); } else { myFeeds = new feeds(); NewsFeed f = CreateDefaultFacebookNewsFeed(); myFeeds.feed.Add(f); } //load news feed from Facebook using settings from subscriptions.xml this.BootstrapAndLoadFeedlist(myFeeds); }
/// <summary> /// Retrieves the RSS feed for a particular subscription then converts /// the blog posts or articles to an arraylist of items. The http requests are async calls. /// </summary> /// <param name="feedUrl">The URL of the feed to download</param> /// <param name="forceDownload">Flag indicates whether cached feed items /// can be returned or whether the application must fetch resources from /// the web</param> /// <param name="manual">Flag indicates whether the call was initiated by user (true), or /// by automatic refresh timer (false)</param> /// <exception cref="ApplicationException">If the RSS feed is not version 0.91, 1.0 or 2.0</exception> /// <exception cref="XmlException">If an error occured parsing the RSS feed</exception> /// <exception cref="ArgumentNullException">If feedUrl is a null reference</exception> /// <exception cref="UriFormatException">If an error occurs while attempting to format the URL as an Uri</exception> /// <returns>true, if the request really was queued up</returns> /// <remarks>Result arraylist is returned by OnUpdatedFeed event within UpdatedFeedEventArgs</remarks> // [MethodImpl(MethodImplOptions.Synchronized)] public override bool AsyncGetItemsForFeed(string feedUrl, bool forceDownload, bool manual) { if (feedUrl == null || feedUrl.Trim().Length == 0) { throw new ArgumentNullException("feedUrl"); } string etag = null; bool requestQueued = false; int priority = 10; if (forceDownload) { priority += 100; } if (manual) { priority += 1000; } Uri feedUri = new Uri(feedUrl); NewsFeed theFeed = null; //see if we've retrieved the news feed before if (feedsTable.ContainsKey(feedUri.CanonicalizedUri())) { theFeed = feedsTable[feedUri.CanonicalizedUri()] as NewsFeed; } if (theFeed == null) //feed list is corrupted { return(false); } // raise event only if we "really" go over the wire for an update: RaiseOnUpdateFeedStarted(feedUri, forceDownload, priority); //DateTime lastRetrieved = DateTime.MinValue; DateTime lastModified = DateTime.MinValue; if (itemsTable.ContainsKey(feedUrl)) { etag = theFeed.etag; lastModified = (theFeed.lastretrievedSpecified ? theFeed.lastretrieved : theFeed.lastmodified); } Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("viewer_id", this.facebookUserId); parameters.Add("session_key", this.sessionKey); parameters.Add("method", "stream.get"); /* FQL * string query = String.Format("?query=select post_id, source_id, created_time, actor_id, target_id, app_id, message, attachment, comments, likes, permalink, attribution, type from stream where filter_key in (select filter_key FROM stream_filter where uid = {0} and type = 'newsfeed') and created_time >= {1} order by created_time desc limit 50", facebookUserId, updatedTime); * parameters = "&v=1.0&method=fql.query&format=JSON&call_id={0}&session_key={1}&api_key={2}&sig={3}"; */ string reqUrl = feedUrl + "?" + CreateHTTPParameterList(parameters, false /* useJson */); Uri reqUri = new Uri(reqUrl); try { try { if ((!forceDownload) || Offline) { GetCachedItemsForFeed(feedUri.CanonicalizedUri()); //load feed into itemsTable RaiseOnUpdatedFeed(feedUri, null, RequestResult.NotModified, priority, false); return(false); } } catch (XmlException xe) { //cache file is corrupt Trace("Unexpected error retrieving cached feed '{0}': {1}", feedUrl, xe.ToDescriptiveString()); } ICredentials c = null; RequestParameter reqParam = RequestParameter.Create(reqUri, this.UserAgent, this.Proxy, c, lastModified, etag); reqParam = RequestParameter.Create(false, reqParam); AsyncWebRequest.QueueRequest(reqParam, OnRequestStart, OnRequestComplete, OnRequestException, priority); requestQueued = true; } catch (Exception e) { Trace("Unexpected error on QueueRequest(), processing feed '{0}': {1}", feedUrl, e.ToDescriptiveString()); RaiseOnUpdateFeedException(feedUrl, e, priority); } return(requestQueued); }