Exemplo n.º 1
0
        public bool Upload(ICaptureDetails captureDetails, ISurface surface, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, false);

            uploadUrl = null;
            try {
                string flickrUrl = null;
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("flickr", LangKey.communication_wait),
                                                 delegate {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));
                    flickrUrl       = FlickrUtils.UploadToFlickr(surface, outputSettings, captureDetails.Title, filename);
                }
                                                 );

                if (flickrUrl == null)
                {
                    return(false);
                }
                uploadUrl = flickrUrl;

                if (_config.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(flickrUrl);
                }
                return(true);
            } catch (Exception e) {
                Log.Error("Error uploading.", e);
                MessageBox.Show(Language.GetString("flickr", LangKey.upload_failure) + " " + e.Message);
            }
            return(false);
        }
Exemplo n.º 2
0
        public void Upload(ICaptureDetails captureDetails, ISurface surface, ExportInformation exportInformation)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false);

            try {
                string flickrUrl = null;
                new PleaseWaitForm().ShowAndWait("Flickr plug-in", Language.GetString("flickr", LangKey.communication_wait),
                                                 delegate() {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    flickrUrl       = FlickrUtils.UploadToFlickr(surface, outputSettings, captureDetails.Title, filename);
                }
                                                 );

                if (flickrUrl == null)
                {
                    exportInformation.ExportMade = false;
                    return;
                }
                exportInformation.ExportMade = true;
                exportInformation.Uri        = flickrUrl;

                if (config.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(flickrUrl);
                }
            } catch (Exception e) {
                MessageBox.Show(Language.GetString("flickr", LangKey.upload_failure) + " " + e.Message);
            }
        }
        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();
                    }
                }
            }
        }