private void OnPhotoAddedToSet(object sender, AddPhotoToSetEventArgs e)
        {
            PhotoSet photoSet = PhotoSetCache[e.SetId];
            Photo photo = PhotoCache[e.PhotoId];

            if (!photoSet.Photos.Contains(photo))
            {
                photoSet.Photos.Insert(0, photo);
                photoSet.PhotoCount++;

                // Dispatch event
                AddPhotoToSetCompleteEventArgs ae = new AddPhotoToSetCompleteEventArgs();
                ae.PhotoId = photo.ResourceId;
                ae.SetId = photoSet.ResourceId;
                AddPhotoToSetCompleted.DispatchEvent(this, ae);
            }
        }
        public void AddPhotoToSetAsync(string photoId, string setId)
        {
            string timestamp = DateTimeUtils.GetTimestamp();
            string nonce = Guid.NewGuid().ToString().Replace("-", null);

            Dictionary<string, string> paramDict = new Dictionary<string, string>();
            paramDict["method"] = "flickr.photosets.addPhoto";
            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["photoset_id"] = setId;
            paramDict["photo_id"] = photoId;

            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)
                    {
                        AddPhotoToSetExceptionEventArgs exceptionArgs = new AddPhotoToSetExceptionEventArgs();
                        exceptionArgs.PhotoId = photoId;
                        exceptionArgs.SetId = setId;
                        exceptionArgs.ErrorMessage = errorMessage;
                        AddPhotoToSetException.DispatchEvent(this, exceptionArgs);
                    }
                    else
                    {
                        AddPhotoToSetEventArgs args = new AddPhotoToSetEventArgs();
                        args.PhotoId = photoId;
                        args.SetId = setId;
                        PhotoAddedToSet.DispatchEvent(this, args);
                    }


                }, (ex) =>
                {
                    AddPhotoToSetExceptionEventArgs exceptionArgs = new AddPhotoToSetExceptionEventArgs();
                    exceptionArgs.PhotoId = photoId;
                    exceptionArgs.SetId = setId;
                    exceptionArgs.ErrorMessage = "Unknown network error";
                    AddPhotoToSetException.DispatchEvent(this, exceptionArgs);
                });
        }
        private void OnPhotoAddedToSet(object sender, AddPhotoToSetEventArgs e)
        {
            if (e.PhotoId != photoId)
            {
                return;
            }

            ShowCompleteStatus("Photo has been added to set");
        }