示例#1
0
        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);
        }
示例#2
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            if (config.DropboxAccessToken == null)
            {
                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));
                        DropboxInfo DropboxInfo = DropboxUtils.UploadToDropbox(buffer, captureDetails.Title, filename);

                        if (config.DropboxUploadHistory == null)
                        {
                            config.DropboxUploadHistory = new Dictionary <string, string>();
                        }

                        if (DropboxInfo.ID != null)
                        {
                            LOG.InfoFormat("Storing Dropbox upload for id {0}", DropboxInfo.ID);

                            config.DropboxUploadHistory.Add(DropboxInfo.ID, DropboxInfo.ID);
                            config.runtimeDropboxHistory.Add(DropboxInfo.ID, DropboxInfo);
                        }

                        DropboxInfo.Image = DropboxUtils.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
                        DropboxUtils.LoadHistory();

                        // Show
                        if (config.AfterUploadOpenHistory)
                        {
                            DropboxHistory.ShowHistory();
                        }

                        if (config.AfterUploadLinkToClipBoard)
                        {
                            Clipboard.SetText(DropboxInfo.WebUrl);
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString());
                        return(false);
                    }
                    finally
                    {
                        backgroundForm.CloseDialog();
                    }
                }
            }
        }