Esempio n. 1
0
 /// <summary>
 ///     Export the capture to the specified page
 /// </summary>
 /// <param name="oneNoteApplication">IOneNoteApplication</param>
 /// <param name="surfaceToUpload">ISurface</param>
 /// <param name="page">OneNotePage</param>
 /// <returns>bool true if everything worked</returns>
 private static bool ExportToPage(IOneNoteApplication oneNoteApplication, ISurface surfaceToUpload, OneNotePage page)
 {
     if (oneNoteApplication == null)
     {
         return(false);
     }
     using (var pngStream = new MemoryStream())
     {
         var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
         ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
         var base64String   = Convert.ToBase64String(pngStream.GetBuffer());
         var imageXmlStr    = string.Format(XmlImageContent, base64String, surfaceToUpload.Screenshot.Width, surfaceToUpload.Screenshot.Height);
         var pageChangesXml = string.Format(XmlOutline, imageXmlStr, page.ID, OnenoteNamespace2010, page.Name);
         Log.Info().WriteLine("Sending XML: {0}", pageChangesXml);
         oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
         try
         {
             oneNoteApplication.NavigateTo(page.ID, null, false);
         }
         catch (Exception ex)
         {
             Log.Warn().WriteLine(ex, "Unable to navigate to the target page");
         }
         return(true);
     }
 }
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 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. 4
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            bool   outputMade;
            bool   overwrite;
            string fullPath;
            // Get output settings from the configuration
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings();

            if (captureDetails != null && captureDetails.Filename != null)
            {
                // As we save a pre-selected file, allow to overwrite.
                overwrite = true;
                LOG.InfoFormat("Using previous filename");
                fullPath = captureDetails.Filename;
                outputSettings.Format = ImageOutput.FormatForFilename(fullPath);
            }
            else
            {
                fullPath = CreateNewFilename(captureDetails);
                // As we generate a file, the configuration tells us if we allow to overwrite
                overwrite = conf.OutputFileAllowOverwrite;
            }
            if (conf.OutputFilePromptQuality)
            {
                QualityDialog qualityDialog = new QualityDialog(outputSettings);
                qualityDialog.ShowDialog();
            }

            // Catching any exception to prevent that the user can't write in the directory.
            // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642
            try {
                ImageOutput.Save(surface, fullPath, overwrite, outputSettings, conf.OutputFileCopyPathToClipboard);
                outputMade = true;
            } catch (ArgumentException ex1) {
                // Our generated filename exists, display 'save-as'
                LOG.InfoFormat("Not overwriting: {0}", ex1.Message);
                // when we don't allow to overwrite present a new SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = (fullPath != null);
            } catch (Exception ex2) {
                LOG.Error("Error saving screenshot!", ex2);
                // Show the problem
                MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                // when save failed we present a SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = (fullPath != null);
            }
            // Don't overwrite filename if no output is made
            if (outputMade)
            {
                exportInformation.ExportMade = outputMade;
                exportInformation.Filepath   = fullPath;
                captureDetails.Filename      = fullPath;
                conf.OutputFileAsFullpath    = fullPath;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        /// <summary>
        /// Save with showing a dialog
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>Path to filename</returns>
        public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
        {
            string returnValue = null;

            using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
            {
                DialogResult dialogResult = saveImageFileDialog.ShowDialog();
                if (dialogResult.Equals(DialogResult.OK))
                {
                    try
                    {
                        string fileNameWithExtension         = saveImageFileDialog.FileNameWithExtension;
                        SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                        if (conf.OutputFilePromptQuality)
                        {
                            QualityDialog qualityDialog = new QualityDialog(outputSettings);
                            qualityDialog.ShowDialog();
                        }
                        // TODO: For now we always overwrite, should be changed
                        Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                        returnValue = fileNameWithExtension;
                        IniConfig.Save();
                    }
                    catch (ExternalException)
                    {
                        MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
                    }
                }
            }
            return(returnValue);
        }
Esempio n. 6
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. 7
0
        /// <summary>
        /// Upload the capture to imgur
        /// </summary>
        /// <param name="captureDetails">ICaptureDetails</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, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, _config.UploadReduceColors);

            try {
                string    filename  = Path.GetFileName(FilenameHelper.GetFilenameFromPattern(_config.FilenamePattern, _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);
                    if (imgurInfo != null && _config.AnonymousAccess)
                    {
                        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();
                    }
                }
                                                 );

                if (imgurInfo != null)
                {
                    // TODO: Optimize a second call for export
                    using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
                        imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
                    }
                    IniConfig.Save();

                    if (_config.UsePageLink)
                    {
                        uploadUrl = imgurInfo.Page;
                    }
                    else
                    {
                        uploadUrl = imgurInfo.Original;
                    }
                    if (!string.IsNullOrEmpty(uploadUrl) && _config.CopyLinkToClipboard)
                    {
                        try
                        {
                            ClipboardHelper.SetClipboardData(uploadUrl);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Can't write to clipboard: ", ex);
                            uploadUrl = null;
                        }
                    }
                    return(true);
                }
            } catch (Exception e) {
                Log.Error("Error uploading.", e);
                MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
        /// <summary>
        /// Helper method to create a temp image file
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static string SaveToTmpFile(ISurface surface, SurfaceOutputSettings outputSettings, string destinationPath)
        {
            string tmpFile = Path.GetRandomFileName() + "." + outputSettings.Format.ToString();

            // Prevent problems with "other characters", which could cause problems
            tmpFile = Regex.Replace(tmpFile, @"[^\d\w\.]", "");
            if (destinationPath == null)
            {
                destinationPath = Path.GetTempPath();
            }
            string tmpPath = Path.Combine(destinationPath, tmpFile);

            LOG.Debug("Creating TMP File : " + tmpPath);

            try
            {
                Save(surface, tmpPath, true, outputSettings, false);
                tmpFileCache.Add(tmpPath, tmpPath);
            }
            catch (Exception)
            {
                return(null);
            }
            return(tmpPath);
        }
Esempio n. 9
0
        /// <summary>
        ///     Do the actual upload to OneDrive
        /// </summary>
        /// <param name="oAuth2Settings">OAuth2Settings</param>
        /// <param name="surfaceToUpload">ISurface to upload</param>
        /// <param name="outputSettings">OutputSettings for the image file format</param>
        /// <param name="title">Title</param>
        /// <param name="filename">Filename</param>
        /// <param name="progress">IProgress</param>
        /// <param name="token">CancellationToken</param>
        /// <returns>ImgurInfo with details</returns>
        public static async Task <OneDriveUploadResponse> UploadToOneDriveAsync(OAuth2Settings oAuth2Settings, ISurface surfaceToUpload,
                                                                                SurfaceOutputSettings outputSettings, string title, string filename, IProgress <int> progress = null,
                                                                                CancellationToken token = default)
        {
            var uploadUri      = new Uri(UrlUtils.GetUploadUrl(filename));
            var localBehaviour = Behaviour.ShallowClone();

            if (progress != null)
            {
                localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); };
            }
            var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);

            using (var imageStream = new MemoryStream())
            {
                ImageOutput.SaveToStream(surfaceToUpload, imageStream, outputSettings);
                imageStream.Position = 0;
                using (var content = new StreamContent(imageStream))
                {
                    content.Headers.Add("Content-Type", "image/" + outputSettings.Format);
                    oauthHttpBehaviour.MakeCurrent();
                    return(await uploadUri.PostAsync <OneDriveUploadResponse>(content, token));
                }
            }
        }
