private void OnPhotoCommentsReturned(object sender, GetPhotoCommentsEventArgs e) { if (!PhotoCache.ContainsKey(e.PhotoId)) return; Photo photo = PhotoCache[e.PhotoId]; // Hack prevent evulation func timeout if (e.Response.Contains("_content")) { JObject rawJson = JObject.Parse(e.Response); JObject rootJson = (JObject)rawJson["comments"]; photo.Comments.Clear(); foreach (var entry in rootJson["comment"]) { JObject commentJObject = (JObject)entry; PhotoComment comment = PhotoCommentFactory.PhotoCommentWithJObject(commentJObject, photo); photo.Comments.Add(comment); } } PhotoCommentsUpdatedEventArgs evt = new PhotoCommentsUpdatedEventArgs(); evt.PhotoId = photo.ResourceId; PhotoCommentsUpdated.DispatchEvent(this, evt); }
public async void GetPhotoCommentsAsync(string photoId, Dictionary<string, string> parameters = null) { if (commentQueue.Contains(photoId)) return; commentQueue.Add(photoId); string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.photos.comments.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"; paramDict["photo_id"] = photoId; 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())) { if(commentQueue.Contains(photoId)) commentQueue.Remove(photoId); GetPhotoCommentsExceptionEventArgs exceptionArgs = null; if (response.StatusCode != HttpStatusCode.OK) { exceptionArgs = new GetPhotoCommentsExceptionEventArgs(); exceptionArgs.PhotoId = photoId; GetPhotoCommentsException.DispatchEvent(this, exceptionArgs); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!IsResponseSuccess(jsonString)) { exceptionArgs = new GetPhotoCommentsExceptionEventArgs(); exceptionArgs.PhotoId = photoId; GetPhotoCommentsException.DispatchEvent(this, exceptionArgs); return; } GetPhotoCommentsEventArgs args = new GetPhotoCommentsEventArgs(); args.PhotoId = photoId; args.Response = jsonString; PhotoCommentsReturned.DispatchEvent(this, args); } }