private void OnPhotoCommentAdded(object sender, AddCommentEventArgs e) { Photo photo = Cinderella.CinderellaCore.PhotoCache[e.PhotoId]; JObject rawJson = JObject.Parse(e.Response); string newCommentId = rawJson["comment"]["id"].ToString(); PhotoComment newComment = new PhotoComment(); newComment.ResourceId = newCommentId; newComment.Message = e.Message; newComment.Author = CurrentUser; newComment.CreationDate = DateTime.Now; photo.CommentCache[newCommentId] = newComment; photo.Comments.Insert(0, newComment); photo.CommentCount++; AddPhotoCommentCompleteEventArgs evt = new AddPhotoCommentCompleteEventArgs(); evt.SessionId = e.SessionId; evt.PhotoId = photo.ResourceId; evt.NewComment = newComment; AddPhotoCommentCompleted.DispatchEvent(this, evt); }
public void AddCommentAsync(string sessionId, string photoId, string message) { string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.photos.comments.addComment"; 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; paramDict["comment_text"] = message; string signature = OAuthCalculateSignature("POST", "https://api.flickr.com/services/rest/", paramDict, AccessTokenSecret); paramDict["oauth_signature"] = signature; DispatchPostRequest("POST", "https://api.flickr.com/services/rest/", paramDict, (response) => { bool success = true; string errorMessage = ""; try { JObject json = JObject.Parse(response); string status = json["stat"].ToString(); if (status != "ok") { success = false; errorMessage = json["message"].ToString(); } } catch (Exception e) { Debug.WriteLine(e.Message); success = false; } if (!success) { AddCommentExceptionEventArgs exceptionArgs = new AddCommentExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddPhotoCommentException.DispatchEvent(this, exceptionArgs); } else { AddCommentEventArgs args = new AddCommentEventArgs(); args.SessionId = sessionId; args.PhotoId = photoId; args.Response = response; args.Message = message; PhotoCommentAdded.DispatchEvent(this, args); } }, (ex) => { AddCommentExceptionEventArgs exceptionArgs = new AddCommentExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddPhotoCommentException.DispatchEvent(this, exceptionArgs); }); }