Esempio n. 1
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            uploadUrl = null;
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false);

            try {
                string dropboxUrl = null;
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait),
                                                 delegate() {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    dropboxUrl      = DropboxUtils.UploadToDropbox(surfaceToUpload, outputSettings, filename);
                }
                                                 );
                if (dropboxUrl == null)
                {
                    return(false);
                }
                uploadUrl = dropboxUrl;
                return(true);
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("dropbox", LangKey.upload_failure) + " " + e.Message);
                return(false);
            }
        }
Esempio n. 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();
                    }
                }
            }
        }