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
        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);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public string Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false);

            try {
                string           url           = null;
                string           filename      = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                SurfaceContainer imageToUpload = new SurfaceContainer(surfaceToUpload, outputSettings, filename);

                new PleaseWaitForm().ShowAndWait("Box plug-in", Language.GetString("box", LangKey.communication_wait),
                                                 delegate() {
                    url = BoxUtils.UploadToBox(imageToUpload, captureDetails.Title, filename);
                }
                                                 );

                if (url != null && config.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(url);
                }

                return(url);
            } catch (Exception ex) {
                LOG.Error("Error uploading.", ex);
                MessageBox.Show(Language.GetString("box", LangKey.upload_failure) + " " + ex.ToString());
                return(null);
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(Designation, Description);
            string                filename          = Path.GetFileName(FilenameHelper.GetFilename(Config.UploadFormat, captureDetails));
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings(Config.UploadFormat, Config.UploadJpegQuality, Config.UploadReduceColors);

            if (_jiraIssue != null)
            {
                try {
                    // Run upload in the background
                    new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                     async() =>
                    {
                        var surfaceContainer = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
                        await _jiraPlugin.JiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer);
                        surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
                    }
                                                     );
                    Log.DebugFormat("Uploaded to Jira {0}", _jiraIssue.Key);
                    exportInformation.ExportMade = true;
                    exportInformation.Uri        = surfaceToUpload.UploadUrl;
                } catch (Exception e) {
                    MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                }
            }
            else
            {
                var jiraForm = new JiraForm(_jiraPlugin.JiraConnector);
                jiraForm.SetFilename(filename);
                var dialogResult = jiraForm.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    try {
                        surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri;
                        // Run upload in the background
                        new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                         async() =>
                        {
                            await jiraForm.UploadAsync(new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                        }
                                                         );
                        Log.DebugFormat("Uploaded to Jira {0}", jiraForm.GetJiraIssue().Key);
                        exportInformation.ExportMade = true;
                        exportInformation.Uri        = surfaceToUpload.UploadUrl;
                    } catch (Exception e) {
                        MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                    }
                }
            }
            ProcessExport(exportInformation, surfaceToUpload);
            return(exportInformation);
        }
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            string                filename          = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);

            if (jira != null)
            {
                try {
                    // Run upload in the background
                    new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                     delegate() {
                        jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                    }
                                                     );
                    LOG.Debug("Uploaded to Jira.");
                    exportInformation.ExportMade = true;
                    // TODO: This can't work:
                    exportInformation.Uri = surfaceToUpload.UploadURL;
                } catch (Exception e) {
                    MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                }
            }
            else
            {
                JiraForm jiraForm = new JiraForm(jiraPlugin.JiraConnector);
                if (jiraPlugin.JiraConnector.isLoggedIn)
                {
                    jiraForm.setFilename(filename);
                    DialogResult result = jiraForm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        try {
                            // Run upload in the background
                            new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                             delegate() {
                                jiraForm.upload(new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                            }
                                                             );
                            LOG.Debug("Uploaded to Jira.");
                            exportInformation.ExportMade = true;
                            // TODO: This can't work:
                            exportInformation.Uri = surfaceToUpload.UploadURL;
                        } catch (Exception e) {
                            MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                        }
                    }
                }
            }
            ProcessExport(exportInformation, surfaceToUpload);
            return(exportInformation);
        }