Esempio n. 10
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. 11
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. 12
0
        /// <summary>
        /// Save with showing a dialog
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>Path to filename</returns>
        public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
        {
            string returnValue = null;

            using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
            {
                DialogResult dialogResult = saveImageFileDialog.ShowDialog();
                if (dialogResult.Equals(DialogResult.OK))
                {
                    try
                    {
                        string fileNameWithExtension         = saveImageFileDialog.FileNameWithExtension;
                        SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                        if (conf.OutputFilePromptQuality)
                        {
                            QualityDialog qualityDialog = new QualityDialog(outputSettings);
                            qualityDialog.ShowDialog();
                        }
                        // For now we always overwrite, should be changed
                        Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                        returnValue = fileNameWithExtension;
                        IniConfig.Save();
                    }
                    catch (ExternalException)
                    {
                        MessageBox.Show(string.Format("Cannot save file to {0}.\r\nPlease check write accessibility of the selected storage location.",
                                                      saveImageFileDialog.FileName).Replace(@"\\", @"\"), "Error");
                    }
                }
            }
            return(returnValue);
        }
Esempio n. 13
0
        /// <summary>
        /// Do the actual upload to Lutim
        /// For more details on the available parameters, see: http://api.lutim.com/resources_anon
        /// </summary>
        /// <param name="surfaceToUpload">ISurface to upload</param>
        /// <param name="outputSettings">OutputSettings for the image file format</param>
        /// <param name="filename">Filename</param>
        /// <returns>LutimInfo with details</returns>
        public static async Task <LutimInfo> UploadToLutim(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string filename)
        {
            var baseUrl = new Uri(Config.LutimUrl);

            // TODO: Upload
            var result = await baseUrl.PostAsync <AddResult>("");

            return(result.LutimInfo);
        }
Esempio n. 14
0
        /// <summary>
        /// Place the bitmap as HTML on the clipboard
        /// </summary>
        /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
        /// <param name="surface">ISurface</param>
        public static void SetAsHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
        {
            var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
            // This file is automatically deleted when Greenshot exits.
            var filename = ImageOutput.SaveNamedTmpFile(surface, surface.CaptureDetails, pngOutputSettings);
            // Set the PNG stream
            var htmlText = GenerateHtmlString(new NativeSize(surface.Width, surface.Height), filename);

            clipboardAccessToken.SetAsHtml(htmlText);
        }
Esempio n. 15
0
        /// <summary>
        ///     Saves ISurface to stream with specified output settings
        /// </summary>
        /// <param name="surface">ISurface to save</param>
        /// <param name="stream">Stream to save to</param>
        /// <param name="outputSettings">SurfaceOutputSettings</param>
        public static void SaveToStream(ISurface surface, Stream stream, SurfaceOutputSettings outputSettings)
        {
            var disposeImage = CreateBitmapFromSurface(surface, outputSettings, out var bitmapToSave);

            SaveToStream(bitmapToSave, surface, stream, outputSettings);
            // cleanup if needed
            if (disposeImage)
            {
                bitmapToSave?.Dispose();
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Place the bitmap as embedded HTML on the clipboard
 /// </summary>
 /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
 /// <param name="surface">ISurface</param>
 public static void SetAsEmbeddedHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
 {
     using (var pngStream = new MemoryStream())
     {
         var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
         ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
         pngStream.Seek(0, SeekOrigin.Begin);
         // Set the PNG stream
         var htmlText = GenerateHtmlDataUrlString(new NativeSize(surface.Width, surface.Height), pngStream);
         clipboardAccessToken.SetAsHtml(htmlText);
     }
 }
        /// <summary>
        /// Saves ISurface to stream with specified output settings
        /// </summary>
        /// <param name="surface">ISurface to save</param>
        /// <param name="stream">Stream to save to</param>
        /// <param name="outputSettings">SurfaceOutputSettings</param>
        public static void SaveToStream(ISurface surface, Stream stream, SurfaceOutputSettings outputSettings)
        {
            Image imageToSave  = null;
            bool  disposeImage = CreateImageFromSurface(surface, outputSettings, out imageToSave);

            SaveToStream(imageToSave, surface, stream, outputSettings);
            // cleanup if needed
            if (disposeImage && imageToSave != null)
            {
                imageToSave.Dispose();
            }
        }
Esempio n. 18
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. 20
0
        private bool Upload(ISurface surfaceToUpload, Content page, string filename, out string errorMessage)
        {
            var outputSettings = new SurfaceOutputSettings(_confluenceConfiguration.UploadFormat, _confluenceConfiguration.UploadJpegQuality, _confluenceConfiguration.UploadReduceColors);

            errorMessage = null;
            try
            {
                // TODO: Create content
                using (var ownedPleaseWaitForm = _pleaseWaitFormFactory())
                {
                    ownedPleaseWaitForm.Value.ShowAndWait(Description, _confluenceLanguage.CommunicationWait,
                                                          () => _confluenceClient.Attachment.AttachAsync(page.Id, surfaceToUpload, filename, null,
                                                                                                         "image/" + _confluenceConfiguration.UploadFormat.ToString().ToLower()));
                }
                Log.Debug().WriteLine("Uploaded to Confluence.");
                if (!_confluenceConfiguration.CopyWikiMarkupForImageToClipboard)
                {
                    return(true);
                }
                var retryCount = 2;
                while (retryCount >= 0)
                {
                    try
                    {
                        Clipboard.SetText("!" + filename + "!");
                        break;
                    }
                    catch (Exception ee)
                    {
                        if (retryCount == 0)
                        {
                            Log.Error().WriteLine(ee);
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    finally
                    {
                        --retryCount;
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }
            return(false);
        }
Esempio n. 21
0
 public static void ExportToPage(ISurface surfaceToUpload, OneNotePage page)
 {
     using (MemoryStream pngStream = new MemoryStream()) {
         SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
         ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
         string base64String   = Convert.ToBase64String(pngStream.GetBuffer());
         string imageXmlStr    = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height);
         string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName });
         using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) {
             LOG.InfoFormat("Sending XML: {0}", pageChangesXml);
             oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
         }
     }
 }
Esempio n. 22
0
        public static string UploadToDropbox(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string filename)
        {
            var oAuth = new OAuthSession(DropBoxCredentials.CONSUMER_KEY, DropBoxCredentials.CONSUMER_SECRET)
            {
                BrowserSize     = new Size(1080, 650),
                CheckVerifier   = false,
                AccessTokenUrl  = "https://api.dropbox.com/1/oauth/access_token",
                AuthorizeUrl    = "https://api.dropbox.com/1/oauth/authorize",
                RequestTokenUrl = "https://api.dropbox.com/1/oauth/request_token",
                LoginTitle      = "Dropbox authorization",
                Token           = DropboxConfig.DropboxToken,
                TokenSecret     = DropboxConfig.DropboxTokenSecret
            };

            try {
                SurfaceContainer imageToUpload  = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
                string           uploadResponse = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://api-content.dropbox.com/1/files_put/sandbox/" + OAuthSession.UrlEncode3986(filename), null, null, imageToUpload);
                Log.DebugFormat("Upload response: {0}", uploadResponse);
            } catch (Exception ex) {
                Log.Error("Upload error: ", ex);
                throw;
            } finally {
                if (!string.IsNullOrEmpty(oAuth.Token))
                {
                    DropboxConfig.DropboxToken = oAuth.Token;
                }
                if (!string.IsNullOrEmpty(oAuth.TokenSecret))
                {
                    DropboxConfig.DropboxTokenSecret = oAuth.TokenSecret;
                }
            }

            // Try to get a URL to the uploaded image
            try {
                string responseString = oAuth.MakeOAuthRequest(HTTPMethod.GET, "https://api.dropbox.com/1/shares/sandbox/" + OAuthSession.UrlEncode3986(filename), null, null, null);
                if (responseString != null)
                {
                    Log.DebugFormat("Parsing output: {0}", responseString);
                    IDictionary <string, object> returnValues = JSONHelper.JsonDecode(responseString);
                    if (returnValues.ContainsKey("url"))
                    {
                        return(returnValues["url"] as string);
                    }
                }
            } catch (Exception ex) {
                Log.Error("Can't parse response.", ex);
            }
            return(null);
        }
Esempio n. 23
0
        public QualityDialog(SurfaceOutputSettings outputSettings)
        {
            Settings = outputSettings;
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            Icon = GreenshotResources.getGreenshotIcon();

            checkBox_reduceColors.Checked = Settings.ReduceColors;
            trackBarJpegQuality.Enabled   = OutputFormat.jpg.Equals(outputSettings.Format);
            trackBarJpegQuality.Value     = Settings.JPGQuality;
            textBoxJpegQuality.Enabled    = OutputFormat.jpg.Equals(outputSettings.Format);
            textBoxJpegQuality.Text       = Settings.JPGQuality.ToString();
        }
Esempio n. 24
0
        private bool Upload(ISurface surfaceToUpload, Page page, string filename, out string errorMessage)
        {
            var outputSettings = new SurfaceOutputSettings(_confluenceConfiguration.UploadFormat, _confluenceConfiguration.UploadJpegQuality, _confluenceConfiguration.UploadReduceColors);

            errorMessage = null;
            try
            {
                new PleaseWaitForm().ShowAndWait(Description, Language.GetString("confluence", LangKey.communication_wait),
                                                 () => _confluenceConnector.AddAttachment(page.Id, "image/" + _confluenceConfiguration.UploadFormat.ToString().ToLower(), null, filename,
                                                                                          new SurfaceContainer(surfaceToUpload, outputSettings, filename))
                                                 );
                Log.Debug().WriteLine("Uploaded to Confluence.");
                if (!_confluenceConfiguration.CopyWikiMarkupForImageToClipboard)
                {
                    return(true);
                }
                var retryCount = 2;
                while (retryCount >= 0)
                {
                    try
                    {
                        Clipboard.SetText("!" + filename + "!");
                        break;
                    }
                    catch (Exception ee)
                    {
                        if (retryCount == 0)
                        {
                            Log.Error().WriteLine(ee);
                        }
                        else
                        {
                            Thread.Sleep(100);
                        }
                    }
                    finally
                    {
                        --retryCount;
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }
            return(false);
        }
Esempio n. 25
0
        /// <summary>
        /// Do the actual upload to Picasa
        /// </summary>
        /// <param name="surfaceToUpload">Image to upload</param>
        /// <param name="outputSettings"></param>
        /// <param name="title"></param>
        /// <param name="filename"></param>
        /// <returns>PicasaResponse</returns>
        public static string UploadToPicasa(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string title, string filename)
        {
            OAuthSession oAuth = new OAuthSession(PicasaCredentials.ConsumerKey, PicasaCredentials.ConsumerSecret);

            oAuth.BrowserSize     = new Size(1020, 590);
            oAuth.AccessTokenUrl  = GoogleAccountUri + "OAuthGetAccessToken";
            oAuth.AuthorizeUrl    = GoogleAccountUri + "OAuthAuthorizeToken";
            oAuth.RequestTokenUrl = GoogleAccountUri + "OAuthGetRequestToken";
            oAuth.LoginTitle      = "Picasa authorization";
            oAuth.Token           = Config.PicasaToken;
            oAuth.TokenSecret     = Config.PicasaTokenSecret;
            oAuth.RequestTokenParameters.Add("scope", "https://picasaweb.google.com/data/");
            oAuth.RequestTokenParameters.Add("xoauth_displayname", "Greenshot");
            if (string.IsNullOrEmpty(oAuth.Token))
            {
                if (!oAuth.Authorize())
                {
                    return(null);
                }
                if (!string.IsNullOrEmpty(oAuth.Token))
                {
                    Config.PicasaToken = oAuth.Token;
                }
                if (!string.IsNullOrEmpty(oAuth.TokenSecret))
                {
                    Config.PicasaTokenSecret = oAuth.TokenSecret;
                }
                IniConfig.Save();
            }
            try {
                IDictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("slug", OAuthSession.UrlEncode3986(filename));
                string response = oAuth.MakeOAuthRequest(HTTPMethod.POST, "https://picasaweb.google.com/data/feed/api/user/default/albumid/default", headers, null, null, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                return(ParseResponse(response));
            } catch (Exception ex) {
                LOG.Error("Upload error: ", ex);
                throw;
            } finally {
                if (!string.IsNullOrEmpty(oAuth.Token))
                {
                    Config.PicasaToken = oAuth.Token;
                }
                if (!string.IsNullOrEmpty(oAuth.TokenSecret))
                {
                    Config.PicasaTokenSecret = oAuth.TokenSecret;
                }
            }
        }
        /// <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. 27
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();


            if (presetCommand != null)
            {
                bool   runInBackground = presetCommand.RunInBackground;
                string fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                string output = null;
                if (runInBackground)
                {
                    Thread commandThread = new Thread(delegate() {
                        CallExternalCommand(presetCommand, fullPath, out output);
                    });
                    commandThread.Name         = "Running " + presetCommand;
                    commandThread.IsBackground = true;
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    try {
                        if (CallExternalCommand(presetCommand, fullPath, out output) == 0)
                        {
                            exportInformation.ExportMade = true;
                        }
                        else
                        {
                            exportInformation.ErrorMessage = output;
                        }
                    } catch (Exception ex) {
                        exportInformation.ErrorMessage = ex.Message;
                    }
                }

                //exportInformation.Uri = "file://" + fullPath;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Esempio n. 28
0
        /// <summary>
        /// Upload the capture to OneDrive
        /// </summary>
        /// <param name="captureDetails">ICaptureDetails</param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <returns>Uri</returns>
        private async Task <Uri> Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload)
        {
            var outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality,
                                                           _config.UploadReduceColors);

            try
            {
                string filename = Path.GetFileName(FilenameHelper.GetFilenameFromPattern(_config.FilenamePattern,
                                                                                         _config.UploadFormat, captureDetails));
                Uri response = null;

                var cancellationTokenSource = new CancellationTokenSource();
                using (var pleaseWaitForm = new PleaseWaitForm("OneDrive plug-in", _oneDriveLanguage.CommunicationWait,
                                                               cancellationTokenSource))
                {
                    pleaseWaitForm.Show();
                    try
                    {
                        var oneDriveResponse = await OneDriveUtils.UploadToOneDriveAsync(_oauth2Settings, surfaceToUpload,
                                                                                         outputSettings, captureDetails.Title, filename, null, cancellationTokenSource.Token);

                        response = new Uri(oneDriveResponse.WebUrl);
                    }
                    finally
                    {
                        pleaseWaitForm.Close();
                    }
                }

                if (response != null)
                {
                    if (_config.AfterUploadLinkToClipBoard)
                    {
                        ClipboardHelper.SetClipboardData(response.ToString());
                    }

                    return(response);
                }
            }
            catch (Exception e)
            {
                Log.Error().WriteLine(e, "Error uploading.");
                MessageBox.Show(_oneDriveLanguage.UploadFailure + " " + e.Message);
            }

            return(null);
        }
Esempio n. 29
0
        private void ApplyEffects(SurfaceOutputSettings printOutputSettings)
        {
            // TODO:
            // add effects here
            if (_coreConfig.OutputPrintMonochrome)
            {
                var threshold = _coreConfig.OutputPrintMonochromeThreshold;
                printOutputSettings.Effects.Add(new MonochromeEffect(threshold));
                printOutputSettings.ReduceColors = true;
            }

            // the invert effect should probably be the last
            if (_coreConfig.OutputPrintInverted)
            {
                printOutputSettings.Effects.Add(new InvertEffect());
            }
        }
Esempio n. 30
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);
        }