/// <summary>Get Image with Watermark</summary>
 public Image ApplyWatermark(Image img, NameParser parser, WatermarkType watermarkType)
 {
     switch (watermarkType)
     {
         default:
         case WatermarkType.NONE:
             return img;
         case WatermarkType.TEXT:
             return DrawWatermark(img, parser.Convert(Config.WatermarkText));
         case WatermarkType.IMAGE:
             return DrawImageWatermark(img, Config.WatermarkImageLocation);
     }
 }
        public static string PrepareFilename(Workflow workflow, Image img, EImageFormat imageFormat, NameParser parser)
        {
            string ext = "png";

            switch (imageFormat)
            {
                case EImageFormat.PNG:
                    ext = "png";
                    break;
                case EImageFormat.JPEG:
                    ext = "jpg";
                    break;
                case EImageFormat.GIF:
                    ext = "gif";
                    break;
                case EImageFormat.BMP:
                    ext = "bmp";
                    break;
                case EImageFormat.TIFF:
                    ext = "tif";
                    break;
            }

            string pattern = workflow.ConfigFileNaming.EntireScreenPattern;
            switch (parser.Type)
            {
                case NameParserType.ActiveWindow:
                    pattern = workflow.ConfigFileNaming.ActiveWindowPattern;
                    break;
                default:
                    pattern = workflow.ConfigFileNaming.EntireScreenPattern;
                    break;
            }
            string fn = parser.Convert(pattern);
            if (Engine.ConfigWorkflow != null)
            {
                Engine.ConfigWorkflow.ConfigFileNaming.AutoIncrement = parser.AutoIncrementNumber; // issue 577; Engine.Workflow.AutoIncrement has to be updated
            }

            string fileName = string.Format("{0}.{1}", fn, ext);

            return FileSystem.GetUniqueFileName(workflow, fileName);
        }
