public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) { SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality); try { string url = null; new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("picasa", LangKey.communication_wait), delegate { string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails)); url = PicasaUtils.UploadToPicasa(surfaceToUpload, outputSettings, captureDetails.Title, filename); } ); uploadUrl = url; if (uploadUrl != null && _config.AfterUploadLinkToClipBoard) { ClipboardHelper.SetClipboardData(uploadUrl); } return(true); } catch (Exception e) { Log.Error("Error uploading.", e); MessageBox.Show(Language.GetString("picasa", LangKey.upload_failure) + " " + e.Message); } uploadUrl = null; return(false); }
public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl) { SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality); try { string url = null; new PleaseWaitForm().ShowAndWait("Picasa plug-in", Language.GetString("picasa", LangKey.communication_wait), delegate() { string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails)); string contentType = "image/" + config.UploadFormat.ToString(); url = PicasaUtils.UploadToPicasa(surfaceToUpload, outputSettings, captureDetails.Title, filename); } ); uploadUrl = url; if (uploadUrl != null && config.AfterUploadLinkToClipBoard) { ClipboardHelper.SetClipboardData(uploadUrl); } return(true); } catch (Exception e) { MessageBox.Show(Language.GetString("picasa", LangKey.upload_failure) + " " + e.ToString()); } uploadUrl = null; return(false); }
public bool Upload(ICaptureDetails captureDetails, Image image) { 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)); string contentType = "image/" + config.UploadFormat.ToString(); PicasaInfo picasaInfo = PicasaUtils.UploadToPicasa(buffer, captureDetails.DateTime.ToString(), filename, contentType); if (config.PicasaUploadHistory == null) { config.PicasaUploadHistory = new Dictionary <string, string>(); } if (picasaInfo.ID != null) { LOG.InfoFormat("Storing Picasa upload for id {0}", picasaInfo.ID); config.PicasaUploadHistory.Add(picasaInfo.ID, picasaInfo.ID); config.runtimePicasaHistory.Add(picasaInfo.ID, picasaInfo); } picasaInfo.Image = PicasaUtils.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 PicasaUtils.LoadHistory(); // Show if (config.AfterUploadOpenHistory) { PicasaHistory.ShowHistory(); } if (config.AfterUploadLinkToClipBoard) { Clipboard.SetText(picasaInfo.LinkUrl(config.PictureDisplaySize)); } return(true); } catch (Google.GData.Client.InvalidCredentialsException eLo) { MessageBox.Show(lang.GetString(LangKey.InvalidCredentials)); } catch (Exception e) { MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString()); } finally { backgroundForm.CloseDialog(); } } return(false); }