Example #1
0
        /// <summary>
        ///     Create a workflow based on the job and settings objects provided. This will create an AutoSave workflow if the
        ///     job's printer has an AutoSave profile associated or the default profile uses AutoSave.
        ///     Otherwise, an interactive workflow will be created.
        ///     基于提供的作业和设置对象创建工作流。如果作业的打印机关联了自动保存配置文件或默认配置文件使用自动保存,
        ///     则此操作将创建自动保存工作流。否则,将创建交互式工作流。
        /// </summary>
        /// <param name="jobInfo">The jobinfo used for the decision</param>
        /// <param name="settings">The settings used for the decision</param>
        /// <returns>A ConversionWorkflow either for AutoSave or interactive use</returns>
        public static ConversionWorkflow CreateWorkflow(IJobInfo jobInfo, clawPDFSettings settings)
        {
            Logger.Trace("Creating Workflow");

            var preselectedProfile = PreselectedProfile(jobInfo, settings).Copy();

            Logger.Debug("Profile: {0} (GUID {1})", preselectedProfile.Name, preselectedProfile.Guid);

            var jobTranslations = new JobTranslations();

            jobTranslations.EmailSignature = MailSignatureHelper.ComposeMailSignature();

            var job = JobFactory.CreateJob(jobInfo, preselectedProfile, JobInfoQueue.Instance, jobTranslations);

            job.AutoCleanUp = true;


            if (preselectedProfile.AutoSave.Enabled)
            {
                Logger.Trace("Creating AutoSaveWorkflow");
                return(new AutoSaveWorkflow(job, settings));
            }

            Logger.Trace("Creating InteractiveWorkflow");
            return(new InteractiveWorkflow(job, settings));
        }
Example #2
0
        public EditEmailTextWindow(bool addSignature)
        {
            AddSignature = addSignature;

            InitializeComponent();

            TranslationHelper.Instance.TranslatorInstance.Translate(this);

            BodyTokenReplacerConverter.TokenReplacer   = TokenHelper.TokenReplacerWithPlaceHolders;
            HeaderTokenReplacerConverter.TokenReplacer = BodyTokenReplacerConverter.TokenReplacer;

            var tokens = TokenHelper.GetTokenListForEmail();

            SubjectTokenComboBox.ItemsSource = tokens;
            BodyTokenComboBox.ItemsSource    = tokens;

            _signatureText = MailSignatureHelper.ComposeMailSignature();
            AttachSignature_OnChecked(null, null);
        }
Example #3
0
        /// <summary>
        /// Creates the job from the queue by index
        /// </summary>
        /// <param name="id">Index of the jobinfo in the queue</param>
        /// <returns>The corresponding ComJob</returns>
        private PrintJob JobById(int id)
        {
            try
            {
                IJobInfo currentJobInfo = _comJobInfoQueue.JobInfos[id];

                var jobTranslations = new JobTranslations();
                jobTranslations.EmailSignature = MailSignatureHelper.ComposeMailSignature();

                IJob currentJob = new GhostscriptJob(currentJobInfo, SettingsHelper.GetDefaultProfile(), JobInfoQueue.Instance, jobTranslations);

                COMLogger.Trace("COM: Creating the ComJob from the queue determined by the index.");
                var indexedJob = new PrintJob(currentJob, _comJobInfoQueue);
                return(indexedJob);
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new COMException("Invalid index. Please check the index parameter.");
            }
        }
Example #4
0
        public void SendTestMail(ConversionProfile profile, Accounts accounts)
        {
            var currentProfile = profile.Copy();

            currentProfile.AutoSave.Enabled = false;

            var signatureHelper = new MailSignatureHelper(_translator);

            var actionResult = _smtpMailAction.Check(currentProfile, accounts);

            if (!actionResult.IsSuccess)
            {
                DisplayErrorMessage(actionResult);
                return;
            }

            var jobTranslations = new JobTranslations();

            jobTranslations.EmailSignature = signatureHelper.ComposeMailSignature(currentProfile.EmailSmtpSettings);

            var job = CreateJob(jobTranslations, currentProfile, accounts);

            var success = TrySetJobPasswords(job, profile);

            if (!success)
            {
                return;
            }

            var testFile = _path.Combine(_path.GetTempPath(), "testfile.txt");

            _file.WriteAllText(testFile, @"PDFCreator", Encoding.GetEncoding("Unicode"));
            job.OutputFiles.Add(testFile);

            var recipients = currentProfile.EmailSmtpSettings.Recipients;

            actionResult = _smtpMailAction.ProcessJob(job);

            _file.Delete(testFile);
            DisplayResult(actionResult, recipients);
        }
Example #5
0
        public EditEmailTextViewModel(ITranslator translator)
        {
            Translator = translator;
            var tokenHelper = new TokenHelper(translator);

            TokenReplacer = tokenHelper.TokenReplacerWithPlaceHolders;
            var tokens = tokenHelper.GetTokenListForEmail();

            var mailSignatureHelper = new MailSignatureHelper(translator);

            _signatureText = mailSignatureHelper.ComposeMailSignature();

            SubjectTextViewModel         = new TokenViewModel(
                s => Interaction.Subject = s,
                () => Interaction?.Subject,
                tokens);

            BodyTextViewModel            = new TokenViewModel(
                s => Interaction.Content = s,
                () => Interaction?.Content,
                tokens);

            OkCommand = new DelegateCommand(ExecuteOk);
        }
