private void OnUploadComplete(object sender, UploadPhotoEventArgs e) { Dispatcher.BeginInvoke(() => { if (e.SessionId != sessionId) return; if (statusView == null) return; // Get full photo info so that we can insert the photo to cache statusView.ProgressView.IsIndeterminate = true; statusView.StatusLabel.Text = "Retrieving photo info"; photoId = e.PhotoId; string currentUserId = Cinderella.CinderellaCore.CurrentUser.ResourceId; Anaconda.AnacondaCore.GetPhotoInfoAsync(e.PhotoId, currentUserId, true); }); }
private void OnPhotoUploaded(object sender, UploadPhotoEventArgs e) { /* Photo newPhoto = new Photo(); newPhoto.ResourceId = e.PhotoId; PhotoCache[e.PhotoId] = newPhoto; CurrentUser.Photos.Add(newPhoto); CurrentUser.PhotoCount++; // Dispatch event PhotoUploadCompleteEventArgs evt = new PhotoUploadCompleteEventArgs(); evt.PhotoId = e.PhotoId; PhotoUploadCompleted.DispatchEvent(this, evt); * */ }
public async void UploadPhoto(string sessionId, string fileName, Stream stream, Dictionary<string, string> parameters = null) { string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); 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"; if (parameters != null) { foreach (var entry in parameters) { paramDict[entry.Key] = entry.Value; } } string signature = OAuthCalculateSignature("POST", "https://api.flickr.com/services/upload/", paramDict, AccessTokenSecret); paramDict["oauth_signature"] = signature; HttpWebResponse response = await UploadDataAsync(sessionId, fileName, stream, paramDict).ConfigureAwait(false); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { if (response.StatusCode != HttpStatusCode.OK) { HandleHTTPException(response); return; } string xmlString = await reader.ReadToEndAsync().ConfigureAwait(false); XDocument xmlDoc = XDocument.Parse(xmlString); if (xmlDoc.Element("rsp").Attribute("stat").Value == "fail") { if (PhotoUploadError != null) { var errorEvt = new UploadPhotoErrorEventArgs(); errorEvt.SessionId = sessionId; PhotoUploadError(this, errorEvt); } return; } else { string photoId = (from x in XDocument.Parse(xmlString).Element("rsp").Descendants().ToList() select x).First().Value; if (PhotoUploaded != null) { var evt = new UploadPhotoEventArgs(); evt.SessionId = sessionId; evt.PhotoId = photoId; PhotoUploaded(this, evt); } } } }