public async void GetEXIFAsync(string photoId) { if (IsGettingEXIFInfo(photoId)) return; exifQueue.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.getExif"; 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; paramDict["extras"] = UrlHelper.Encode(commonExtraParameters); 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(exifQueue.Contains(photoId)) exifQueue.Remove(photoId); GetEXIFExceptionEventArgs exceptionArgs = null; if (response.StatusCode != HttpStatusCode.OK) { exceptionArgs = new GetEXIFExceptionEventArgs(); exceptionArgs.PhotoId = photoId; EXIFException.DispatchEvent(this, exceptionArgs); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!IsResponseSuccess(jsonString)) { exceptionArgs = new GetEXIFExceptionEventArgs(); exceptionArgs.PhotoId = photoId; EXIFException.DispatchEvent(this, exceptionArgs); return; } GetEXIFEventArgs args = new GetEXIFEventArgs(); args.PhotoId = photoId; args.Response = jsonString; EXIFReturned.DispatchEvent(this, args); } }
private void OnEXIFReturned(object sender, GetEXIFEventArgs e) { if (!PhotoCache.ContainsKey(e.PhotoId)) return; Photo photo = PhotoCache[e.PhotoId]; JObject json = JObject.Parse(e.Response); photo.EXIF = PhotoEXIFFactory.EXIFWithJObject((JObject)json["photo"]); EXIFUpdatedEventArgs evt = new EXIFUpdatedEventArgs(); evt.PhotoId = photo.ResourceId; EXIFUpdated.DispatchEvent(this, evt); }