public void AddTopicAsync(string sessionId, string groupId, string subject, 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.topics.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["group_id"] = groupId; paramDict["subject"] = subject; 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) { AddTopicExceptionEventArgs exceptionArgs = new AddTopicExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddTopicException.DispatchEvent(this, exceptionArgs); } else { AddTopicEventArgs args = new AddTopicEventArgs(); args.SessionId = sessionId; args.GroupId = groupId; args.Response = response; args.Subject = subject; args.Message = message; TopicAdded.DispatchEvent(this, args); } }, (ex) => { AddTopicExceptionEventArgs exceptionArgs = new AddTopicExceptionEventArgs(); exceptionArgs.SessionId = sessionId; AddTopicException.DispatchEvent(this, exceptionArgs); }); }
private void OnTopicAdded(object sender, AddTopicEventArgs e) { FlickrGroup group = Cinderella.CinderellaCore.GroupCache[e.GroupId]; JObject rawJson = JObject.Parse(e.Response); string newTopicId = rawJson["topic"]["id"].ToString(); Topic newTopic = new Topic(); newTopic.ResourceId = newTopicId; newTopic.Subject = e.Subject; newTopic.Message = e.Message; newTopic.Author = CurrentUser; newTopic.CreationDate = DateTime.Now; group.TopicCache[newTopicId] = newTopic; group.Topics.Insert(0, newTopic); group.TopicCount++; AddTopicCompleteEventArgs evt = new AddTopicCompleteEventArgs(); evt.SessionId = e.SessionId; evt.GroupId = group.ResourceId; evt.newTopic = newTopic; AddTopicCompleted.DispatchEvent(this, evt); }