public void AddTopicReplyAsync(string sessionId, string topicId, string groupId, string message) { string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.groups.discuss.replies.add"; 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["topic_id"] = topicId; paramDict["message"] = 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) { AddTopicReplyExceptionEventArgs exceptionArgs = new AddTopicReplyExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddTopicReplyException.DispatchEvent(this, exceptionArgs); } else { AddTopicReplyEventArgs args = new AddTopicReplyEventArgs(); args.SessionId = sessionId; args.GroupId = groupId; args.TopicId = topicId; args.Response = response; args.Message = message; TopicReplyAdded.DispatchEvent(this, args); } }, (ex) => { AddTopicReplyExceptionEventArgs exceptionArgs = new AddTopicReplyExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddTopicReplyException.DispatchEvent(this, exceptionArgs); }); }
private void OnTopicReplyAdded(object sender, AddTopicReplyEventArgs e) { FlickrGroup group = Cinderella.CinderellaCore.GroupCache[e.GroupId]; Topic topic = group.TopicCache[e.TopicId]; JObject rawJson = JObject.Parse(e.Response); string newReplyId = rawJson["reply"]["id"].ToString(); TopicReply newReply = new TopicReply(); newReply.ResourceId = newReplyId; newReply.Message = e.Message; newReply.Author = CurrentUser; newReply.CreationDate = DateTime.Now; topic.ReplyCache[newReplyId] = newReply; topic.Replies.Insert(0, newReply); topic.ReplyCount++; AddTopicReplyCompleteEventArgs evt = new AddTopicReplyCompleteEventArgs(); evt.SessionId = e.SessionId; evt.GroupId = group.ResourceId; evt.TopicId = topic.ResourceId; evt.newReply = newReply; AddTopicReplyCompleted.DispatchEvent(this, evt); }