Esempio n. 8
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);

            // force password check to take place before the pages load
            if (!ConfluencePlugin.ConfluenceConnector.isLoggedIn)
            {
                return(exportInformation);
            }

            Page   selectedPage = page;
            bool   openPage     = (page == null) && config.OpenPageAfterUpload;
            string filename     = FilenameHelper.GetFilename(config.UploadFormat, captureDetails);

            if (selectedPage == null)
            {
                ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename);
                Nullable <bool>  dialogResult     = confluenceUpload.ShowDialog();
                if (dialogResult.HasValue && dialogResult.Value)
                {
                    selectedPage = confluenceUpload.SelectedPage;
                    if (confluenceUpload.isOpenPageSelected)
                    {
                        openPage = false;
                    }
                    filename = confluenceUpload.Filename;
                }
            }
            if (selectedPage != null)
            {
                string errorMessage;
                bool   uploaded = upload(surface, selectedPage, filename, out errorMessage);
                if (uploaded)
                {
                    if (openPage)
                    {
                        try {
                            Process.Start(selectedPage.Url);
                        } catch { }
                    }
                    exportInformation.ExportMade = true;
                    exportInformation.Uri        = selectedPage.Url;
                }
                else
                {
                    exportInformation.ErrorMessage = errorMessage;
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        /// <summary>
        ///     Export the capture to Photobucket
        /// </summary>
        /// <param name="manuallyInitiated"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns></returns>
        public override async Task <ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            var outputSettings    = new SurfaceOutputSettings(_photobucketConfiguration.UploadFormat, _photobucketConfiguration.UploadJpegQuality, false);
            var filename          = Path.GetFileName(FilenameHelper.GetFilename(_photobucketConfiguration.UploadFormat, captureDetails));

            var uploaded = await UploadToPhotobucket(surface, outputSettings, filename, captureDetails.Title, _albumPath);

            if (uploaded != null)
            {
                exportInformation.ExportMade = true;
                exportInformation.Uri        = uploaded.Original;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Esempio n. 10
0
        /// <summary>
        /// Upload the capture to imgur
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="image"></param>
        /// <param name="uploadURL">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);

            try {
                string    filename  = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                ImgurInfo imgurInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Imgur plug-in", Language.GetString("imgur", LangKey.communication_wait),
                                                 delegate() {
                    imgurInfo = ImgurUtils.UploadToImgur(surfaceToUpload, outputSettings, captureDetails.Title, filename);
                    LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
                    config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
                    config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
                    CheckHistory();
                }
                                                 );

                // TODO: Optimize a second call for export
                using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
                    imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
                }
                IniConfig.Save();
                uploadURL = null;
                try {
                    if (config.UsePageLink)
                    {
                        uploadURL = imgurInfo.Page;
                        ClipboardHelper.SetClipboardData(imgurInfo.Page);
                    }
                    else
                    {
                        uploadURL = imgurInfo.Original;
                        ClipboardHelper.SetClipboardData(imgurInfo.Original);
                    }
                } catch (Exception ex) {
                    LOG.Error("Can't write to clipboard: ", ex);
                }
                return(true);
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
            }
            uploadURL = null;
            return(false);
        }
