Esempio n. 1
0
        private static int StartApplication(string[] args, Func <Bootstrapper> getBootstrapperFunc)
        {
            Application.EnableVisualStyles();

            Thread.CurrentThread.Name = "ProgramThread";

            InitializeLogging();
            Logger.Debug("Starting PDFCreator");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var bootstrapper = getBootstrapperFunc();
            var container    = new Container();

            var windowResolver = new SimpleInjectorWindowResolver(container);
            var windowRegistry = new WindowRegistry(windowResolver);

            bootstrapper.ConfigureContainer(container, windowRegistry);
            bootstrapper.RegisterInteractions(windowRegistry);

            container.Verify(VerificationOption.VerifyOnly);

            var resolver = new SimpleInjectorAppStartResolver(container);

            var appStartFactory = new AppStartFactory(resolver);
            var appStart        = appStartFactory.CreateApplicationStart(args);

            var app = new App(appStart);

            app.DispatcherUnhandledException += Application_DispatcherUnhandledException;

            return(app.Run());
        }
        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
        }
Esempio n. 3
0
        public void Called_WithNonSense_ReturnsMainWindowStartUp()
        {
            string[] args = { "NonSense123" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <MainWindowStart>(appStart);
        }
Esempio n. 4
0
        public void Called_WithInitializeSettings_ReturnsInitializeJobStart()
        {
            string[] args = { string.Format("/InitializeSettings") };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <InitializeSettingsStart>(appStart);
        }
Esempio n. 5
0
        public void Called_WithPrintFileAndInitializeSettings_ReturnsPrintFileJobStart()
        {
            string[] args = { string.Format("/PrintFile=C:\\Test.txt"), "/InitializeSettings" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <PrintFileStart>(appStart);
        }
Esempio n. 6
0
        public void Called_WithPrintFileAndPrinterParameter_ReturnsPrintFileStartUpWithCorrectPrinter()
        {
            string[] args = { "/PrintFile=C:\\Test.txt", "/PrinterName=TestPrinter" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <PrintFileStart>(appStart);
            Assert.AreEqual("TestPrinter", ((PrintFileStart)appStart).PrinterName);
        }
Esempio n. 7
0
        private static int StartApplication(string[] args, Func <Bootstrapper> getBootstrapperFunc)
        {
            Application.EnableVisualStyles();

            Thread.CurrentThread.Name = "ProgramThread";

            InitializeLogging();
            Logger.Debug("Starting PDFCreator");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            var bootstrapper = getBootstrapperFunc();

            _container = new Container();

            var profileSettingsTabs     = bootstrapper.DefineProfileSettingsTabs();
            var applicationSettingsTabs = bootstrapper.DefineApplicationSettingsTabs();

            var prismBootstrapper = new PrismBootstrapper(profileSettingsTabs, applicationSettingsTabs);

            prismBootstrapper.ConfigurePrismDependecies(_container);
            prismBootstrapper.RegisterNavigationViews(_container);

            bootstrapper.ConfigureContainer(_container);
            bootstrapper.RegisterInteractions();

            ViewRegistry.WindowFactory = new DelegateWindowFactory(content =>
            {
                var window     = _container.GetInstance <InteractionHostWindow>();
                window.Content = content;

                return(window);
            });

            if (Debugger.IsAttached)
            {
                _container.Verify(VerificationOption.VerifyOnly);
            }

            bootstrapper.RegisterEditiondependentRegions(_container.GetInstance <IRegionManager>());
            prismBootstrapper.InitPrismStuff(_container);

            var resolver = new SimpleInjectorAppStartResolver(_container);

            var appStartFactory = new AppStartFactory(resolver);
            var appStart        = appStartFactory.CreateApplicationStart(args);

            var helpCommandHandler = _container.GetInstance <HelpCommandHandler>();
            var settingsManager    = _container.GetInstance <ISettingsManager>();

            var app = new App(appStart, helpCommandHandler, settingsManager);

            app.DispatcherUnhandledException += Application_DispatcherUnhandledException;
            return(app.Run());
        }
Esempio n. 8
0
        private static void InitalizeApplication(string[] args, SimpleInjectorPrismApplication application)
        {
            var resolver           = new SimpleInjectorAppStartResolver(_container);
            var appStartFactory    = new AppStartFactory(resolver, _container.GetInstance <IPathUtil>(), _container.GetInstance <IDirectConversionHelper>());
            var appStart           = appStartFactory.CreateApplicationStart(args);
            var helpCommandHandler = _container.GetInstance <HelpCommandHandler>();
            var settingsManager    = _container.GetInstance <ISettingsManager>();

            application.InitApplication(appStart, helpCommandHandler, settingsManager);
            application.DispatcherUnhandledException += Application_DispatcherUnhandledException;
        }
Esempio n. 9
0
        public void Called_WithManagePrintJobs_ReturnsManagePrintJobsStartUp()
        {
            string[] args = { "/ManagePrintJobs" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            MaybePipedStart maybePipedStart = appStart as MaybePipedStart;

            Assert.IsTrue(maybePipedStart.StartManagePrintJobs);
        }
Esempio n. 10
0
        public void Called_WithPdfFileAndInitializeSettings_ReturnsNewPrintJobStart()
        {
            string jobFile = @"C:\test.pdf";

            string[] args = { string.Format("/PdfFile={0}", jobFile), "/InitializeSettings" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <NewPsJobStart>(appStart);
        }
Esempio n. 11
0
        public void Called_WithExistingFile_ReturnsDragAndDropStart()
        {
            string[] args = { "ExistingFile.xxx" };

            var fileStub = Substitute.For <IFile>();

            fileStub.Exists("ExistingFile.xxx").Returns(true);
            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args, fileStub);

            Assert.IsAssignableFrom <DragAndDropStart>(appStart);
        }
Esempio n. 12
0
        public void Called_WithNotExistingFile_ReturnsMainWindowStartUp()
        {
            string[] args = { "NotExistingFile.xxx" };

            var fileStub = Substitute.For <IFile>();

            fileStub.Exists("NotExistingFile.xxx").Returns(false);
            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args, fileStub);

            Assert.IsAssignableFrom <MainWindowStart>(appStart);
        }
Esempio n. 13
0
        public void Called_WithPdfFile_ReturnsNewPsJobStart()
        {
            string jobFile = @"C:\test.pdf";

            string[] args = { string.Format("/PdfFile={0}", jobFile) };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <NewPsJobStart>(appStart);
            Assert.AreEqual(jobFile, ((NewPsJobStart)appStart).NewPsFile, "Wrong File in NewPsJobStart.");
        }
Esempio n. 14
0
        public void Called_WithPsFileAndManagePrintJobs_NewPsJobStartWithManagePrintJobs()
        {
            string jobFile = @"C:\test.ps";

            string[] args = { string.Format("/PsFile={0}", jobFile), "/ManagePrintJobs" };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <NewPsJobStart>(appStart);
            Assert.IsTrue(((NewPsJobStart)appStart).StartManagePrintJobs);
        }
Esempio n. 15
0
        public void Called_WithJobInfo_ReturnsNewPrintJobStart()
        {
            string jobFile = @"C:\test.inf";

            string[] args = { string.Format("/InfoDataFile={0}", jobFile) };

            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args);

            Assert.IsAssignableFrom <NewPrintJobStart>(appStart);
            Assert.AreEqual(jobFile, ((NewPrintJobStart)appStart).NewJobInfoFile, "Wrong JobInfoFile.");
        }
Esempio n. 16
0
        public void Called_WithFilesAndNonsenseParameter_ReturnsMainWindowStart()
        {
            string[] args = { "ExistingFile1.xxx", "/NonSenseParameter", "NotExistingFile.xxx", "ExistingFile2.xxx" };

            var fileStub = Substitute.For <IFile>();

            fileStub.Exists("ExistingFile1.xxx").Returns(true);
            fileStub.Exists("NotExistingFile.xxx").Returns(false);
            fileStub.Exists("ExistingFile2.xxx").Returns(true);
            var appStartFactory = new AppStartFactory(new ApplicationSettings());
            var appStart        = appStartFactory.CreateApplicationStart(args, fileStub);

            Assert.IsAssignableFrom <MainWindowStart>(appStart);
        }
Esempio n. 17
0
        private void RunApplication(string[] commandLineArguments)
        {
            CheckSpoolerRunning();

            // Must be done before the other checks to initialize the translator
            SettingsHelper.Init();

            // Check translations and Ghostscript. Exit if there is a problem
            CheckInstallation();

            CheckLicensing();

            AppStartFactory appStartFactory = new AppStartFactory();
            var             appStart        = appStartFactory.CreateApplicationStart(commandLineArguments);

            // PrintFile needs to be started before initializing the JonbInfoQueue
            if (appStart is PrintFileStart)
            {
                appStart.Run();
                return;
            }

            Logger.Debug("Starting PDFCreator");

            if (commandLineArguments.Length > 0)
            {
                Logger.Info("Command Line parameters: \r\n" + String.Join(" ", commandLineArguments));
            }

            if (!InitializeJobInfoQueue())
            {
                return;
            }

            // Start the application
            appStart.Run();

            Logger.Debug("Waiting for all threads to finish");
            ThreadManager.Instance.WaitForThreadsAndShutdown(this);
        }
Esempio n. 18
0
        private AppStartFactory BuildAppStartFactory()
        {
            var appStartFactory = new AppStartFactory(_resolver, _parametersManager);

            return(appStartFactory);
        }
Esempio n. 19
0
        private AppStartFactory BuildAppStartFactory()
        {
            var appStartFactory = new AppStartFactory(_resolver);

            return(appStartFactory);
        }