Пример #3
0
        private static string PrepareFilename(EImageFormat imageFormat, Image img)
        {
            string ext = "png";

            switch (imageFormat)
            {
                case EImageFormat.PNG:
                    ext = "png";
                    break;
                case EImageFormat.JPEG:
                    ext = "jpg";
                    break;
                case EImageFormat.GIF:
                    ext = "gif";
                    break;
                case EImageFormat.BMP:
                    ext = "bmp";
                    break;
                case EImageFormat.TIFF:
                    ext = "tif";
                    break;
            }

            NameParser parser = new NameParser { Picture = img };

            return string.Format("{0}.{1}", parser.Convert(Program.Settings.NameFormatPattern), ext);
        }
 public string GetSubFolderPath()
 {
     NameParser parser = new NameParser { Host = this.LocalhostRoot, IsFolderPath = true };
     return parser.Convert(this.SubFolderPath);
 }
 public string GetHttpHomePath()
 {
     NameParser parser = new NameParser { Host = this.LocalhostRoot, IsFolderPath = true };
     HttpHomePath = parser.RemovePrefixes(HttpHomePath);
     return parser.Convert(HttpHomePath);
 }
        /// <summary>
        /// Sets Clipboard text and returns the content
        /// </summary>
        /// <returns></returns>
        public static void ShowUploadResults(WorkerTask task, bool showDialog)
        {
            if (!task.WorkflowConfig.ClipboardOverwrite && !Clipboard.ContainsFileDropList() && !Clipboard.ContainsImage() && !Clipboard.ContainsText() || task.WorkflowConfig.ClipboardOverwrite)
            {
                if (task.UploadResults.Count > 0)
                {
                    if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Count > 1 || Engine.ConfigUI.ShowUploadResultsWindow || showDialog)
                    {
                        ClipboardOptions cmp = new ClipboardOptions(task);
                        cmp.Icon = Resources.zss_main;
                        if (showDialog) { cmp.ShowDialog(); }
                        else { NativeMethods.ShowWindow(cmp.Handle, (int)WindowShowStyle.ShowNoActivate); }
                        showDialog = true;
                    }
                }

                if (task.WorkflowConfig.DestConfig.Outputs.Contains(OutputEnum.Clipboard))
                {
                    StringBuilder clipboardText = new StringBuilder();

                    if (task.JobIsImageToClipboard())
                    {
                        Adapter.CopyImageToClipboard(task.TempImage, task.WorkflowConfig.ClipboardForceBmp);
                    }
                    else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local))
                    {
                        foreach (UploadResult ur in task.UploadResults)
                        {
                            if (Engine.ConfigUI.ConfLinkFormat.Count > 0)
                            {
                                clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.LocalFilePath));
                            }

                            if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                            {
                                break;
                            }
                        }
                    }
                    else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.OCR))
                    {
                        if (!string.IsNullOrEmpty(task.OCRText))
                        {
                            clipboardText.Append(task.OCRText);
                        }
                    }

                // If the user requests for the full image URL, preference is given for the Shortened URL is exists
                    else if (task.Job1 == EDataType.Image && task.WorkflowConfig.DestConfig.LinkFormat.Contains((int)LinkFormatEnum.FULL))
                    {
                        if (task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL))
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.ShortenedURL))
                                {
                                    clipboardText.AppendLine(ur.ShortenedURL);
                                    if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        // If no shortened URL exists then default full URL will be used
                        else
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.URL))
                                {
                                    clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(ur.URL));
                                    if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (clipboardText.Length == 0 && task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local))
                            {
                                foreach (UploadResult ur in task.UploadResults)
                                {
                                    if (!string.IsNullOrEmpty(ur.LocalFilePath))
                                    {
                                        clipboardText.AppendLine(ur.LocalFilePath);
                                        if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    else
                    {
                        // From this point onwards app needs to respect all other Clipboard URL modes for Images
                        if (task.UploadResults.Count > 0 && task.Job1 == EDataType.Image)
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (task.WorkflowConfig.DestConfig.LinkFormat.Count > 0)
                                {
                                    clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.URL));
                                }

                                if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0)
                                {
                                    break;
                                }
                            }
                        }
                        // Text and File catagories are still left to process. Exception for Google Translate
                        else if (task.Job1 == EDataType.Text && task.Job2 == WorkerTask.JobLevel2.Translate)
                        {
                            if (task.TranslationInfo != null)
                            {
                                clipboardText.AppendLine(task.TranslationInfo.Result);
                            }
                        }
                        // Text and File catagories are still left to process. If shortened URL exists, preference is given to that
                        else if (task.UploadResults.Count > 0 && task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL))
                        {
                            foreach (UploadResult ur in task.UploadResults)
                            {
                                if (!string.IsNullOrEmpty(ur.ShortenedURL))
                                {
                                    clipboardText.AppendLine(ur.ShortenedURL);
                                    break;
                                }
                            }
                        }
                        // Otherwise full URL for Text or File is used
                        else if (task.UploadResults.Count > 0)
                        {
                            clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(task.UploadResults[0].URL));
                        }
                    }

                    if (clipboardText.Length > 0)
                    {
                        bool bClipboardFormatOnLongUrl = Engine.ConfigUI.EnableClipboardFormatForLongURLs && task.Job1 == EDataType.URL;
                        bool bClipboardFormat = bClipboardFormatOnLongUrl || task.Job1 != EDataType.URL;
                        var np = new NameParser(NameParserType.Clipboard)
                                     {
                                         Link = clipboardText.ToString().Trim(),
                                         FileSize = task.Info.FileSize,
                                         FileName = task.Info.FileName
                                     };
                        if (bClipboardFormat)
                        {
                            np.WindowText = task.Info.WindowTitleText;
                        }

                        string tempText = bClipboardFormat ? np.Convert(Engine.ConfigUI.ClipboardFormat) : clipboardText.ToString().Trim();

                        if (!string.IsNullOrEmpty(tempText))
                        {
                            DebugHelper.WriteLine("Setting Clipboard with URL: " + tempText);
                            Clipboard.SetText(tempText); // auto
                            Engine.zPreviousSetClipboardText = tempText;
                            Engine.IsClipboardUploading = false;

                            // optional deletion link
                            if (task.UploadResults != null)
                            {
                                foreach (UploadResult ur in task.UploadResults)
                                {
                                    string linkdel = ur.DeletionURL;
                                    if (!string.IsNullOrEmpty(linkdel))
                                    {
                                        DebugHelper.WriteLine("Deletion Link: " + linkdel);
                                    }
                                }
                            }
                        }
                    }
                }

                if (!showDialog)
                {
                    task.Dispose();
                }
            }
        }
