public async void GetPhotoInfoAsync(string photoId, string OwnerId, bool isUploadedPhoto) { if (infoQueue.Contains(photoId)) return; infoQueue.Add(photoId); string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.photos.getInfo"; 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; string paramString = GenerateParamString(paramDict); string signature = GenerateSignature("GET", AccessTokenSecret, "https://api.flickr.com/services/rest", paramString); string requestUrl = "https://api.flickr.com/services/rest?" + paramString + "&oauth_signature=" + signature; HttpWebResponse response = await DispatchRequest("GET", requestUrl, null).ConfigureAwait(false); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { if (infoQueue.Contains(photoId)) infoQueue.Remove(photoId); GetPhotoInfoExceptionEventArgs exceptionArgs = null; if (response.StatusCode != HttpStatusCode.OK) { exceptionArgs = new GetPhotoInfoExceptionEventArgs(); exceptionArgs.PhotoId = photoId; PhotoInfoException.DispatchEvent(this, exceptionArgs); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!IsResponseSuccess(jsonString)) { exceptionArgs = new GetPhotoInfoExceptionEventArgs(); exceptionArgs.PhotoId = photoId; PhotoInfoException.DispatchEvent(this, exceptionArgs); return; } GetPhotoInfoEventArgs args = new GetPhotoInfoEventArgs(); args.PhotoId = photoId; args.Response = jsonString; args.OwnerId = OwnerId; args.IsUploadedPhoto = isUploadedPhoto; PhotoInfoReturned.DispatchEvent(this, args); } }
private void OnPhotoInfoReturned(object sender, GetPhotoInfoEventArgs e) { JObject json = JObject.Parse(e.Response); Photo photo = PhotoFactory.PhotoWithPhotoInfoJObject((JObject)json["photo"]); // Should add this photo to stream? if (e.IsUploadedPhoto) { // Dispatch event UploadedPhotoInfoReturnedEventArgs evt = new UploadedPhotoInfoReturnedEventArgs(); evt.PhotoId = e.PhotoId; UploadedPhotoInfoReturned.DispatchEvent(this, evt); } var updateEvt = new PhotoInfoUpdatedEventArgs(); updateEvt.PhotoId = photo.ResourceId; PhotoInfoUpdated.DispatchEvent(this, updateEvt); }
private void OnPhotoInfoReturned(object sender, GetPhotoInfoEventArgs e) { Dispatcher.BeginInvoke(() => { if (e.PhotoId != photoId) return; if (statusView == null) return; // Do we need to upload to a photo collection? if (UploadToPhotoSetId != null) { statusView.ProgressView.IsIndeterminate = true; statusView.StatusLabel.Text = "Adding to photo set..."; Anaconda.AnacondaCore.AddPhotoToSetAsync(e.PhotoId, UploadToPhotoSetId); } else { ShowCompleteStatus("Upload is complete"); } }); }