public static void GetFlickrImageSizes(ImageFeedItem imageFeedItem, string flickrApiKey, GetFlickrImageSizesCallback callback) { if (imageFeedItem == null || (imageFeedItem.Sizes != null && imageFeedItem.Sizes.Count > 0) || imageFeedItem.SourceType != SourceType.Flickr) { callback(imageFeedItem); } string query = string.Format(CultureInfo.InvariantCulture, "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key={0}&photo_id={1}", flickrApiKey, imageFeedItem.ServiceId); AsyncWebRequest request = new AsyncWebRequest(); request.Request(new Uri(query)); request.Result += (sender, e) => { if (e.Status != HttpStatusCode.OK) { callback(imageFeedItem); } try { XDocument doc = XDocument.Parse(e.Response); imageFeedItem.Sizes = new Dictionary <Size, Uri>(); foreach (XElement size in doc.Descendants("size")) { imageFeedItem.Sizes[new Size(int.Parse(size.Attribute("width").Value, CultureInfo.InvariantCulture), int.Parse(size.Attribute("height").Value, CultureInfo.InvariantCulture))] = new Uri(size.Attribute("source").Value); } callback(imageFeedItem); } catch { callback(imageFeedItem); } }; }
public static void GetFlickrImageSizes(ImageFeedItem imageFeedItem, string flickrApiKey, GetFlickrImageSizesCallback callback) { if (imageFeedItem == null || (imageFeedItem.Sizes != null && imageFeedItem.Sizes.Count > 0) || imageFeedItem.SourceType != SourceType.Flickr) { callback(imageFeedItem); } string query = string.Format(CultureInfo.InvariantCulture, "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key={0}&photo_id={1}", flickrApiKey, imageFeedItem.ServiceId); AsyncWebRequest request = new AsyncWebRequest(); request.Request(new Uri(query)); request.Result += (sender, e) => { if (e.Status != HttpStatusCode.OK) { callback(imageFeedItem); } try { XDocument doc = XDocument.Parse(e.Response); imageFeedItem.Sizes = new Dictionary<Size, Uri>(); foreach (XElement size in doc.Descendants("size")) { imageFeedItem.Sizes[new Size(int.Parse(size.Attribute("width").Value, CultureInfo.InvariantCulture), int.Parse(size.Attribute("height").Value, CultureInfo.InvariantCulture))] = new Uri(size.Attribute("source").Value); } callback(imageFeedItem); } catch { callback(imageFeedItem); } }; }
/// <summary> /// Processes the response from the feed service. /// </summary> /// <param name="response">response from the feed service.</param> internal override void ProcessResponse(object responseObject) { string response = responseObject.ToString(); if (response.Contains("<rsp stat=\"fail\">")) { #if DEBUG throw new InvalidOperationException(response); #else return; #endif } XDocument document = XDocument.Parse(response); foreach (XElement node in document.Element("rsp").Element("photos").Elements("photo")) { _flickrUserNameCache[node.Attribute("owner").Value] = node.Attribute("ownername").Value; _minUploadDate = Math.Max(_minUploadDate, long.Parse(node.Attribute("dateupload").Value, CultureInfo.InvariantCulture)); ImageFeedItem feedItem = new ImageFeedItem { // Build the page URI with the user photo url, since that's what a user would put in the ban list. Uri = new Uri(string.Format( CultureInfo.InvariantCulture, SourceUriFormatString, string.IsNullOrEmpty(node.Attribute("pathalias").Value) ? node.Attribute("owner").Value : node.Attribute("pathalias").Value, node.Attribute("id").Value)), Date = FlickrSearchFeed.ConvertFromUnixTimestamp(int.Parse(node.Attribute("dateupload").Value, CultureInfo.InvariantCulture)), Author = HttpUtility.HtmlDecode(_flickrUserNameCache[node.Attribute("owner").Value]), AvatarUri = new Uri(string.Format( CultureInfo.InstalledUICulture, AvatarUriFormatString, node.Attribute("iconfarm").Value, node.Attribute("iconserver").Value, node.Attribute("owner").Value)), SourceType = SourceType.Flickr, Title = HttpUtility.HtmlDecode(node.Attribute("title").Value), Caption = HttpUtility.HtmlDecode(StripHtml(node.Element("description") != null ? node.Element("description").Value : string.Empty)), ThumbnailUri = new Uri(string.Format( CultureInfo.InvariantCulture, ThumbnailUriFormatString, node.Attribute("farm").Value, node.Attribute("server").Value, node.Attribute("id").Value, node.Attribute("secret").Value)), ServiceId = node.Attribute("id").Value }; if (feedItem.Date < MinDate) { continue; } RaiseGotNewFeedItem(feedItem); } }
/// <summary> /// Processes the response to convert owner's posts into feed items. /// </summary> /// <param name="response">response from the feed service.</param> internal void ProcessResponseWithOwner(dynamic response) { #region Process Owner's Image Items if (response.data[_ownerPhotoDataIndex]["fql_result_set"].Count > 0) // ownerphotodata { foreach (dynamic photo in response.data[_ownerPhotoDataIndex]["fql_result_set"]) // ownerphotodata { foreach (dynamic author in response.data[_ownerPhotoAuthorDataIndex]["fql_result_set"]) // ownerphotoauthordata { DateTime created = ConvertFromUnixTimestamp(double.Parse(photo["created"].ToString())); if (created < MinDate) { continue; } // add a feed if matching author is found for the post if (photo.owner == author.page_id) { ImageFeedItem feedItem = new ImageFeedItem { Author = (string)author["name"], AvatarUri = new Uri((string)author["pic_small"]), Date = created, ServiceId = (string)photo["pid"], Uri = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["link"])), SourceType = SourceType.Facebook, Caption = (string)photo["caption"], ThumbnailUri = new Uri(string.Format(CultureInfo.InvariantCulture, (string)photo["src_big"])), }; RaiseGotNewFeedItem(feedItem); } break; } } } #endregion #region Process Owner's Status Items if (response.data[_ownerStatusStreamIndex]["fql_result_set"].Count > 0) { foreach (dynamic post in response.data[_ownerStatusStreamIndex]["fql_result_set"]) // ownerstatusstream { foreach (dynamic author in response.data[_ownerStatusAuthorDataIndex]["fql_result_set"]) // ownerstatusauthordata { if (post.actor_id == author.page_id) { // create status feed item if matching author data is found for this post DateTime created = ConvertFromUnixTimestamp(double.Parse(post["created_time"].ToString())); if (created < MinDate) { continue; } StatusFeedItem feedItem = new StatusFeedItem { Author = (string)author["name"], AvatarUri = new Uri((string)author["pic_small"]), Date = created, ServiceId = (string)post["post_id"], Uri = new Uri(string.Format(CultureInfo.InvariantCulture, (string)post["permalink"])), Status = (string)post["message"], SourceType = SourceType.Facebook, }; RaiseGotNewFeedItem(feedItem); break; } } } } #endregion }