Пример #7
0
        public UploadResult UploadFile(Stream stream, string fileName)
        {
            FileUploader fileUploader = null;

            switch (UploadManager.FileUploader)
            {
                case FileDestination.Dropbox:
                    NameParser parser = new NameParser { IsFolderPath = true };
                    string uploadPath = parser.Convert(Dropbox.TidyUploadPath(Program.UploadersConfig.DropboxUploadPath));
                    fileUploader = new Dropbox(Program.UploadersConfig.DropboxOAuthInfo, uploadPath, Program.UploadersConfig.DropboxAccountInfo)
                    {
                        AutoCreateShareableLink = Program.UploadersConfig.DropboxAutoCreateShareableLink
                    };
                    break;
                case FileDestination.RapidShare:
                    fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword,
                        Program.UploadersConfig.RapidShareFolderID);
                    break;
                case FileDestination.SendSpace:
                    fileUploader = new SendSpace(ZKeys.SendSpaceKey);
                    switch (Program.UploadersConfig.SendSpaceAccountType)
                    {
                        case AccountType.Anonymous:
                            SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey);
                            break;
                        case AccountType.User:
                            SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey, Program.UploadersConfig.SendSpaceUsername, Program.UploadersConfig.SendSpacePassword);
                            break;
                    }
                    break;
                case FileDestination.Minus:
                    fileUploader = new Minus(Program.UploadersConfig.MinusConfig, new OAuthInfo(ZKeys.MinusConsumerKey, ZKeys.MinusConsumerSecret));
                    break;
                case FileDestination.Box:
                    fileUploader = new Box(ZKeys.BoxKey)
                    {
                        AuthToken = Program.UploadersConfig.BoxAuthToken,
                        FolderID = Program.UploadersConfig.BoxFolderID,
                        Share = Program.UploadersConfig.BoxShare
                    };
                    break;
                case FileDestination.CustomUploader:
                    if (Program.UploadersConfig.CustomUploadersList.HasValidIndex(Program.UploadersConfig.CustomUploaderSelected))
                    {
                        fileUploader = new CustomUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomUploaderSelected]);
                    }
                    break;
                case FileDestination.FTP:
                    int index = Program.UploadersConfig.GetFtpIndex(Info.DataType);

                    if (Program.UploadersConfig.FTPAccountList2.HasValidIndex(index))
                    {
                        fileUploader = new FTPUploader(Program.UploadersConfig.FTPAccountList2[index]);
                    }
                    break;
                case FileDestination.Email:
                    using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty,
                        Program.UploadersConfig.EmailDefaultSubject, Program.UploadersConfig.EmailDefaultBody))
                    {
                        if (emailForm.ShowDialog() == DialogResult.OK)
                        {
                            if (Program.UploadersConfig.EmailRememberLastTo)
                            {
                                Program.UploadersConfig.EmailLastTo = emailForm.ToEmail;
                            }

                            fileUploader = new Email
                            {
                                SmtpServer = Program.UploadersConfig.EmailSmtpServer,
                                SmtpPort = Program.UploadersConfig.EmailSmtpPort,
                                FromEmail =  Program.UploadersConfig.EmailFrom,
                                Password = Program.UploadersConfig.EmailPassword,
                                ToEmail = emailForm.ToEmail,
                                Subject = emailForm.Subject,
                                Body = emailForm.Body
                            };
                        }
                        else
                        {
                            IsStopped = true;
                        }
                    }
                    break;
            }

            if (fileUploader != null)
            {
                PrepareUploader(fileUploader);
                return fileUploader.Upload(stream, fileName);
            }

            return null;
        }
 private void txtActiveWindow_TextChanged(object sender, EventArgs e)
 {
     Config.ActiveWindowPattern = txtActiveWindow.Text;
     var parser = new NameParser(NameParserType.ActiveWindow)
                      {
                          CustomProductName = Application.ProductName,
                          IsPreview = true,
                          MaxNameLength = Config.MaxNameLength
                      };
     lblActiveWindowPreview.Text = parser.Convert(Config.ActiveWindowPattern);
 }
 private void txtEntireScreen_TextChanged(object sender, EventArgs e)
 {
     Config.EntireScreenPattern = txtEntireScreen.Text;
     var parser = new NameParser(NameParserType.EntireScreen)
                      {
                          CustomProductName = Application.ProductName,
                          IsPreview = true,
                          MaxNameLength = Config.MaxNameLength
                      };
     lblEntireScreenPreview.Text = parser.Convert(Config.EntireScreenPattern);
 }