Ejemplo n.º 1
0
        /// <summary>
        ///     Prints all files in the list.
        /// </summary>
        /// <returns>true, if all files could be printed</returns>
        public bool PrintAll()
        {
            if (string.IsNullOrEmpty(PdfCreatorPrinter))
            {
                _logger.Error("No PDFCreator is installed.");
                return(false);
            }

            var requiresDefaultPrinter = _printCommands.RequiresDefaultPrinter;
            var defaultPrinter         = _printerHelper.GetDefaultPrinter();

            try
            {
                if (requiresDefaultPrinter && (defaultPrinter != PdfCreatorPrinter))
                {
                    _logger.Debug("Current default printer is " + defaultPrinter);
                    _logger.Info("PDFCreator must be set temporarily as default printer");
                    if (_settingsProvider.Settings.CreatorAppSettings.AskSwitchDefaultPrinter)
                    {
                        if (!QuerySwitchDefaultPrinter())
                        {
                            return(false);
                        }
                    }
                    if (!_printerHelper.SetDefaultPrinter(PdfCreatorPrinter))
                    {
                        _logger.Error("PDFCreator could not be set as default printer");
                        return(false);
                    }

                    _logger.Debug("PDFCreator set as default printer");
                }

                return(_printCommands.PrintAll(_settingsProvider.Settings.ApplicationSettings.ConversionTimeout));
            }
            finally
            {
                if (requiresDefaultPrinter)
                {
                    _printerHelper.SetDefaultPrinter(defaultPrinter);
                    _logger.Debug("Default printer set back to " + defaultPrinter);
                }
                _printCommands = new PrintCommandGroup();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Prints all files in the list.
        /// </summary>
        /// <returns>true, if all files could be printed</returns>
        public bool PrintAll()
        {
            if (string.IsNullOrEmpty(PdfCreatorPrinter))
            {
                _logger.Error("No PDFCreator is installed.");
                return(false);
            }

            var requiresDefaultPrinter = _printCommands.RequiresDefaultPrinter;
            var defaultPrinter         = _printerHelper.GetDefaultPrinter();

            try
            {
                if (requiresDefaultPrinter)
                {
                    if (_settingsProvider.Settings.ApplicationSettings.AskSwitchDefaultPrinter)
                    {
                        if (!QuerySwitchDefaultPrinter())
                        {
                            return(false);
                        }
                    }

                    _printerHelper.SetDefaultPrinter(PdfCreatorPrinter);
                }

                return(_printCommands.PrintAll());
            }
            finally
            {
                if (requiresDefaultPrinter)
                {
                    _printerHelper.SetDefaultPrinter(defaultPrinter);
                }
                _printCommands = new PrintCommandGroup();
            }
        }