public IAppStart CreateApplicationStart(string[] commandLineArgs) { LogCommandLineParameters(commandLineArgs); if (IsDragAndDropStart(commandLineArgs)) { _logger.Debug("Launched Drag & Drop"); var dragAndDropStart = _appStartResolver.ResolveAppStart<DragAndDropStart>(); dragAndDropStart.DroppedFiles = commandLineArgs.ToList(); return dragAndDropStart; } var commandLineParser = new CommandLineParser(commandLineArgs); if (commandLineParser.HasArgument("InitializeDefaultSettings")) { var defaultSettingsStart = _appStartResolver.ResolveAppStart<InitializeDefaultSettingsStart>(); defaultSettingsStart.SettingsFile = commandLineParser.GetArgument("InitializeDefaultSettings"); return defaultSettingsStart; } if (commandLineParser.HasArgument("StoreLicenseForAllUsers")) { var storeLicenseForAllUsers = _appStartResolver.ResolveAppStart<StoreLicenseForAllUsersStart>(); if (commandLineParser.HasArgument("LicenseServerCode")) storeLicenseForAllUsers.LicenseServerCode = commandLineParser.GetArgument("LicenseServerCode"); if (commandLineParser.HasArgument("LicenseKey")) storeLicenseForAllUsers.LicenseKey = commandLineParser.GetArgument("LicenseKey"); return storeLicenseForAllUsers; } if (commandLineParser.HasArgument("PrintFile")) { var printFile = FindPrintFile(commandLineParser); var printerName = FindPrinterName(commandLineParser); var printFileStart = _appStartResolver.ResolveAppStart<PrintFileStart>(); printFileStart.PrintFile = printFile; printFileStart.PrinterName = printerName; return printFileStart; } if (ShouldCallInitialize(commandLineParser)) { return _appStartResolver.ResolveAppStart<InitializeSettingsStart>(); } var appStart = DetermineAppStart(commandLineParser, _appStartResolver); if (commandLineParser.HasArgument("ManagePrintJobs")) { appStart.StartManagePrintJobs = true; } return appStart; }
private MaybePipedStart DetermineAppStart(CommandLineParser commandLineParser, IAppStartResolver appStartResolver) { // let's see if we have a new JobInfo passed as command line argument var newJob = FindJobInfoFile(commandLineParser); if (newJob != null) { var newPrintJobStart = appStartResolver.ResolveAppStart <NewPrintJobStart>(); newPrintJobStart.NewJobInfoFile = newJob; return(newPrintJobStart); } // or a PSFile? newJob = FindPSFile(commandLineParser); if (newJob != null) { var printerName = FindPrinterName(commandLineParser); var profileParameter = ""; if (string.IsNullOrWhiteSpace(printerName)) { profileParameter = FindProfileParameter(commandLineParser); } var outputFileParameter = FindOutputfileParameter(commandLineParser); var newPsJobStart = appStartResolver.ResolveAppStart <NewPsJobStart>(); newPsJobStart.NewDirectConversionFile = newJob; newPsJobStart.PrinterName = printerName; newPsJobStart.OutputFileParameter = outputFileParameter; newPsJobStart.ProfileParameter = profileParameter; return(newPsJobStart); } // or a PdfFile? newJob = FindPdfFile(commandLineParser); if (newJob != null) { var printerName = FindPrinterName(commandLineParser); var outputFileParameter = FindOutputfileParameter(commandLineParser); var profileParameter = ""; if (string.IsNullOrWhiteSpace(printerName)) { profileParameter = FindProfileParameter(commandLineParser); } var newPdfJobStart = appStartResolver.ResolveAppStart <NewPdfJobStart>(); newPdfJobStart.NewDirectConversionFile = newJob; newPdfJobStart.PrinterName = printerName; newPdfJobStart.OutputFileParameter = outputFileParameter; newPdfJobStart.ProfileParameter = profileParameter; return(newPdfJobStart); } // ...nope!? We have a MainWindowStart return(appStartResolver.ResolveAppStart <MainWindowStart>()); }
public void Setup() { LoggingHelper.InitConsoleLogger("Test", LoggingLevel.Off); var startupConditions = Substitute.For <ICheckAllStartupConditions>(); var starter = Substitute.For <IMaybePipedApplicationStarter>(); starter.StartupConditions.Returns(startupConditions); _resolver = Substitute.For <IAppStartResolver>(); // We need some special syntax here to make NSubsitute work here: .Returns(x => new MainWindowStart(...)); _resolver.ResolveAppStart <MainWindowStart>().Returns(x => new MainWindowStart(null, starter, Substitute.For <IPdfArchitectCheck>(), Substitute.For <IMainWindowThreadLauncher>())); _resolver.ResolveAppStart <DragAndDropStart>().Returns(x => new DragAndDropStart(Substitute.For <IFileConversionAssistant>(), starter)); _resolver.ResolveAppStart <PrintFileStart>().Returns(x => new PrintFileStart(Substitute.For <ICheckAllStartupConditions>(), Substitute.For <IPrintFileHelper>(), null, Substitute.For <IStoredParametersManager>())); _resolver.ResolveAppStart <DirectConversionStart>().Returns(x => new DirectConversionStart(null, starter, null, null)); _resolver.ResolveAppStart <NewPrintJobStart>().Returns(x => new NewPrintJobStart(null, null, null, starter, null)); _resolver.ResolveAppStart <InitializeDefaultSettingsStart>().Returns(x => new InitializeDefaultSettingsStart(null, null, null, Substitute.For <IInstallationPathProvider>(), Substitute.For <IDataStorageFactory>())); _resolver.ResolveAppStart <StoreLicenseForAllUsersStart>().Returns(x => new StoreLicenseForAllUsersStart(null, null, new InstallationPathProvider("", "", "", RegistryHive.CurrentUser))); _pathUtil = Substitute.For <IPathUtil>(); var directConversionHelper = Substitute.For <IDirectConversionHelper>(); _appStartFactory = new AppStartFactory(_resolver, _pathUtil, directConversionHelper); // TODO: Add tests of thr Run() method as it is testable now }
private MaybePipedStart DetermineAppStart(CommandLineParser commandLineParser, IAppStartResolver appStartResolver) { // let's see if we have a new JobInfo passed as command line argument var newJob = FindJobInfoFile(commandLineParser); if (newJob != null) { var newPrintJobStart = appStartResolver.ResolveAppStart <NewPrintJobStart>(); newPrintJobStart.NewJobInfoFile = newJob; return(newPrintJobStart); } // or a PSFile? newJob = FindPSFile(commandLineParser); if (newJob != null) { var printerName = FindPrinterName(commandLineParser); var newPsJobStart = appStartResolver.ResolveAppStart <NewPsJobStart>(); newPsJobStart.NewDirectConversionFile = newJob; newPsJobStart.PrinterName = printerName; return(newPsJobStart); } // or a PdfFile? newJob = FindPdfFile(commandLineParser); if (newJob != null) { var printerName = FindPrinterName(commandLineParser); var newPdfJobStart = appStartResolver.ResolveAppStart <NewPdfJobStart>(); newPdfJobStart.NewDirectConversionFile = newJob; newPdfJobStart.PrinterName = printerName; return(newPdfJobStart); } // ...nope!? We have a MainWindowStart return(appStartResolver.ResolveAppStart <MainWindowStart>()); }
public IAppStart CreateApplicationStart(string[] commandLineArgs) { LogCommandLineParameters(commandLineArgs); if (IsDragAndDropStart(commandLineArgs)) { _logger.Debug("Launched Drag & Drop"); var dragAndDropStart = _appStartResolver.ResolveAppStart <DragAndDropStart>(); dragAndDropStart.DroppedFiles = commandLineArgs.ToList(); return(dragAndDropStart); } var commandLineParser = new CommandLineParser(commandLineArgs); if (commandLineParser.HasArgument("RestorePrinters")) { _logger.Debug("Launched RestorePrinters"); return(_appStartResolver.ResolveAppStart <RestorePrinterAppStart>()); } var appStartParameters = new AppStartParameters(); appStartParameters.ManagePrintJobs = commandLineParser.HasArgument("ManagePrintJobs"); if (commandLineParser.HasArgumentWithValue("InfoDataFile")) { var infFile = commandLineParser.GetArgument("InfoDataFile"); var newPrintJobStart = _appStartResolver.ResolveAppStart <NewPrintJobStart>(); newPrintJobStart.NewJobInfoFile = infFile; newPrintJobStart.AppStartParameters = appStartParameters; return(newPrintJobStart); } if (commandLineParser.HasArgument("InitializeDefaultSettings")) { var defaultSettingsStart = _appStartResolver.ResolveAppStart <InitializeDefaultSettingsStart>(); defaultSettingsStart.SettingsFile = commandLineParser.GetArgument("InitializeDefaultSettings"); return(defaultSettingsStart); } if (commandLineParser.HasArgument("InitializeSettings")) { return(_appStartResolver.ResolveAppStart <InitializeSettingsStart>()); } if (commandLineParser.HasArgument("StoreLicenseForAllUsers")) { var storeLicenseForAllUsersStart = _appStartResolver.ResolveAppStart <StoreLicenseForAllUsersStart>(); if (commandLineParser.HasArgumentWithValue("LicenseServerCode")) { storeLicenseForAllUsersStart.LicenseServerCode = commandLineParser.GetArgument("LicenseServerCode"); } if (commandLineParser.HasArgumentWithValue("LicenseKey")) { storeLicenseForAllUsersStart.LicenseKey = commandLineParser.GetArgument("LicenseKey"); } return(storeLicenseForAllUsersStart); } appStartParameters.Merge = commandLineParser.HasArgument("Merge"); appStartParameters.Printer = FindPrinterName(commandLineParser); appStartParameters.Profile = FindProfileParameter(commandLineParser); appStartParameters.OutputFile = FindOutputfileParameter(commandLineParser); var files = new List <string>(); if (commandLineParser.HasArgumentWithValue("PrintFile")) { var printFile = commandLineParser.GetArgument("PrintFile"); if (_directConversionHelper.CanConvertDirectly(printFile)) { files.Add(printFile); //Add file and proceed with directConversion see below } else { var printFileStart = _appStartResolver.ResolveAppStart <PrintFileStart>(); printFileStart.PrintFile = printFile; printFileStart.AppStartParameters = appStartParameters; return(printFileStart); } } AddDirectConversionFiles(files, commandLineParser); var parameterlessFiles = commandLineArgs.Where(IsFileArg).ToList(); files.AddRange(parameterlessFiles); if (files.Count > 0) { _logger.Debug("Launched DragAndDropStart"); var dragAndDropStart = _appStartResolver.ResolveAppStart <DragAndDropStart>(); dragAndDropStart.DroppedFiles = files; dragAndDropStart.AppStartParameters = appStartParameters; return(dragAndDropStart); } // ... else we have a MainWindowStart var mainWindowStart = _appStartResolver.ResolveAppStart <MainWindowStart>(); // suppress ManagePrintJobWindows together with the MainWindow (at this point no conversion was requested) appStartParameters.ManagePrintJobs = false; mainWindowStart.AppStartParameters = appStartParameters; return(mainWindowStart); }
public IAppStart CreateApplicationStart(string[] commandLineArgs) { LogCommandLineParameters(commandLineArgs); if (IsDragAndDropStart(commandLineArgs)) { _logger.Debug("Launched Drag & Drop"); var dragAndDropStart = _appStartResolver.ResolveAppStart <DragAndDropStart>(); dragAndDropStart.DroppedFiles = commandLineArgs.ToList(); return(dragAndDropStart); } var commandLineParser = new CommandLineParser(commandLineArgs); if (commandLineParser.HasArgument("InitializeDefaultSettings")) { var defaultSettingsStart = _appStartResolver.ResolveAppStart <InitializeDefaultSettingsStart>(); defaultSettingsStart.SettingsFile = commandLineParser.GetArgument("InitializeDefaultSettings"); return(defaultSettingsStart); } if (commandLineParser.HasArgument("StoreLicenseForAllUsers")) { var storeLicenseForAllUsers = _appStartResolver.ResolveAppStart <StoreLicenseForAllUsersStart>(); if (commandLineParser.HasArgument("LicenseServerCode")) { storeLicenseForAllUsers.LicenseServerCode = commandLineParser.GetArgument("LicenseServerCode"); } if (commandLineParser.HasArgument("LicenseKey")) { storeLicenseForAllUsers.LicenseKey = commandLineParser.GetArgument("LicenseKey"); } return(storeLicenseForAllUsers); } if (commandLineParser.HasArgument("PrintFile")) { var printFile = FindPrintFile(commandLineParser); var printerName = FindPrinterName(commandLineParser); var outputFileParameter = FindOutputfileParameter(commandLineParser); // Ignore profileParameter if printerName is set to ensure that the printer has priority. // Later we can't distinguish, if the printer was requested or set by default. var profileParameter = ""; if (string.IsNullOrWhiteSpace(printerName)) { profileParameter = FindProfileParameter(commandLineParser); } var printFileStart = _appStartResolver.ResolveAppStart <PrintFileStart>(); printFileStart.PrintFile = printFile; printFileStart.PrinterName = printerName; if (!string.IsNullOrWhiteSpace(outputFileParameter) || !string.IsNullOrWhiteSpace(profileParameter)) { _parametersManager.SaveParameterSettings(outputFileParameter, profileParameter); } return(printFileStart); } if (ShouldCallInitialize(commandLineParser)) { return(_appStartResolver.ResolveAppStart <InitializeSettingsStart>()); } var appStart = DetermineAppStart(commandLineParser, _appStartResolver); if (commandLineParser.HasArgument("ManagePrintJobs")) { appStart.StartManagePrintJobs = true; } return(appStart); }