public void AddValidExtension_GivenBadFiles_ReturnsGoodFiles() { foreach (var sample in _badSamples) { Assert.IsTrue(_outputFormatHelper.HasValidExtension(_outputFormatHelper.EnsureValidExtension(sample.Key, sample.Value), sample.Value)); } }
private QueryResult <OutputFilenameResult> InvokeInteraction(SaveFileInteraction interaction, OutputFormat outputFormat, bool canChangeFormat) { var result = new QueryResult <OutputFilenameResult> { Success = false }; _interactionInvoker.Invoke(interaction); if (!interaction.Success) { return(result); } if (canChangeFormat) { outputFormat = (OutputFormat)interaction.FilterIndex - 1; } var outputFile = interaction.FileName; var outputFormatHelper = new OutputFormatHelper(); if (!outputFormatHelper.HasValidExtension(outputFile, outputFormat)) { outputFile = outputFormatHelper.EnsureValidExtension(outputFile, outputFormat); } result.Success = true; result.Data = new OutputFilenameResult(outputFile, outputFormat); return(result); }
private bool LaunchSaveFileForRetyping(SaveFileDialog saveFileDialog) { var result = TopMostHelper.ShowDialogTopMost(saveFileDialog, !Job.Profile.SkipPrintDialog); if (result != DialogResult.OK) { Logger.Info("User cancelled the save dialog. No file will be created."); WorkflowStep = WorkflowStep.AbortedByUser; return(false); } try { var outputFile = saveFileDialog.FileName; if (!OutputFormatHelper.HasValidExtension(outputFile, Job.Profile.OutputFormat)) { outputFile = OutputFormatHelper.EnsureValidExtension(outputFile, Job.Profile.OutputFormat); } Job.OutputFilenameTemplate = outputFile; return(true); } catch (PathTooLongException) { Logger.Error("Filename (+ path) from savefile dialog is too long."); var message = _translator.GetTranslation("InteractiveWorkflow", "SelectedPathTooLong", "The total length of path and filename is too long.\r\nPlease use a shorter name."); var caption = _translator.GetTranslation("InteractiveWorkflow", "SelectDestination", "Select destination"); MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Warning); return(LaunchSaveFileForRetyping(saveFileDialog)); } }
public void AddValidExtension_GivenGoodFiles_ReturnsSameFiles() { foreach (KeyValuePair <string, OutputFormat> sample in _goodSamples) { Assert.AreEqual(OutputFormatHelper.EnsureValidExtension(sample.Key, sample.Value), sample.Key); } }
/// <summary> /// Get the list of Ghostscript Parameters. This List contains of a basic set of parameters together with some /// device-specific /// parameters that will be added by the device implementation /// </summary> /// <param name="ghostscriptVersion"></param> /// <returns>A list of parameters that will be passed to Ghostscript</returns> public IList <string> GetGhostScriptParameters(GhostscriptVersion ghostscriptVersion) { IList <string> parameters = new List <string>(); var outputFormatHelper = new OutputFormatHelper(); parameters.Add("gs"); parameters.Add("--permit-file-all=\"" + Job.JobTempFolder + "\\\""); parameters.Add("-I" + ghostscriptVersion.LibPaths); parameters.Add("-sFONTPATH=" + _osHelper.WindowsFontsFolder); parameters.Add("-dNOPAUSE"); parameters.Add("-dBATCH"); if (!outputFormatHelper.HasValidExtension(Job.OutputFileTemplate, Job.Profile.OutputFormat)) { outputFormatHelper.EnsureValidExtension(Job.OutputFileTemplate, Job.Profile.OutputFormat); } AddOutputfileParameter(parameters); AddDeviceSpecificParameters(parameters); // Add user-defined parameters if (!string.IsNullOrEmpty(Job.Profile.Ghostscript.AdditionalGsParameters)) { var args = _commandLineUtil.CommandLineToArgs(Job.Profile.Ghostscript.AdditionalGsParameters); foreach (var s in args) { parameters.Add(s); } } //Dictonary-Parameters must be the last Parameters if (DistillerDictonaries.Count > 0) { parameters.Add("-c"); foreach (var parameter in DistillerDictonaries) { parameters.Add(parameter); } } //Don't add further paramters here, since the distiller-parameters should be the last! parameters.Add("-f"); SetSourceFiles(parameters, Job); // Compose name of the pdfmark file based on the location and name of the inf file var pdfMarkFileName = PathSafe.Combine(Job.JobTempFolder, "metadata.mtd"); CreatePdfMarksFile(pdfMarkFileName); // Add pdfmark file as input file to set metadata parameters.Add(pdfMarkFileName); return(parameters); }
private string EnsureValidExtensionInFilename(string fileName, OutputFormat format) { if (Job?.Profile?.OutputFormat == null) { return(""); } return(_outputFormatHelper.EnsureValidExtension(fileName, format)); }
private void ChangeOutputFormat() { if (Job?.Profile?.OutputFormat == null) { return; } var outputFormat = Job.Profile.OutputFormat; OutputFilename = _outputFormatHelper.EnsureValidExtension(OutputFilename, outputFormat); }
private string GetTargetFilenameText() { var profile = _selectedProfileProvider.SelectedProfile; if (profile == null) { return(""); } var formatHelper = new OutputFormatHelper(); return(formatHelper.EnsureValidExtension(profile.FileNameTemplate, profile.OutputFormat)); }
private async Task <bool> CheckJob(Job job) { //Ensure extension before the checks job.OutputFileTemplate = _outputFormatHelper.EnsureValidExtension(job.OutputFileTemplate, job.Profile.OutputFormat); if (!_interactiveProfileChecker.CheckWithErrorResultInOverlay(job)) { return(false); } var fileExistsResult = await _interactiveFileExistsChecker.CheckIfFileExistsWithResultInOverlay(job, _getLatestConfirmedPath()); _setLatestConfirmedPath(fileExistsResult.ConfirmedPath); return(fileExistsResult.Success); }
/// <summary> /// Sets the location where the job should be converted to and the jobs full name /// </summary> /// <param name="fileName">Specifies the location and the name of the converted file</param> private string DetermineOutputFilename(string fileName) { if (fileName == null) { throw new COMException("The output filename was not set"); } var tmpPath = PathSafe.GetDirectoryName(fileName); if (tmpPath == null || !_directory.Exists(tmpPath)) { throw new COMException("Invalid path. Please check if the directory exists."); } Logger.Trace("COM: Setting the full name of the job:" + fileName); return(_outputFormatHelper.EnsureValidExtension(fileName, Job.Profile.OutputFormat)); }
private QueryResult <string> InvokeInteraction(SaveFileInteraction interaction, Job job, bool canChangeFormat) { var result = new QueryResult <string> { Success = false }; _interactionInvoker.Invoke(interaction); if (!interaction.Success) { return(result); } if (canChangeFormat) { job.Profile.OutputFormat = (OutputFormat)interaction.FilterIndex - 1; } try { var outputFile = interaction.FileName; var outputFormatHelper = new OutputFormatHelper(); if (!outputFormatHelper.HasValidExtension(outputFile, job.Profile.OutputFormat)) { outputFile = outputFormatHelper.EnsureValidExtension(outputFile, job.Profile.OutputFormat); } result.Success = true; result.Data = outputFile; return(result); } catch (PathTooLongException) { NotifyUserAboutPathTooLong(); return(InvokeInteraction(interaction, job, canChangeFormat)); } }
/// <summary> /// Get the list of Ghostscript Parameters. This List contains of a basic set of parameters together with some /// device-specific /// parameters that will be added by the device implementation /// </summary> /// <param name="ghostscriptVersion"></param> /// <returns>A list of parameters that will be passed to Ghostscript</returns> public IList <string> GetGhostScriptParameters(GhostscriptVersion ghostscriptVersion) { IList <string> parameters = new List <string>(); var outputFormatHelper = new OutputFormatHelper(); parameters.Add("gs"); parameters.Add("-I" + ghostscriptVersion.LibPaths); parameters.Add("-sFONTPATH=" + _osHelper.WindowsFontsFolder); parameters.Add("-dNOPAUSE"); parameters.Add("-dBATCH"); if (!outputFormatHelper.HasValidExtension(Job.OutputFilenameTemplate, Job.Profile.OutputFormat)) { outputFormatHelper.EnsureValidExtension(Job.OutputFilenameTemplate, Job.Profile.OutputFormat); } AddOutputfileParameter(parameters); AddDeviceSpecificParameters(parameters); // Add user-defined parameters if (!string.IsNullOrEmpty(Job.Profile.Ghostscript.AdditionalGsParameters)) { var args = _commandLineUtil.CommandLineToArgs(Job.Profile.Ghostscript.AdditionalGsParameters); foreach (var s in args) { parameters.Add(s); } } //Dictonary-Parameters must be the last Parameters if (DistillerDictonaries.Count > 0) { parameters.Add("-c"); foreach (var parameter in DistillerDictonaries) { parameters.Add(parameter); } } //Don't add further paramters here, since the distiller-parameters should be the last! parameters.Add("-f"); if (Job.Profile.Stamping.Enabled) { // Compose name of the stamp file based on the location and name of the inf file var stampFileName = PathSafe.Combine(Job.JobTempFolder, PathSafe.GetFileNameWithoutExtension(Job.JobInfo.InfFile) + ".stm"); CreateStampFile(stampFileName, Job.Profile, Job.TokenReplacer); parameters.Add(stampFileName); } if (Job.Profile.CoverPage.Enabled) { parameters.Add(PathHelper.GetShortPathName(Job.Profile.CoverPage.File)); } foreach (var sfi in Job.JobInfo.SourceFiles) { parameters.Add(PathHelper.GetShortPathName(sfi.Filename)); } if (Job.Profile.AttachmentPage.Enabled) { parameters.Add(PathHelper.GetShortPathName(Job.Profile.AttachmentPage.File)); } // Compose name of the pdfmark file based on the location and name of the inf file var pdfMarkFileName = PathSafe.Combine(Job.JobTempFolder, "metadata.mtd"); CreatePdfMarksFile(pdfMarkFileName); // Add pdfmark file as input file to set metadata parameters.Add(pdfMarkFileName); return(parameters); }
public void AddValidExtension_GivenBadFiles_ReturnsGoodFiles(string filename, OutputFormat outputFormat) { var fixedFile = _outputFormatHelper.EnsureValidExtension(filename, outputFormat); Assert.IsTrue(_outputFormatHelper.HasValidExtension(fixedFile, outputFormat)); }