internal void UploadEnded(object sender, UploaderEndedEventArgs e) { if (this.InvokeRequired) { Trace.WriteLine("Self invoking...", string.Format("PeekPreview.UploadEnded [{0}]", System.Threading.Thread.CurrentThread.Name)); this.BeginInvoke(new MethodInvoker(() => UploadEnded(sender, e))); return; } if (e.Screenshot != this.CurrentScreenshot) return; UploadAnimationIndex = -1; pnUpload.BackgroundImage = pnUpload.isMouseOver() ? Resources.cloud_upload_link_white_32x32 : Resources.cloud_upload_link_black_32x32; ResetFadeCloseCountdown(); }
private void Uploader_UploadEnded(object sender, UploaderEndedEventArgs e) { if (e.IsSuccess) { LatestScreenshot.Remote.ImageLink = e.ImageLinkUrl; LatestScreenshot.Remote.DeleteLink = e.DeleteLinkUrl; GroomUploadMenuItemStyles(); //todo: Action Item Clipboard.SetText(LatestScreenshot.Remote.ImageLink); } else { MessageBox.Show(this, string.Format("An error occurred while uploading this screenshot:\n{0}", e.exception), "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UploadAnimationIndex = -1; pnUpload.BackgroundImage = pnUpload.isMouseOver() ? Resources.cloud_upload_link_white_32x32 : Resources.cloud_upload_link_black_32x32; ResetFadeCloseCountdown(); UploadComplete(sender, new EventArgs()); }
public Task <UploaderEndedEventArgs> Upload(ExtendedScreenshot screenshot) { Trace.WriteLine("Starting upload process...", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var t = new TaskCompletionSource <UploaderEndedEventArgs>(); try { using (var wc = new WebClient()) { wc.UploadProgressChanged += (s, e) => { this.UploadProgress(this, new UploaderProgressEventArgs(screenshot, (e.BytesSent * 100) / e.TotalBytesToSend)); }; wc.UploadValuesCompleted += (s, e) => { Trace.WriteLine("Upload complete.", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); XmlDocument ResponseDoc = new XmlDocument(); ResponseDoc.Load(new MemoryStream(e.Result)); ResponseDoc.Save(Configuration.LocalPath + @"\response.txt"); XmlNodeList ImageLink = ResponseDoc.SelectNodes(this.ImageLinkXPath); screenshot.Remote.ImageLink = ImageLink.Count > 0 ? ImageLink[0].InnerText : null; XmlNodeList DeleteLink = ResponseDoc.SelectNodes(this.DeleteLinkXPath); screenshot.Remote.DeleteLink = DeleteLink.Count > 0 ? DeleteLink[0].InnerText : null; var result = new UploaderEndedEventArgs(screenshot); this.UploadEnded(this, result); t.SetResult(result); }; Trace.WriteLine("Starting stream conversion... ", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var ImageData = string.Empty; using (var ms = screenshot.EditedScreenshotPNGImageStream()) ImageData = Convert.ToBase64String(ms.ToArray()); var CurrentUploadValues = new NameValueCollection(); foreach (var k in this.UploadValues.AllKeys.ToList()) { CurrentUploadValues.Add(k, this.UploadValues[k].Replace("%i", ImageData)); } Trace.WriteLine("Stream conversion complete.", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); Trace.WriteLine("Starting upload...", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); wc.UploadValuesAsync(new Uri(this.EndpointUrl), CurrentUploadValues); this.UploadStarted(this, new UploaderProgressEventArgs(screenshot, 0)); } } catch (Exception ex) { Trace.WriteLine(string.Format("Exception occurred during upload: {0}", ex.GetBaseException()), string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var result = new UploaderEndedEventArgs(ex.GetBaseException()); this.UploadEnded(this, result); t.SetResult(result); } return(t.Task); }
protected void OnUploadEnded(UploaderEndedEventArgs e) { _context.Post(o => UploadEnded(this, e), null); }
public Task<UploaderEndedEventArgs> Upload(ExtendedScreenshot screenshot) { Trace.WriteLine("Starting upload process...", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var t = new TaskCompletionSource<UploaderEndedEventArgs>(); try { using (var wc = new WebClient()) { wc.UploadProgressChanged += (s, e) => { this.UploadProgress(this, new UploaderProgressEventArgs(screenshot, (e.BytesSent * 100) / e.TotalBytesToSend)); }; wc.UploadValuesCompleted += (s, e) => { Trace.WriteLine("Upload complete.", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); XmlDocument ResponseDoc = new XmlDocument(); ResponseDoc.Load(new MemoryStream(e.Result)); ResponseDoc.Save(Configuration.LocalPath + @"\response.txt"); XmlNodeList ImageLink = ResponseDoc.SelectNodes(this.ImageLinkXPath); screenshot.Remote.ImageLink = ImageLink.Count > 0 ? ImageLink[0].InnerText : null; XmlNodeList DeleteLink = ResponseDoc.SelectNodes(this.DeleteLinkXPath); screenshot.Remote.DeleteLink = DeleteLink.Count > 0 ? DeleteLink[0].InnerText : null; var result = new UploaderEndedEventArgs(screenshot); this.UploadEnded(this, result); t.SetResult(result); }; Trace.WriteLine("Starting stream conversion... ", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var ImageData = string.Empty; using (var ms = screenshot.EditedScreenshotPNGImageStream()) ImageData = Convert.ToBase64String(ms.ToArray()); var CurrentUploadValues = new NameValueCollection(); foreach (var k in this.UploadValues.AllKeys.ToList()) CurrentUploadValues.Add(k, this.UploadValues[k].Replace("%i", ImageData)); Trace.WriteLine("Stream conversion complete.", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); Trace.WriteLine("Starting upload...", string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); wc.UploadValuesAsync(new Uri(this.EndpointUrl), CurrentUploadValues); this.UploadStarted(this, new UploaderProgressEventArgs(screenshot, 0)); } } catch (Exception ex) { Trace.WriteLine(string.Format("Exception occurred during upload: {0}", ex.GetBaseException()), string.Format("MultipartFormDataUploadService.Upload [{0}]", System.Threading.Thread.CurrentThread.Name)); var result = new UploaderEndedEventArgs(ex.GetBaseException()); this.UploadEnded(this, result); t.SetResult(result); } return t.Task; }