/// <summary> /// This will be called when the menu item in the Editor is clicked /// </summary> public string Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload) { SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false); try { string url = null; string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename); new PleaseWaitForm().ShowAndWait("Box plug-in", Language.GetString("box", LangKey.communication_wait), delegate() { url = BoxUtils.UploadToBox(imageToUpload, captureDetails.Title, filename); } ); if (url != null && config.AfterUploadLinkToClipBoard) { ClipboardHelper.SetClipboardData(url); } return(url); } catch (Exception ex) { LOG.Error("Error uploading.", ex); MessageBox.Show(Language.GetString("box", LangKey.upload_failure) + " " + ex.ToString()); return(null); } }
/// <summary> /// This will be called when the menu item in the Editor is clicked /// </summary> public bool Upload(ICaptureDetails captureDetails, Image image) { if (string.IsNullOrEmpty(config.boxToken)) { MessageBox.Show(lang.GetString(LangKey.TokenNotSet), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } else { using (MemoryStream stream = new MemoryStream()) { BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, lang.GetString(LangKey.communication_wait)); host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality); byte[] buffer = stream.GetBuffer(); try { string contentType = "image/" + config.UploadFormat.ToString(); string filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails)); BoxInfo BoxInfo = BoxUtils.UploadToBox(buffer, captureDetails.Title, filename, contentType); if (config.BoxUploadHistory == null) { config.BoxUploadHistory = new Dictionary <string, string>(); } if (BoxInfo.ID != null) { LOG.InfoFormat("Storing Box upload for id {0}", BoxInfo.ID); config.BoxUploadHistory.Add(BoxInfo.ID.ToString(), BoxInfo.ID.ToString()); config.runtimeBoxHistory.Add(BoxInfo.ID.ToString(), BoxInfo); } BoxInfo.Image = BoxUtils.CreateThumbnail(image, 90, 90); // Make sure the configuration is save, so we don't lose the deleteHash IniConfig.Save(); // Make sure the history is loaded, will be done only once BoxUtils.LoadHistory(); // Show if (config.AfterUploadOpenHistory) { BoxHistory.ShowHistory(); } if (config.AfterUploadLinkToClipBoard) { Clipboard.SetText(BoxInfo.LinkUrl(config.PictureDisplaySize)); } return(true); } catch (Exception e) { MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString()); return(false); } finally { backgroundForm.CloseDialog(); } } } }