Пример #1
0
        /// <summary>
        /// Installs the remote printers.  For Citrix these printers need to be installed on the
        /// client ahead of time so that they are autocreated on the server.
        /// </summary>
        private void InstallRemotePrinters()
        {
            TraceFactory.Logger.Debug("Installing remote printers");

            // The manifest includes all queues required for the entire session.
            // Only install queues for activities that are part of this manifest.
            var activityIds = SystemManifest.Resources.SelectMany(n => n.MetadataDetails).Select(n => n.Id);
            List <RemotePrintQueueInfo> remotePrintQueues = activityIds.Select(n => SystemManifest.ActivityPrintQueues[n]).SelectMany(n => n.OfType <RemotePrintQueueInfo>()).ToList();

            List <Guid> createdQueues = new List <Guid>();

            foreach (RemotePrintQueueInfo queueInfo in remotePrintQueues)
            {
                // Only install the printer once by checking the printQueueId list.
                if (!createdQueues.Contains(queueInfo.PrintQueueId))
                {
                    createdQueues.Add(queueInfo.PrintQueueId);
                }

                string printerName = queueInfo.GetPrinterName();

                if (!PrintQueueInstaller.IsInstalled(printerName))
                {
                    ChangeMachineStatusMessage("Installing queue {0}".FormatWith(printerName));

                    // Install the print queue using administrator first to ensure the driver gets down
                    // without any authorization issues.  Sleep for a few seconds, then try to install
                    // the queue for the given user.  It should use the already installed driver and eliminate
                    // any issues in getting the driver down on the box.
                    CallPrintUi(printerName, credential: AdminCredential);
                    Thread.Sleep(1000);
                    CallPrintUi(printerName, credential: _credential);
                }

                // Display the printers that have been installed
                List <string> queues = PrintQueueController.GetPrintQueues().Select(n => n.ShareName).ToList();

                TraceFactory.Logger.Debug("Printers after Install: {0}{1}".FormatWith
                                          (
                                              Environment.NewLine,
                                              string.Join(Environment.NewLine, queues))
                                          );
            }
        }
Пример #2
0
        /// <summary>
        /// Installs a local print queue that points to this print device.
        /// </summary>
        /// <param name="installCheck">if set to <c>true</c> and the driver is already installed, then this will return.</param>
        /// <example>
        /// The example below shows how to install a driver and associated queue for a given local print
        /// device.  In this example, all drivers for a given distribution are first loaded, then one
        /// driver is chosen based on the system architecture.  In addition, a port is created that points
        /// to the target device.  The port, driver and platform type for the device are given to the print
        /// device object when then proceeds to install the driver and queue on the system.
        /// <code>
        /// // Load all drivers in the driver package located in the given directory
        /// PrintDeviceDriverCollection drivers = new PrintDeviceDriverCollection();
        /// drivers.LoadFromDirectory(@"\\DriverRepository\5.7.0\UPD\pcl6\winxp_vista_x64", includeAllArchitectures: true);
        /// if (drivers.Count() &gt; 0)
        /// {
        /// // Use the first driver from the distribution that matches this architecture
        /// PrintDeviceDriver driver = drivers.Where(x =&gt; x.Architecture == ProcessorArchitectureInfo.Current).FirstOrDefault();
        /// if (driver == null)
        /// {
        /// throw new InvalidOperationException("Device driver for this architecture not found in the distribution");
        /// }
        /// // Construct a port that the print queue will use when printing jobs.
        /// var port = StandardTcpIPPort.CreateRawPortData("15.198.212.221", portName: "IP_15.198.212.221", snmpEnabled: false);
        /// // Construct a local print device using all of the data built thus far.
        /// var device = new LocalPrintDevice(driver, port, DevicePlatform.Physical);
        /// // Install the device, which includes installing the driver and creating the queue
        /// device.Install();
        /// }
        /// </code></example>
        /// <remarks>This method goes through a series of calls to incrementally build the queue.  It starts by
        /// installing the driver if not already installed.  It then creates the printer port, then
        /// sets up the configuration file (CFM) if there is one, then applies the printer shortcut
        /// if it exists.  Then it adds the actual print queue, followed by the setup of client rendering
        /// and then configures the shared queue setting.  It then waits until all these steps are complete.</remarks>
        public void Install()
        {
            if (PrintQueueInstaller.IsInstalled(QueueName))
            {
                TraceFactory.Logger.Info("Print queue is already installed");
                return;
            }

            // Install the print driver
            CopyDriver();
            DriverInstaller.Install(_driver);

            // Create the Printer Port
            CreatePort();

            // Create the print queue
            CreatePrintQueue();

            // Wait until all the queue creation activity has completed.
            PrintQueueInstaller.WaitForInstallationComplete(QueueName, _driver.Name);
        }
        /// <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");
        }
Пример #4
0
        private void CreatePrintQueue()
        {
            //no shortcut selected, use winspool to install
            if (string.IsNullOrEmpty(_configFile))
            {
                PrintQueueInstaller.CreatePrintQueue(QueueName, _driver.Name, _portName, _driver.PrintProcessor);
            }
            else
            {
                //the installer is always in the driver directory
                string installerPath = Path.GetDirectoryName(_driver.InfPath).Trim('\\') + "\\install.exe";
                if (!File.Exists(installerPath))
                {
                    throw new PrintQueueInstallationException("UPD Installer missing");
                }

                //derive the printer IP from the Portname
                string printerIp = _portName.Substring(_portName.LastIndexOf("_") + 1);

                //use the command line arguments to install the print queue
                string cfm;
                if (string.IsNullOrEmpty(_defaultShortcut) || _defaultShortcut.Equals("None"))
                {
                    cfm = _configFile;
                }
                else
                {
                    cfm = BuildShortcut();
                }

                FileInfo installer = new FileInfo(installerPath);
                FileInfo cfmFile   = new FileInfo(cfm);
                PrintQueueInstaller.InstallUpdPrinter(installer, QueueName, printerIp, cfmFile);
            }
            TraceFactory.Logger.Info("Adding print queue complete.");
        }