private void OnGetCommentsException(object sender, GetPhotoCommentsExceptionEventArgs e) { Dispatcher.BeginInvoke(() => { if (e.PhotoId != PhotoSource.ResourceId) return; LoadingView.Text = AppResources.DetailPageLoadCommentsErrorText; }); }
public async void GetPhotoCommentsAsync(string photoId, Dictionary<string, string> parameters = null) { if (commentQueue.Contains(photoId)) return; commentQueue.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.comments.getList"; 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(commentQueue.Contains(photoId)) commentQueue.Remove(photoId); GetPhotoCommentsExceptionEventArgs exceptionArgs = null; if (response.StatusCode != HttpStatusCode.OK) { exceptionArgs = new GetPhotoCommentsExceptionEventArgs(); exceptionArgs.PhotoId = photoId; GetPhotoCommentsException.DispatchEvent(this, exceptionArgs); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!IsResponseSuccess(jsonString)) { exceptionArgs = new GetPhotoCommentsExceptionEventArgs(); exceptionArgs.PhotoId = photoId; GetPhotoCommentsException.DispatchEvent(this, exceptionArgs); return; } GetPhotoCommentsEventArgs args = new GetPhotoCommentsEventArgs(); args.PhotoId = photoId; args.Response = jsonString; PhotoCommentsReturned.DispatchEvent(this, args); } }