Example #6
0
        private void EmailClientTestButton_OnClick(object sender, RoutedEventArgs e)
        {
            var emailClientFactory = new EmailClientFactory();
            var emailClient        = emailClientFactory.CreateEmailClient();

            if (emailClient == null)
            {
                string caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("EmailClientActionSettings", "CheckMailClient", "Check e-mail client");
                string message = TranslationHelper.Instance.TranslatorInstance.GetTranslation("EmailClientActionSettings", "NoMapiClientFound",
                                                                                              "Could not find MAPI client (e.g. Thunderbird or Outlook).");
                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Warning);
                return;
            }

            var eMail = new Email();

            eMail.To.Add(EmailClientSettings.Recipients);
            eMail.Subject = EmailClientSettings.Subject;
            eMail.Body    = EmailClientSettings.Content + MailSignatureHelper.ComposeMailSignature(EmailClientSettings);

            try
            {
                string tempFolder    = Path.GetTempPath();
                string tmpTestFolder = Path.Combine(tempFolder, "PDFCreator-Test\\SendSmtpTestmail");
                Directory.CreateDirectory(tmpTestFolder);
                string tmpFile = Path.Combine(tmpTestFolder, "PDFCreator Mail Client Test.pdf");
                File.WriteAllText(tmpFile, "");
                eMail.Attachments.Add(new Attachment(tmpFile));

                emailClient.ShowEmailClient(eMail);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "Exception while creating mail");
            }
        }
Example #7
0
        private void SendTestMailButton_OnClick(object sender, RoutedEventArgs e)
        {
            var smtpMailAction = new SmtpMailAction(MailSignatureHelper.ComposeMailSignature(CurrentProfile.EmailSmtp));

            var currentProfile = ((ActionsTabViewModel)DataContext).CurrentProfile.Copy();

            #region check profile
            var result = smtpMailAction.Check(currentProfile);
            if (!result.Success)
            {
                var caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("SmtpEmailActionSettings", "SendTestMail", "Send test mail");
                var message = ErrorCodeInterpreter.GetFirstErrorText(result, true);
                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Error);
                return;
            }
            #endregion

            #region create job
            string tempFolder    = Path.GetTempPath();
            string tmpTestFolder = Path.Combine(tempFolder, "PdfCreatorTest\\SendSmtpTestmail");
            Directory.CreateDirectory(tmpTestFolder);
            string tmpInfFile = Path.Combine(tmpTestFolder, "SmtpTest.inf");

            var sb = new StringBuilder();
            sb.AppendLine("[1]");
            sb.AppendLine("SessionId=1");
            sb.AppendLine("WinStation=Console");
            sb.AppendLine("UserName=SampleUser1234");
            sb.AppendLine("ClientComputer=\\PC1");
            sb.AppendLine("PrinterName=PDFCreator");
            sb.AppendLine("JobId=1");
            sb.AppendLine("DocumentTitle=SmtpTest");
            sb.AppendLine("");

            File.WriteAllText(tmpInfFile, sb.ToString(), Encoding.GetEncoding("Unicode"));

            JobTranslations jobTranslations = new JobTranslations();
            jobTranslations.EmailSignature = MailSignatureHelper.ComposeMailSignature(true);

            var tempFolderProvider = new StaticTempFolderProvider(Path.Combine(Path.GetTempPath(), "PDFCreator"));

            var job = new GhostscriptJob(new JobInfo(tmpInfFile), new ConversionProfile(), tempFolderProvider, jobTranslations);

            job.Profile = currentProfile;
            #endregion

            #region add password
            if (string.IsNullOrEmpty(Password))
            {
                var pwWindow = new SmtpPasswordWindow(SmtpPasswordMiddleButton.None, currentProfile.EmailSmtp.Address, currentProfile.EmailSmtp.Recipients);
                if (pwWindow.ShowDialogTopMost() != SmtpPasswordResponse.OK)
                {
                    Directory.Delete(tmpTestFolder, true);
                    return;
                }
                job.Passwords.SmtpPassword = pwWindow.SmtpPassword;
            }
            else
            {
                job.Passwords.SmtpPassword = Password;
            }
            #endregion

            #region add testfile
            string testFile = (Path.Combine(tmpTestFolder, "testfile.txt"));
            File.WriteAllText(testFile, @"PDFCreator", Encoding.GetEncoding("Unicode"));
            job.OutputFiles.Add(testFile);
            #endregion

            LogManager.GetCurrentClassLogger().Info("Send test mail over smtp.");
            result = smtpMailAction.ProcessJob(job);
            Directory.Delete(tmpTestFolder, true);

            if (!result.Success)
            {
                var caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("SmtpEmailActionSettings", "SendTestMail",
                                                                                           "Send test mail");
                var message = ErrorCodeInterpreter.GetFirstErrorText(result, true);
                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Error);
            }
            else
            {
                var caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation("SmtpEmailActionSettings", "SendTestMail", "Send test mail");
                var message = TranslationHelper.Instance.TranslatorInstance.GetFormattedTranslation("SmtpEmailActionSettings", "TestMailSent",
                                                                                                    "Test mail sent to {0}.", job.Profile.EmailSmtp.Recipients);
                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Info);
            }
        }