/// <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); } }
public SettingsForm(BoxConfiguration config) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); InitializeTexts(); combobox_uploadimageformat.Items.Clear(); foreach (OutputFormat format in Enum.GetValues(typeof(OutputFormat))) { combobox_uploadimageformat.Items.Add(format.ToString()); } comboBox_DefaultSize.Items.Clear(); foreach (PictureDisplaySize displaySize in Enum.GetValues(typeof(PictureDisplaySize))) { comboBox_DefaultSize.Items.Add(displaySize.ToString()); } BoxUtils.LoadHistory(); if (config.runtimeBoxHistory.Count > 0) { historyButton.Enabled = true; } else { historyButton.Enabled = false; } }
public static BoxInfo RetrieveBoxInfo(long id) { BoxInfo boxInfo = new BoxInfo(); boxInfo.ID = id; boxInfo.WebUrl = string.Format("http://www.box.com/files#/files/0/f/0/1/f_{0}", id); boxInfo.SquareThumbnailUrl = string.Format("https://www.box.net/api/1.0/download/{0}/{1}", config.boxToken, id); boxInfo.OriginalUrl = boxInfo.SquareThumbnailUrl; boxInfo.Timestamp = DateTime.Now; using (BoxNet.boxnetPortClient client = BoxUtils.SoapClient()) { BoxNet.SOAPFileInfo info; client.get_file_info(out info, BoxUtils.Box_API_KEY, config.boxToken, id); if (info != null) { boxInfo.Description = info.description; boxInfo.Title = info.file_name; if (info.shared == 1) { boxInfo.WebUrl = string.Format("http://www.box.net/shared/{0}", info.public_name); } } } return(boxInfo); }
public static void LoadHistory() { if (config.runtimeBoxHistory == null) { return; } if (config.BoxUploadHistory == null) { return; } if (config.runtimeBoxHistory.Count == config.BoxUploadHistory.Count) { return; } // Load the Box history List <string> hashes = new List <string>(); foreach (string hash in config.BoxUploadHistory.Keys) { hashes.Add(hash); } bool saveNeeded = false; foreach (string hash in hashes) { if (config.runtimeBoxHistory.ContainsKey(hash)) { // Already loaded continue; } try { long id = 0; id = long.Parse(hash); BoxInfo imgurInfo = BoxUtils.RetrieveBoxInfo(id); if (imgurInfo != null) { BoxUtils.RetrieveBoxThumbnail(imgurInfo); config.runtimeBoxHistory.Add(hash, imgurInfo); } else { LOG.DebugFormat("Deleting not found Box {0} from config.", hash); config.BoxUploadHistory.Remove(hash); saveNeeded = true; } } catch (Exception e) { LOG.Error("Problem loading Box history for hash " + hash, e); } } if (saveNeeded) { // Save needed changes IniConfig.Save(); } }
public static void DeleteBoxImage(BoxInfo BoxInfo) { config.runtimeBoxHistory.Remove(BoxInfo.ID.ToString()); config.BoxUploadHistory.Remove(BoxInfo.ID.ToString()); using (BoxNet.boxnetPortClient client = BoxUtils.SoapClient()) { client.delete(BoxUtils.Box_API_KEY, config.boxToken, "file", BoxInfo.ID); } BoxInfo.Image = null; }
void ButtonOKClick(object sender, EventArgs e) { if (!string.IsNullOrEmpty(boxTicket)) { using (BoxNet.boxnetPortClient client = BoxUtils.SoapClient()) { string auth_token = string.Empty; BoxNet.SOAPUser user = new BoxNet.SOAPUser(); client.get_auth_token(out auth_token, out user, BoxUtils.Box_API_KEY, boxTicket); textBoxAuthToken.Text = auth_token; this.DialogResult = DialogResult.OK; } } else { this.DialogResult = DialogResult.OK; } }
private void buttonAuthenticate_Click(object sender, EventArgs e) { using (BoxNet.boxnetPortClient client = BoxUtils.SoapClient()) { if (string.IsNullOrEmpty(boxTicket)) { string result = client.get_ticket(out boxTicket, BoxUtils.Box_API_KEY); System.Diagnostics.Process.Start(string.Format("https://www.box.net/api/1.0/auth/{0}", boxTicket)); } else { string auth_token = string.Empty; BoxNet.SOAPUser user = new BoxNet.SOAPUser(); string result = client.get_auth_token(out auth_token, out user, BoxUtils.Box_API_KEY, boxTicket); boxTicket = string.Empty; textBoxAuthToken.Text = auth_token; } } }
/// <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(); } } } }
public void HistoryMenuClick(object sender, EventArgs eventArgs) { BoxUtils.LoadHistory(); BoxHistory.ShowHistory(); }