/// <summary>
        /// Installs the PrintDriver With LPR Queue Details as in activity Data
        /// </summary>
        private void InstallPrintDriverWithLPRQueue()
        {
            DriverDetails driver = CreateDriver(_activityData.PrintDriver, _pluginSettings["PrintDriverServer"]);

            UpdateStatus($"Installing driver from {driver.InfPath}");
            ExecutionServices.SystemTrace.LogDebug($"Installing driver from {driver.InfPath}");
            DriverInstaller.Install(driver);
            UpdateStatus("Driver Installation Completed");

            UpdateStatus(string.Format("Creating LPR Port connecting to HPAC Server :{0}, QueueName : {1}", _hpacServerIP, _activityData.LprQueueName));
            ExecutionServices.SystemTrace.LogDebug($"Creating LPR Port connecting to HPAC Server :{_hpacServerIP}, QueueName : {_activityData.LprQueueName}");
            string portName = string.Format("_IP {0}_{1}", _hpacServerIP, _activityData.LprQueueName);

            PrintPortManager.AddLprPort(portName, LprPrinterPortInfo.DefaultPortNumber, _hpacServerIP, _activityData.LprQueueName);
            UpdateStatus("Port Creation Completed");

            UpdateStatus(string.Format("Creating LocalPrintDevice with Driver :{0} and port : {1}", driver.Name, portName));
            ExecutionServices.SystemTrace.LogDebug(string.Format("Creating LocalPrintDevice with Driver :{0} and port : {1}", driver.Name, portName));

            string queueName = string.Format("{0} ({1})", driver.Name, portName);

            if (!PrintQueueInstaller.IsInstalled(queueName))
            {
                PrintQueueInstaller.CreatePrintQueue(queueName, driver.Name, portName, driver.PrintProcessor);
                PrintQueueInstaller.WaitForInstallationComplete(queueName, driver.Name);
                UpdateStatus("Print Device Installation Completed");
            }

            PrintQueue queue = PrintQueueController.GetPrintQueue(queueName);

            if (_activityData.IsDefaultPrinter)
            {
                PrintQueueController.SetDefaultQueue(queue);
                UpdateStatus("Setting the Installed Print Device as a default Print Device");
            }

            ConfigurePrinterAttributes(queue);
            UpdateStatus("Printer Attributes Configuration Completed");
        }
        /// <summary>
        /// Prints the specified file to the specified print queue.
        /// </summary>
        /// <param name="file">The file to print.</param>
        /// <param name="printQueue">The <see cref="PrintQueue" /> to print the file to.</param>
        /// <param name="printVerb">The <see cref="PrintVerb" /> to use.</param>
        /// <returns>A <see cref="FilePrintResult" /> object representing the outcome of the print operation.</returns>
        /// <exception cref="FilePrintException">An error occurred while printing the file.</exception>
        protected FilePrintResult PrintFile(FileInfo file, PrintQueue printQueue, PrintVerb printVerb)
        {
            OnStatusChanged($"Printing document using the {printVerb} verb.");

            // If the verb being used is the Print verb, the default printer must be changed.
            if (printVerb == PrintVerb.Print)
            {
                PrintQueueController.SetDefaultQueue(printQueue);
            }

            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName        = file.FullName,
                Verb            = printVerb.ToString().ToLower(CultureInfo.CurrentCulture),
                Arguments       = string.Format("\"{0}\"", printQueue.FullName),
                CreateNoWindow  = true,
                WindowStyle     = ProcessWindowStyle.Hidden,
                UseShellExecute = true,
                ErrorDialog     = false
            };

            return(PrintFileViaProcess(file, processStartInfo));
        }
Beispiel #3
0
        /// <summary>
        /// Installs the print queue
        /// </summary>
        private Status InstallPrintQueue(PluginExecutionData executionData)
        {
            if (executionData.PrintQueues.Count == 0)
            {
                return(Status.Skipped);
            }


            _printQueueInfo    = executionData.PrintQueues.First();
            _defaultPrintQueue = PrintQueueController.Connect(_printQueueInfo);

            // Log the device/server that was used for this job, if one was specified
            LogDevice(executionData, _printQueueInfo);

            //To check count of paper size,type and trays
            try
            {
                int paperSize  = GetCountFromRegistry("MediaSize");
                int paperType  = GetCountFromRegistry("MediaType");
                int inputtrays =
                    ((string[])
                     Registry.LocalMachine.OpenSubKey(
                         $@"System\CurrentControlSet\Control\Print\Printers\{ (object)_defaultPrintQueue.FullName}\PrinterDriverData").GetValue("InputSlot")).Count(
                        x => x.StartsWith("Tray", StringComparison.OrdinalIgnoreCase));

                ExecutionServices.SystemTrace.LogInfo($"Paper Sizes available for { (object)_defaultPrintQueue.FullName} are { (object)paperSize}");
                ExecutionServices.SystemTrace.LogInfo($"Paper Types available for { (object)_defaultPrintQueue.FullName} are { (object)paperType}");
                ExecutionServices.SystemTrace.LogInfo($"Trays available  for {_defaultPrintQueue.Name}  are {inputtrays}");
            }
            catch (NullReferenceException nullRefEx)
            {
                ExecutionServices.SystemTrace.LogInfo($"Something went wrong when trying to read values from registry, Please manually validate the supported paper sizes, types and trays supported. Exception: { (object)nullRefEx.Message}");
            }
            if (ValidatePrintingShortcut(_defaultPrintQueue.FullName))
            {
                try
                {
                    //this is a fix for defaultprintqueue.connected not working in windows vista due to UAC
                    foreach (string printerName in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                    {
                        if (_defaultPrintQueue.FullName.Equals(printerName))
                        {
                            if (_activityData.IsDefaultPrinter)
                            {
                                PrintQueueController.SetDefaultQueue(_defaultPrintQueue);
                            }

                            ExecutionServices.SystemTrace.LogDebug($"Printer installed: { (object)printerName}");
                            return(Status.Passed);
                        }
                    }
                }
                catch
                {
                    return(Status.Failed);
                }
            }
            else
            {
                ExecutionServices.SystemTrace.LogInfo(
                    $"Failed to install the device: {_printQueueInfo.AssociatedAssetId}");
                return(Status.Failed);
            }

            return(Status.Passed);
        }