public static void LoadHistory() { if (config.runtimeFlickrHistory == null) { return; } if (config.flickrUploadHistory == null) { return; } if (config.runtimeFlickrHistory.Count == config.flickrUploadHistory.Count) { return; } // Load the flickr history List <string> hashes = new List <string>(); foreach (string hash in config.flickrUploadHistory.Keys) { hashes.Add(hash); } bool saveNeeded = false; foreach (string hash in hashes) { if (config.runtimeFlickrHistory.ContainsKey(hash)) { // Already loaded continue; } try { FlickrInfo imgurInfo = FlickrUtils.RetrieveFlickrInfo(hash); if (imgurInfo != null) { FlickrUtils.RetrieveFlickrThumbnail(imgurInfo); config.runtimeFlickrHistory.Add(hash, imgurInfo); } else { LOG.DebugFormat("Deleting not found Flickr {0} from config.", hash); config.flickrUploadHistory.Remove(hash); saveNeeded = true; } } catch (Exception e) { LOG.Error("Problem loading Flickr history for hash " + hash, e); } } if (saveNeeded) { // Save needed changes IniConfig.Save(); } }
public static void DeleteFlickrImage(FlickrInfo flickrInfo) { // Make sure we remove it from the history, if no error occured config.runtimeFlickrHistory.Remove(flickrInfo.ID); config.flickrUploadHistory.Remove(flickrInfo.ID); Flickr flickr = new Flickr(Flickr_API_KEY, Flickr_SHARED_SECRET, config.flickrToken); flickr.PhotosDelete(flickrInfo.ID); flickr = null; flickrInfo.Image = null; }
public static void RetrieveFlickrThumbnail(FlickrInfo imgurInfo) { LOG.InfoFormat("Retrieving Flickr 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; }
public static FlickrInfo RetrieveFlickrInfo(string id) { LOG.InfoFormat("Retrieving flickr info for {0}", id); FlickrInfo flickrInfo = new FlickrInfo(); Flickr flickr = new Flickr(Flickr_API_KEY, Flickr_SHARED_SECRET, config.flickrToken); PhotoInfo photoInfo = flickr.PhotosGetInfo(id); flickrInfo.ID = id; flickrInfo.Title = photoInfo.Title; flickrInfo.Timestamp = photoInfo.DatePosted; flickrInfo.Description = photoInfo.Description; flickrInfo.LargeUrl = photoInfo.LargeUrl; flickrInfo.MediumUrl = photoInfo.MediumUrl; flickrInfo.OriginalUrl = photoInfo.OriginalUrl; flickrInfo.SquareThumbnailUrl = photoInfo.SquareThumbnailUrl; flickrInfo.WebUrl = photoInfo.WebUrl; flickr = null; return(flickrInfo); }
public bool Upload(ICaptureDetails captureDetails, Image image) { if (string.IsNullOrEmpty(config.flickrToken)) { 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 filename = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails)); FlickrInfo flickrInfo = FlickrUtils.UploadToFlickr(buffer, captureDetails.Title, filename); if (config.flickrUploadHistory == null) { config.flickrUploadHistory = new Dictionary <string, string>(); } if (flickrInfo.ID != null) { LOG.InfoFormat("Storing Flickr upload for id {0}", flickrInfo.ID); config.flickrUploadHistory.Add(flickrInfo.ID, flickrInfo.ID); config.runtimeFlickrHistory.Add(flickrInfo.ID, flickrInfo); } flickrInfo.Image = FlickrUtils.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 FlickrUtils.LoadHistory(); // Show if (config.AfterUploadOpenHistory) { FlickrHistory.ShowHistory(); } if (config.AfterUploadLinkToClipBoard) { Clipboard.SetText(flickrInfo.LinkUrl(config.PictureDisplaySize)); } return(true); } catch (Exception e) { MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.Message); return(false); } finally { backgroundForm.CloseDialog(); } } } }
public static FlickrInfo RetrieveFlickrInfo(string id) { LOG.InfoFormat("Retrieving flickr info for {0}", id); FlickrInfo flickrInfo = new FlickrInfo(); Flickr flickr = new Flickr(Flickr_API_KEY, Flickr_SHARED_SECRET, config.flickrToken); PhotoInfo photoInfo = flickr.PhotosGetInfo(id); flickrInfo.ID = id; flickrInfo.Title = photoInfo.Title; flickrInfo.Timestamp = photoInfo.DatePosted; flickrInfo.Description = photoInfo.Description; flickrInfo.LargeUrl = photoInfo.LargeUrl; flickrInfo.MediumUrl = photoInfo.MediumUrl; flickrInfo.OriginalUrl = photoInfo.OriginalUrl; flickrInfo.SquareThumbnailUrl = photoInfo.SquareThumbnailUrl; flickrInfo.WebUrl = photoInfo.WebUrl; flickr = null; return flickrInfo; }