Esempio n. 11
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            CoreConfiguration     config            = IniConfig.GetIniSection <CoreConfiguration>();
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();

            string file     = FilenameHelper.GetFilename(OutputFormat.png, null);
            string filePath = Path.Combine(config.OutputFilePath, file);

            using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
                ImageOutput.SaveToStream(surface, stream, outputSettings);
            }
            exportInformation.Filepath   = filePath;
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Esempio n. 12
0
        /// <summary>
        /// Upload the capture to qiniu cloud
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="albumPath">Path to the album</param>
        /// <param name="uploadUrl">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, _config.UploadReduceColors);

            try
            {
                string filename = _config.ImageNamePrefix + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + _config.UploadFormat.ToString().ToLower();
                Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));

                string path = Directory.GetCurrentDirectory();

                string fullPath = Path.Combine(path, filename);

                // public static void Save(ISurface surface, string fullPath, bool allowOverwrite, SurfaceOutputSettings outputSettings, bool copyPathToClipboard)
                // Run upload in the background
                MemoryStream streamoutput = new MemoryStream();
                ImageOutput.SaveToStream(surfaceToUpload, streamoutput, outputSettings);
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("qiniu", LangKey.communication_wait),
                                                 delegate
                {
                    HttpResult result = QiniuUtils.UploadFile(streamoutput, filename);
                }
                                                 );
                // This causes an exeption if the upload failed :)
                //Log.DebugFormat("Uploaded to qiniu page: " + qiniuInfo.Page);

                uploadUrl = _config.DefaultDomain + filename;

                string markdownURL = "![](" + uploadUrl + ")";


                Clipboard.SetText(markdownURL);



                return(true);
            }
            catch (Exception e)
            {
                Log.Error(e);
                MessageBox.Show(Language.GetString("qiniu", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
Esempio n. 13
0
        public async Task <string> Upload(ICaptureDetails captureDetails, ISurface surface)
        {
            string uploadUrl = null;

            var outputSettings = new SurfaceOutputSettings(_flickrConfiguration.UploadFormat, _flickrConfiguration.UploadJpegQuality, false);

            try
            {
                var cancellationTokenSource = new CancellationTokenSource();
                using (var pleaseWaitForm = new PleaseWaitForm("Flickr", _flickrLanguage.CommunicationWait, cancellationTokenSource))
                {
                    pleaseWaitForm.Show();
                    try
                    {
                        var filename = Path.GetFileName(FilenameHelper.GetFilename(_flickrConfiguration.UploadFormat, captureDetails));
                        uploadUrl = await FlickrUtils.UploadToFlickrAsync(surface, outputSettings, captureDetails.Title, filename);
                    }
                    finally
                    {
                        pleaseWaitForm.Close();
                    }
                }


                if (uploadUrl == null)
                {
                    return(null);
                }
                if (_flickrConfiguration.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(uploadUrl);
                }
            }
            catch (Exception e)
            {
                Log.Error().WriteLine(e, "Error uploading.");
                MessageBox.Show(_flickrLanguage.UploadFailure + " " + e.Message);
            }
            return(uploadUrl);
        }
Esempio n. 14
0
        /// <summary>
        /// Upload the capture to Photobucket
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="uploadURL">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, string albumPath, out string uploadURL)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.OutputFileFormat, config.OutputFileJpegQuality, config.OutputFileAutoReduceColors);

            try {
                string          filename        = Path.GetFileName(FilenameHelper.GetFilename(config.OutputFileFormat, captureDetails));
                PhotobucketInfo photobucketInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Photobucket plug-in", Language.GetString("photobucket", LangKey.communication_wait),
                                                 delegate() {
                    photobucketInfo = PhotobucketUtils.UploadToPhotobucket(surfaceToUpload, outputSettings, albumPath, captureDetails.Title, filename);
                }
                                                 );
                // This causes an exeption if the upload failed :)
                LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
                uploadURL = null;
                try {
                    if (config.UsePageLink)
                    {
                        uploadURL = photobucketInfo.Page;
                        Clipboard.SetText(photobucketInfo.Page);
                    }
                    else
                    {
                        uploadURL = photobucketInfo.Original;
                        Clipboard.SetText(photobucketInfo.Original);
                    }
                } catch (Exception ex) {
                    LOG.Error("Can't write to clipboard: ", ex);
                }
                return(true);
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("photobucket", LangKey.upload_failure) + " " + e.Message);
            }
            uploadURL = null;
            return(false);
        }
Esempio n. 15
0
        /// <summary>
        ///     This will be called when the menu item in the Editor is clicked
        /// </summary>
        private async Task <string> UploadAsync(ICaptureDetails captureDetails, ISurface surfaceToUpload, CancellationToken cancellationToken = default)
        {
            string dropboxUrl     = null;
            var    outputSettings = new SurfaceOutputSettings(_dropboxPluginConfiguration.UploadFormat, _dropboxPluginConfiguration.UploadJpegQuality, false);

            try
            {
                var cancellationTokenSource = new CancellationTokenSource();
                using (var pleaseWaitForm = new PleaseWaitForm("Dropbox", _dropboxLanguage.CommunicationWait, cancellationTokenSource))
                {
                    pleaseWaitForm.Show();
                    try
                    {
                        var filename = Path.GetFileName(FilenameHelper.GetFilename(_dropboxPluginConfiguration.UploadFormat, captureDetails));
                        using (var imageStream = new MemoryStream())
                        {
                            ImageOutput.SaveToStream(surfaceToUpload, imageStream, outputSettings);
                            imageStream.Position = 0;
                            using (var streamContent = new StreamContent(imageStream))
                            {
                                streamContent.Headers.ContentType = new MediaTypeHeaderValue("image/" + outputSettings.Format);
                                dropboxUrl = await UploadAsync(filename, streamContent, null, cancellationToken);
                            }
                        }
                    }
                    finally
                    {
                        pleaseWaitForm.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error().WriteLine(e);
                MessageBox.Show(_dropboxLanguage.UploadFailure + " " + e.Message);
            }
            return(dropboxUrl);
        }
        /// <summary>
        /// Upload the capture to FogBugz
        /// </summary>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(OutputFormat.jpg, 90, false);

            using (MemoryStream stream = new MemoryStream()) {
                surfaceToUpload.GetImageForExport().Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                try {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(OutputFormat.jpg, captureDetails));

                    CaseSearchForm caseSearchForm = new CaseSearchForm(config, this.host, filename, captureDetails, stream);

                    if (caseSearchForm.ShowDialog() == DialogResult.OK)
                    {
                        IniConfig.Save();
                        return(true);
                    }
                } catch (Exception e) {
                    MessageBox.Show(Language.GetString("fogbugz", LangKey.upload_failure) + " " + e.Message);
                }
            }
            return(false);
        }
