コード例 #1
0
        private void OnPhotoSetPrimaryUpdated(object sender, ChangePhotoSetPrimaryEventArgs e)
        {
            PhotoSet photoSet = PhotoSetCache[e.SetId];
            photoSet.Primary = e.PhotoId;
            photoSet.PrimaryPhoto = PhotoCache[photoSet.Primary];

            PhotoSetPrimaryUpdatedEventArgs evt = new PhotoSetPrimaryUpdatedEventArgs();
            evt.PhotoSetId = e.SetId;
            PhotoSetPrimaryChanged.DispatchEvent(this, evt);
        }
コード例 #2
0
        public void ChangePhotoSetPrimaryPhotoAsync(string setId, string photoId)
        {
            string timestamp = DateTimeUtils.GetTimestamp();
            string nonce = Guid.NewGuid().ToString().Replace("-", null);

            Dictionary<string, string> paramDict = new Dictionary<string, string>();
            paramDict["method"] = "flickr.photosets.setPrimaryPhoto";
            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)
                    {
                        ChangePhotoSetPrimaryExceptionEventArgs exceptionArgs = new ChangePhotoSetPrimaryExceptionEventArgs();
                        exceptionArgs.PhotoId = photoId;
                        exceptionArgs.SetId = setId;
                        exceptionArgs.ErrorMessage = errorMessage;
                        PhotoSetChangePrimaryException.DispatchEvent(this, exceptionArgs);
                    }
                    else
                    {
                        ChangePhotoSetPrimaryEventArgs args = new ChangePhotoSetPrimaryEventArgs();
                        args.PhotoId = photoId;
                        args.SetId = setId;
                        PhotoSetChangedPrimary.DispatchEvent(this, args);
                    }


                }, (ex) =>
                {
                    ChangePhotoSetPrimaryExceptionEventArgs exceptionArgs = new ChangePhotoSetPrimaryExceptionEventArgs();
                    exceptionArgs.PhotoId = photoId;
                    exceptionArgs.SetId = setId;
                    exceptionArgs.ErrorMessage = "Unknown network error";
                    PhotoSetChangePrimaryException.DispatchEvent(this, exceptionArgs);
                });
        }