// Favourite stream returned private void OnFavouriteStreamReturned(object sender, GetFavouriteStreamEventArgs e) { JObject rawJson = JObject.Parse(e.Response); JObject rootJson = (JObject)rawJson["photos"]; TotalFavouritePhotosCount = int.Parse(rootJson["total"].ToString()); int page = int.Parse(rootJson["page"].ToString()); int numPages = int.Parse(rootJson["pages"].ToString()); int perPage = int.Parse(rootJson["perpage"].ToString()); List<Photo> newPhotos = new List<Photo>(); foreach (var entry in rootJson["photo"]) { JObject json = (JObject)entry; Photo photo = PhotoFactory.PhotoWithJObject(json); if (!FavouriteList.Contains(photo)) { FavouriteList.Add(photo); newPhotos.Add(photo); } } // Dispatch event FavouriteStreamUpdatedEventArgs args = new FavouriteStreamUpdatedEventArgs(); args.Page = page; args.PageCount = numPages; args.PerPage = perPage; args.NewPhotos = newPhotos; FavouriteStreamUpdated.DispatchEvent(this, args); }
public async void GetFavouritePhotoStreamAsync(string userId, Dictionary<string, string> parameters = null) { isLoadingFavStream = true; string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.favorites.getList"; paramDict["format"] = "json"; paramDict["nojsoncallback"] = "1"; paramDict["oauth_consumer_key"] = consumerKey; paramDict["oauth_nonce"] = nonce; paramDict["oauth_signature_method"] = "HMAC-SHA1"; paramDict["oauth_timestamp"] = timestamp; paramDict["oauth_token"] = AccessToken; paramDict["oauth_version"] = "1.0"; if (parameters != null) { foreach (var entry in parameters) { paramDict[entry.Key] = entry.Value; } } paramDict["user_id"] = UrlHelper.Encode(Cinderella.Cinderella.CinderellaCore.CurrentUser.ResourceId); paramDict["extras"] = UrlHelper.Encode(commonExtraParameters); string paramString = GenerateParamString(paramDict); string signature = GenerateSignature("GET", AccessTokenSecret, "https://api.flickr.com/services/rest", paramString); string requestUrl = "https://api.flickr.com/services/rest?" + paramString + "&oauth_signature=" + signature; HttpWebResponse response = await DispatchRequest("GET", requestUrl, null).ConfigureAwait(false); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { isLoadingFavStream = false; if (response.StatusCode != HttpStatusCode.OK) { HandleHTTPException(response); FavouriteStreamException(this, null); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!TryHandleResponseException(jsonString, () => { GetFavouritePhotoStreamAsync(userId, parameters); })) { FavouriteStreamException(this, null); return; } GetFavouriteStreamEventArgs args = new GetFavouriteStreamEventArgs(); args.UserId = userId; args.Response = jsonString; FavouriteStreamReturned.DispatchEvent(this, args); } }