Esempio n. 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="progress"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <string> UploadToPicasa(ISurface surface, IProgress <int> progress = null, CancellationToken token = default)
        {
            string filename       = Path.GetFileName(FilenameHelper.GetFilename(_googlePhotosConfiguration.UploadFormat, surface.CaptureDetails));
            var    outputSettings = new SurfaceOutputSettings(_googlePhotosConfiguration.UploadFormat, _googlePhotosConfiguration.UploadJpegQuality);
            // Fill the OAuth2Settings

            var oAuthHttpBehaviour = HttpBehaviour.Current.ShallowClone();

            // Use UploadProgress
            if (progress != null)
            {
                oAuthHttpBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100))); };
            }
            oAuthHttpBehaviour.OnHttpMessageHandlerCreated = httpMessageHandler => new OAuth2HttpMessageHandler(_oAuth2Settings, oAuthHttpBehaviour, httpMessageHandler);
            if (_googlePhotosConfiguration.AddFilename)
            {
                oAuthHttpBehaviour.OnHttpClientCreated = httpClient => httpClient.AddDefaultRequestHeader("Slug", Uri.EscapeDataString(filename));
            }

            string response;
            var    uploadUri = new Uri("https://picasaweb.google.com/data/feed/api/user").AppendSegments(_googlePhotosConfiguration.UploadUser, "albumid", _googlePhotosConfiguration.UploadAlbum);

            using (var imageStream = new MemoryStream())
            {
                ImageOutput.SaveToStream(surface, imageStream, outputSettings);
                imageStream.Position = 0;
                using (var content = new StreamContent(imageStream))
                {
                    content.Headers.Add("Content-Type", "image/" + outputSettings.Format);

                    oAuthHttpBehaviour.MakeCurrent();
                    response = await uploadUri.PostAsync <string>(content, token);
                }
            }

            return(ParseResponse(response));
        }
Esempio n. 18
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var    exportInformation = new ExportInformation(this.Designation, this.Description);
            string filename          = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
            var    outputSettings    = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);

            try
            {
                // Run upload in the background
                new PleaseWaitForm().ShowAndWait(Description, "Uploading",
                                                 delegate()
                {
                    demoPlugin.DemoConnector.AddAttachment(filename, new SurfaceContainer(surface, outputSettings, filename));
                }
                                                 );
                LOG.Debug("Uploaded to Jira.");
                exportInformation.ExportMade = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Upload failure");
            }
            return(exportInformation);
        }
