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; }
public static void RetrieveBoxThumbnail(BoxInfo imgurInfo) { LOG.InfoFormat("Retrieving Box image for {0} with url {1}", imgurInfo.ID, imgurInfo); HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreatedWebRequest(imgurInfo.SquareThumbnailUrl); webRequest.Method = "GET"; webRequest.ServicePoint.Expect100Continue = false; using (WebResponse response = webRequest.GetResponse()) { Stream responseStream = response.GetResponseStream(); imgurInfo.Image = Image.FromStream(responseStream); } return; }
/// <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 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; }