public void SendValidPDFJob_CallExecute_CallOpenOutputFile() { var command = BuildCommand(); var defaultViewerByOutputFormat = _settingsProvider.Settings.GetDefaultViewerByOutputFormat(OutputFormat.Pdf); defaultViewerByOutputFormat.IsActive = true; _job.OutputFiles.Add(_fileList.First()); _fileAssoc.HasOpen(Arg.Any <string>()).Returns(false); _defaultViewerAction.OpenOutputFile(_job.OutputFiles.First()).Returns(new ActionResult()); command.Execute(_job); _defaultViewerAction.Received(1).OpenOutputFile(_job.OutputFiles.First()); }
public void OpenOutputFile_NoDefaultViewer_FileAssocHasOpen_OpensOutputFile() { var filePath = @"X:\SomeFile\test.pdf"; _fileAssoc.HasOpen(".pdf").Returns(true); var result = _defaultViewerAction.OpenOutputFile(filePath); Assert.IsTrue(result.IsSuccess); _processStarter.Received(1).Start(filePath); }
/// <summary> /// Open all files in the default viewer /// </summary> /// <param name="job">Job information</param> /// <returns>An ActionResult to determine the success and a list of errors</returns> public ActionResult ProcessJob(Job job) { Logger.Debug("Launched Viewer-Action"); var isPdfFile = job.Profile.OutputFormat == OutputFormat.Pdf || job.Profile.OutputFormat == OutputFormat.PdfA1B || job.Profile.OutputFormat == OutputFormat.PdfA2B || job.Profile.OutputFormat == OutputFormat.PdfX; if (!isPdfFile) { return(OpenJobOutput(job)); } if (job.Profile.OpenWithPdfArchitect && IsArchitectInstalled()) { return(OpenWithArchitect(job)); } if (!_fileAssoc.HasOpen(".pdf")) { Logger.Error("No program associated with pdf."); _recommendArchitect.Show(); return(new ActionResult()); //return true, to avoid another message window. } return(OpenJobOutput(job)); }
private bool ShouldOpenWithArchitect(OutputFormat outputFormat, bool openWithPdfArchitectSetting) { if (!outputFormat.IsPdf()) { return(false); } if (_pdfArchitectCheck.IsInstalled()) { if (openWithPdfArchitectSetting) { return(true); } if (!_fileAssoc.HasOpen(".pdf")) { return(true); } } return(false); }
public override void Execute(object obj) { var path = GetPaths(obj).FirstOrDefault(); if (!path.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase)) { HandleActionResult(Action.OpenOutputFile(path)); } else { if (FileAssoc.HasOpen(".pdf") || SettingsProvider.Settings.ApplicationSettings.GetDefaultViewerByOutputFormat(OutputFormat.Pdf).IsActive) { HandleActionResult(Action.OpenOutputFile(path)); } else { CommandLocator.GetCommand <QuickActionOpenWithPdfArchitectCommand>().Execute(obj); } } }
public ActionResult OpenOutputFile(string filePath) { var outputFormatByPath = _outputFormatHelper.GetOutputFormatByPath(filePath); var defaultViewer = _settingsProvider.Settings.GetDefaultViewerByOutputFormat(outputFormatByPath); try { if (defaultViewer.IsActive) { var result = _defaultViewerCheck.Check(defaultViewer); if (!result) { return(result); } Logger.Debug($"Open \"{filePath}\" with default viewer: {defaultViewer.Path} "); _processStarter.Start(defaultViewer.Path, "\"" + filePath + "\""); return(new ActionResult()); } if (outputFormatByPath.IsPdf() && !_fileAssoc.HasOpen(".pdf")) { if (_pdfArchitectCheck.IsInstalled()) { return(OpenWithArchitect(filePath)); } _recommendArchitect.Show(); return(new ActionResult()); //return true, to avoid another message window. } Logger.Debug("Open file with system default application: " + filePath); _processStarter.Start(filePath); } catch { Logger.Error("File could not be opened."); } return(new ActionResult()); }
/// <summary> /// Open all files in the default viewer /// </summary> /// <param name="job">Job information</param> /// <returns>An ActionResult to determine the success and a list of errors</returns> public ActionResult ProcessJob(Job job) { Logger.Debug("Launched Viewer-Action"); var isPdfFile = job.Profile.OutputFormat == OutputFormat.Pdf || job.Profile.OutputFormat == OutputFormat.PdfA1B || job.Profile.OutputFormat == OutputFormat.PdfA2B || job.Profile.OutputFormat == OutputFormat.PdfX; if (!isPdfFile) { return(OpenJobOutput(job)); } if (job.Profile.OpenWithPdfArchitect) { string architectPath = null; try { architectPath = _architectCheck.GetInstallationPath(); } catch (Exception ex) { Logger.Warn(ex, "There was an exception while checking the PDF Architect path"); } if (architectPath != null) { Logger.Debug("Open with PDF Architect"); foreach (var file in job.OutputFiles) { try { var p = new Process(); p.StartInfo.FileName = architectPath; p.StartInfo.Arguments = "\"" + file + "\""; p.Start(); Logger.Trace("Openend: " + file); } catch { Logger.Error("PDF Architect could not open file: " + file); return(new ActionResult(ErrorCode.Viewer_ArchitectCouldNotOpenOutput)); } } return(new ActionResult()); } Logger.Warn("Open with PDF Architect selected, but not installed"); } if (!_fileAssoc.HasOpen(".pdf")) { Logger.Error("No program associated with pdf."); var displayed = _recommendArchitect.Show(); if (displayed) { return(new ActionResult()); //return true, to avoid another message window. } } return(OpenJobOutput(job)); }
public void FileAssocHasPrint_GivenTxt_HasOpenVerb() { Assert.IsTrue(_fileAssoc.HasOpen("txt")); }