Esempio n. 19
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            var filename          = Path.GetFileName(FilenameHelper.GetFilename(_jiraConfiguration.UploadFormat, captureDetails));
            var outputSettings    = new SurfaceOutputSettings(_jiraConfiguration.UploadFormat, _jiraConfiguration.UploadJpegQuality, _jiraConfiguration.UploadReduceColors);

            if (_jiraIssue != null)
            {
                try
                {
                    // Run upload in the background
                    new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                     async() =>
                    {
                        var surfaceContainer = new SurfaceContainer(surface, outputSettings, filename);
                        await _jiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer);
                        surface.UploadUrl = _jiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
                    }
                                                     );
                    Log.Debug().WriteLine("Uploaded to Jira {0}", _jiraIssue.Key);
                    exportInformation.ExportMade = true;
                    exportInformation.Uri        = surface.UploadUrl;
                }
                catch (Exception e)
                {
                    MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                }
            }
            else
            {
                // TODO: set filename
                // _jiraViewModel.SetFilename(filename);
                if (_windowManager.ShowDialog(_jiraViewModel) == true)
                {
                    try
                    {
                        surface.UploadUrl = _jiraConnector.JiraBaseUri.AppendSegments("browse", _jiraViewModel.JiraIssue.Key).AbsoluteUri;
                        // Run upload in the background
                        new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                         async() =>
                        {
                            var attachment = new SurfaceContainer(surface, outputSettings, _jiraViewModel.Filename);

                            await _jiraConnector.AttachAsync(_jiraViewModel.JiraIssue.Key, attachment);

                            if (!string.IsNullOrEmpty(_jiraViewModel.Comment))
                            {
                                await _jiraConnector.AddCommentAsync(_jiraViewModel.JiraIssue.Key, _jiraViewModel.Comment);
                            }
                        }
                                                         );
                        Log.Debug().WriteLine("Uploaded to Jira {0}", _jiraViewModel.JiraIssue.Key);
                        exportInformation.ExportMade = true;
                        exportInformation.Uri        = surface.UploadUrl;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                    }
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Esempio n. 20
0
        /// <summary>
        /// Share the surface by using the Share-UI of Windows 10
        /// </summary>
        /// <param name="shareInfo">ShareInfo</param>
        /// <param name="handle">IntPtr with the handle for the hosting window</param>
        /// <param name="surface">ISurface with the bitmap to share</param>
        /// <param name="captureDetails">ICaptureDetails</param>
        /// <returns>Task with string, which describes the application which was used to share with</returns>
        private async Task Share(ShareInfo shareInfo, IntPtr handle, ISurface surface, ICaptureDetails captureDetails)
        {
            using (var imageStream = new MemoryRandomAccessStream())
                using (var logoStream = new MemoryRandomAccessStream())
                    using (var thumbnailStream = new MemoryRandomAccessStream())
                    {
                        var outputSettings = new SurfaceOutputSettings();
                        outputSettings.PreventGreenshotFormat();

                        // Create capture for export
                        ImageOutput.SaveToStream(surface, imageStream, outputSettings);
                        imageStream.Position = 0;
                        Log.Debug().WriteLine("Created RandomAccessStreamReference for the image");
                        var imageRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(imageStream);

                        // Create thumbnail
                        RandomAccessStreamReference thumbnailRandomAccessStreamReference;
                        using (var tmpImageForThumbnail = surface.GetBitmapForExport())
                            using (var thumbnail = tmpImageForThumbnail.CreateThumbnail(240, 160))
                            {
                                ImageOutput.SaveToStream(thumbnail, null, thumbnailStream, outputSettings);
                                thumbnailStream.Position             = 0;
                                thumbnailRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(thumbnailStream);
                                Log.Debug().WriteLine("Created RandomAccessStreamReference for the thumbnail");
                            }

                        // Create logo
                        RandomAccessStreamReference logoRandomAccessStreamReference;
                        using (var logo = GreenshotResources.GetGreenshotIcon().ToBitmap())
                            using (var logoThumbnail = logo.CreateThumbnail(30, 30))
                            {
                                ImageOutput.SaveToStream(logoThumbnail, null, logoStream, outputSettings);
                                logoStream.Position             = 0;
                                logoRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(logoStream);
                                Log.Info().WriteLine("Created RandomAccessStreamReference for the logo");
                            }

                        var dataTransferManagerHelper = new DataTransferManagerHelper(handle);
                        dataTransferManagerHelper.DataTransferManager.ShareProvidersRequested += (sender, args) =>
                        {
                            shareInfo.AreShareProvidersRequested = true;
                            Log.Debug().WriteLine("Share providers requested: {0}", string.Join(",", args.Providers.Select(p => p.Title)));
                        };
                        dataTransferManagerHelper.DataTransferManager.TargetApplicationChosen += (dtm, args) =>
                        {
                            shareInfo.ApplicationName = args.ApplicationName;
                            Log.Debug().WriteLine("TargetApplicationChosen: {0}", args.ApplicationName);
                        };
                        var filename    = FilenameHelper.GetFilename(OutputFormats.png, captureDetails);
                        var storageFile = await StorageFile.CreateStreamedFileAsync(filename, async streamedFileDataRequest =>
                        {
                            shareInfo.IsDeferredFileCreated = true;
                            // Information on the "how" was found here: https://socialeboladev.wordpress.com/2013/03/15/how-to-use-createstreamedfileasync/
                            Log.Debug().WriteLine("Creating deferred file {0}", filename);
                            try
                            {
                                using (var deferredStream = streamedFileDataRequest.AsStreamForWrite())
                                {
                                    await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
                                    await imageStream.FlushAsync().ConfigureAwait(false);
                                }
                                // Signal that the stream is ready
                                streamedFileDataRequest.Dispose();
                            }
                            catch (Exception)
                            {
                                streamedFileDataRequest.FailAndClose(StreamedFileFailureMode.Incomplete);
                            }
                        }, imageRandomAccessStreamReference).AsTask().ConfigureAwait(false);

                        dataTransferManagerHelper.DataTransferManager.DataRequested += (dataTransferManager, dataRequestedEventArgs) =>
                        {
                            var deferral = dataRequestedEventArgs.Request.GetDeferral();
                            try
                            {
                                shareInfo.IsDataRequested = true;
                                Log.Debug().WriteLine("DataRequested with operation {0}", dataRequestedEventArgs.Request.Data.RequestedOperation);
                                var dataPackage = dataRequestedEventArgs.Request.Data;
                                dataPackage.OperationCompleted += (dp, eventArgs) =>
                                {
                                    Log.Debug().WriteLine("OperationCompleted: {0}, shared with", eventArgs.Operation);
                                    shareInfo.CompletedWithOperation = eventArgs.Operation;
                                    shareInfo.AcceptedFormat         = eventArgs.AcceptedFormatId;

                                    shareInfo.ShareTask.TrySetResult(true);
                                };
                                dataPackage.Destroyed += (dp, o) =>
                                {
                                    shareInfo.IsDestroyed = true;
                                    Log.Debug().WriteLine("Destroyed");
                                    shareInfo.ShareTask.TrySetResult(true);
                                };
                                dataPackage.ShareCompleted += (dp, shareCompletedEventArgs) =>
                                {
                                    shareInfo.IsShareCompleted = true;
                                    Log.Debug().WriteLine("ShareCompleted");
                                    shareInfo.ShareTask.TrySetResult(true);
                                };
                                dataPackage.Properties.Title               = captureDetails.Title;
                                dataPackage.Properties.ApplicationName     = "Greenshot";
                                dataPackage.Properties.Description         = "Share a screenshot";
                                dataPackage.Properties.Thumbnail           = thumbnailRandomAccessStreamReference;
                                dataPackage.Properties.Square30x30Logo     = logoRandomAccessStreamReference;
                                dataPackage.Properties.LogoBackgroundColor = Color.FromArgb(0xff, 0x3d, 0x3d, 0x3d);
                                dataPackage.SetStorageItems(new[] { storageFile });
                                dataPackage.SetBitmap(imageRandomAccessStreamReference);
                            }
                            finally
                            {
                                deferral.Complete();
                                Log.Debug().WriteLine("Called deferral.Complete()");
                            }
                        };
                        dataTransferManagerHelper.ShowShareUi();
                        Log.Debug().WriteLine("ShowShareUi finished.");
                        await shareInfo.ShareTask.Task.ConfigureAwait(false);
                    }
        }
Esempio n. 21
0
        /// <summary>
        /// Share the screenshot with a windows app
        /// </summary>
        /// <param name="manuallyInitiated"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>ExportInformation</returns>
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);

            try
            {
                var handle = PluginUtils.Host.GreenshotForm.Handle;

                var exportTarget = Task.Run(async() =>
                {
                    var taskCompletionSource = new TaskCompletionSource <string>();

                    using (var imageStream = new MemoryRandomAccessStream())
                        using (var logoStream = new MemoryRandomAccessStream())
                            using (var thumbnailStream = new MemoryRandomAccessStream())
                            {
                                var outputSettings = new SurfaceOutputSettings();
                                outputSettings.PreventGreenshotFormat();

                                // Create capture for export
                                ImageOutput.SaveToStream(surface, imageStream, outputSettings);
                                imageStream.Position = 0;
                                Log.Info("Created RandomAccessStreamReference for the image");
                                var imageRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(imageStream);
                                RandomAccessStreamReference thumbnailRandomAccessStreamReference;
                                RandomAccessStreamReference logoRandomAccessStreamReference;

                                // Create thumbnail
                                using (var tmpImageForThumbnail = surface.GetImageForExport())
                                {
                                    using (var thumbnail = ImageHelper.CreateThumbnail(tmpImageForThumbnail, 240, 160))
                                    {
                                        ImageOutput.SaveToStream(thumbnail, null, thumbnailStream, outputSettings);
                                        thumbnailStream.Position             = 0;
                                        thumbnailRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(thumbnailStream);
                                        Log.Info("Created RandomAccessStreamReference for the thumbnail");
                                    }
                                }
                                // Create logo
                                using (var logo = GreenshotResources.getGreenshotIcon().ToBitmap())
                                {
                                    using (var logoThumbnail = ImageHelper.CreateThumbnail(logo, 30, 30))
                                    {
                                        ImageOutput.SaveToStream(logoThumbnail, null, logoStream, outputSettings);
                                        logoStream.Position             = 0;
                                        logoRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(logoStream);
                                        Log.Info("Created RandomAccessStreamReference for the logo");
                                    }
                                }
                                string applicationName        = null;
                                var dataTransferManagerHelper = new DataTransferManagerHelper(handle);
                                dataTransferManagerHelper.DataTransferManager.TargetApplicationChosen += (dtm, args) =>
                                {
                                    Log.InfoFormat("Trying to share with {0}", args.ApplicationName);
                                    applicationName = args.ApplicationName;
                                };
                                var filename    = FilenameHelper.GetFilename(OutputFormat.png, captureDetails);
                                var storageFile = await StorageFile.CreateStreamedFileAsync(filename, async streamedFileDataRequest =>
                                {
                                    // Information on how was found here: https://socialeboladev.wordpress.com/2013/03/15/how-to-use-createstreamedfileasync/
                                    Log.DebugFormat("Creating deferred file {0}", filename);
                                    try
                                    {
                                        using (var deferredStream = streamedFileDataRequest.AsStreamForWrite())
                                        {
                                            await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
                                            await imageStream.FlushAsync().ConfigureAwait(false);
                                        }
                                        // Signal that the stream is ready
                                        streamedFileDataRequest.Dispose();
                                    }
                                    catch (Exception)
                                    {
                                        streamedFileDataRequest.FailAndClose(StreamedFileFailureMode.Incomplete);
                                    }
                                    // Signal transfer ready to the await down below
                                    taskCompletionSource.TrySetResult(applicationName);
                                }, imageRandomAccessStreamReference).AsTask().ConfigureAwait(false);

                                dataTransferManagerHelper.DataTransferManager.DataRequested += (sender, args) =>
                                {
                                    var deferral = args.Request.GetDeferral();
                                    args.Request.Data.OperationCompleted += (dp, eventArgs) =>
                                    {
                                        Log.DebugFormat("OperationCompleted: {0}, shared with", eventArgs.Operation);
                                        taskCompletionSource.TrySetResult(applicationName);
                                    };
                                    var dataPackage = args.Request.Data;
                                    dataPackage.Properties.Title               = captureDetails.Title;
                                    dataPackage.Properties.ApplicationName     = "Greenshot";
                                    dataPackage.Properties.Description         = "Share a screenshot";
                                    dataPackage.Properties.Thumbnail           = thumbnailRandomAccessStreamReference;
                                    dataPackage.Properties.Square30x30Logo     = logoRandomAccessStreamReference;
                                    dataPackage.Properties.LogoBackgroundColor = Color.FromArgb(0xff, 0x3d, 0x3d, 0x3d);
                                    dataPackage.SetStorageItems(new List <IStorageItem> {
                                        storageFile
                                    });
                                    dataPackage.SetBitmap(imageRandomAccessStreamReference);
                                    dataPackage.Destroyed += (dp, o) =>
                                    {
                                        Log.Debug("Destroyed.");
                                    };
                                    deferral.Complete();
                                };
                                dataTransferManagerHelper.ShowShareUi();
                                return(await taskCompletionSource.Task.ConfigureAwait(false));
                            }
                }).Result;
                if (string.IsNullOrWhiteSpace(exportTarget))
                {
                    exportInformation.ExportMade = false;
                }
                else
                {
                    exportInformation.ExportMade             = true;
                    exportInformation.DestinationDescription = exportTarget;
                }
            }
            catch (Exception ex)
            {
                exportInformation.ExportMade   = false;
                exportInformation.ErrorMessage = ex.Message;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Esempio n. 22
0
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                SurfaceOutputSettings outputSettings = new SurfaceOutputSettings
                {
                    Format     = config.UploadFormat,
                    JPGQuality = config.UploadJpegQuality
                };
                ImageOutput.SaveToStream(image, null, stream, outputSettings);
                byte[] buffer = stream.GetBuffer();


                try
                {
                    string  filename    = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    string  contentType = $"image/{config.UploadFormat}";
                    TFSInfo tfsInfo     = TFSUtils.UploadToTFS(buffer, captureDetails.DateTime.ToString(CultureInfo.CurrentCulture), filename, contentType);
                    if (tfsInfo == null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (config.TfsUploadHistory == null)
                        {
                            config.TfsUploadHistory = new Dictionary <string, string>();
                        }

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

                            config.TfsUploadHistory.Add(tfsInfo.ID, tfsInfo.ID);
                            config.runtimeTfsHistory.Add(tfsInfo.ID, tfsInfo);
                        }

                        // 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
                        TFSUtils.LoadHistory();

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

                        if (config.AfterUploadLinkToClipBoard && !string.IsNullOrEmpty(tfsInfo.WebEditUrl))
                        {
                            Clipboard.SetText(tfsInfo.WebEditUrl);
                        }
                        if (config.AfterUploadOpenWorkItem && !string.IsNullOrEmpty(tfsInfo.WebEditUrl))
                        {
                            System.Diagnostics.Process.Start(tfsInfo.WebEditUrl);
                        }
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(Language.GetString("tfs", $"{LangKey.upload_failure} {e}"));
                }
                finally
                {
                    //backgroundForm.CloseDialog();
                }
            }
            return(false);
        }
