protected override void ImageCaptured(object sender, ImageCapturedEventArgs e) { Tracing.Trace("Picasa::{0:X8}::ImageCaptured", this.GetHashCode()); Hacks.BootstrapSettings(PluginSettings); this._fileName = e.ImageNames.FullSize; output.FetchOutputStream(new StreamHandler(this.SaveImage), this._fileName, e.FullSizeImage); }
/// <summary> /// This does the real work of the plugin - uploading to imgur.com. /// </summary> /// /// <remarks> /// First upload the main image, and then place the raw /// image URL onto the clipboard for easy reference/paste. /// </remarks> private void UploadImage() { Tracing.Trace("Imgur::UploadImage"); if (!VerifyBasicSettings()) { return; } Hacks.BootstrapSettings(PluginSettings); try { var http = new HttpClient(Plugin._baseUri); var form = new HttpMultipartMimeForm(); using (var fs = File.Open(this._fileName, FileMode.Open, FileAccess.Read)) { form.Add("key", PluginSettings.Key); form.Add("image", this._fileName, HttpContent.Create(fs, "application/octet-stream", fs.Length)); form.Add("type", "file"); form.Add("title", "uploaded by Cropper SendToImgur plugin"); // optional form.Add("caption", "http://cropper.codeplex.com"); // optional var response = http.Post("upload.xml", form.CreateHttpContent()); response.EnsureStatusIsSuccessful(); var foo = response.Content.ReadAsXmlSerializable <UploadResponse>(); if (foo.links == null) { throw new InvalidOperationException("Successful response, but link is empty."); } string rawImageUri = foo.links.original; if (PluginSettings.PopBrowser) { System.Diagnostics.Process.Start(rawImageUri); } Clipboard.SetDataObject(rawImageUri, true); if (this._logger != null) { try { this._logger.Log(rawImageUri); } catch (Exception ex2) { MessageBox.Show("There's been an exception writing the ImgUr log?" + Environment.NewLine + ex2.Message + Environment.NewLine, "This isn't serious", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (Exception exception2) { Tracing.Trace("Exception: {0}", exception2.StackTrace); Tracing.Trace("---------------------------------"); MessageBox.Show("There's been an exception uploading your image:" + Environment.NewLine + exception2.Message + Environment.NewLine + Environment.NewLine + "You will have to upload this file manually: " + Environment.NewLine + this._fileName, "Upload to Imgur failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; }