Esempio n. 23
0
        /// <summary>
        ///     Do the actual upload to Box
        ///     For more details on the available parameters, see:
        ///     http://developers.box.net/w/page/12923951/ApiFunction_Upload%20and%20Download
        /// </summary>
        /// <param name="surface">ICapture</param>
        /// <param name="progress">IProgress</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>url to uploaded image</returns>
        public async Task <string> UploadToBoxAsync(ICaptureDetails captureDetails, ISurface surface, IProgress <int> progress = null, CancellationToken cancellationToken = default)
        {
            string filename       = Path.GetFileName(FilenameHelper.GetFilename(_boxConfiguration.UploadFormat, captureDetails));
            var    outputSettings = new SurfaceOutputSettings(_boxConfiguration.UploadFormat, _boxConfiguration.UploadJpegQuality, false);

            var oauthHttpBehaviour = HttpBehaviour.Current.ShallowClone();

            // Use UploadProgress
            if (progress != null)
            {
                oauthHttpBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100))); };
            }

            oauthHttpBehaviour.OnHttpMessageHandlerCreated = httpMessageHandler => new OAuth2HttpMessageHandler(_oauth2Settings, oauthHttpBehaviour, httpMessageHandler);

            // TODO: See if the PostAsync<Bitmap> can be used? Or at least the HttpContentFactory?
            using (var imageStream = new MemoryStream())
            {
                var multiPartContent = new MultipartFormDataContent();
                var parentIdContent  = new StringContent(_boxConfiguration.FolderId);
                parentIdContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "\"parent_id\""
                };
                multiPartContent.Add(parentIdContent);
                ImageOutput.SaveToStream(surface, imageStream, outputSettings);
                imageStream.Position = 0;

                BoxFile response;
                using (var streamContent = new StreamContent(imageStream))
                {
                    streamContent.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream"); //"image/" + outputSettings.Format);
                    streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                    {
                        Name     = "\"file\"",
                        FileName = "\"" + filename + "\""
                    }; // the extra quotes are important here
                    multiPartContent.Add(streamContent);

                    oauthHttpBehaviour.MakeCurrent();
                    response = await UploadFileUri.PostAsync <BoxFile>(multiPartContent, cancellationToken);
                }

                if (response == null)
                {
                    return(null);
                }

                if (_boxConfiguration.UseSharedLink)
                {
                    if (response.SharedLink?.Url == null)
                    {
                        var uriForSharedLink = FilesUri.AppendSegments(response.Id);
                        var updateAccess     = new
                        {
                            shared_link = new
                            {
                                access = "open"
                            }
                        };
                        oauthHttpBehaviour.MakeCurrent();
                        response = await uriForSharedLink.PostAsync <BoxFile>(updateAccess, cancellationToken);
                    }

                    return(response.SharedLink.Url);
                }
                return($"http://www.box.com/files/0/f/0/1/f_{response.Id}");
            }
        }