Пример #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>
        /// Retrieves the list of installed ports on this machine and pairs the port data with it's corresponding queue information.
        /// </summary>
        /// <returns></returns>
        private List <QueuePortData> GetQueueData()
        {
            Collection <StandardTcpIPPort> ports  = StandardTcpIPPort.InstalledPorts;
            List <QueuePortData>           result = new List <QueuePortData>();

            _installedPorts = new Dictionary <QueuePortData, StandardTcpIPPort>();

            StandardTcpIPPort port = null;

            foreach (PrintQueue queue in PrintQueueController.GetPrintQueues())
            {
                QueuePortData data = new QueuePortData(queue.Name, queue.QueuePort.Name);
                port = ports.Where(p => p.PortName == data.PortName).FirstOrDefault();
                if (port != null) //Only return the queues that have a port.
                {
                    data.PortAddress = port.Address;
                    data.PortNumber  = unchecked ((int)port.PortNumber);
                    result.Add(data);
                    _installedPorts.Add(data, port);
                }
            }

            return(result);
        }
Пример #3
0
        private static PrintQueue GetCitrixPrintQueue(PrintQueueInfo printQueueInfo)
        {
            // Special handling for Citrix session queues - they are connections to a remote server,
            // but don't show up when querying the local server for a list of queues.
            // Connect to the queue directly by parsing the queue name
            LocalPrintQueueInfo localPrintQueueInfo = printQueueInfo as LocalPrintQueueInfo;

            if (localPrintQueueInfo != null)
            {
                LogDebug("Attempting to parse Citrix session queue.");
                var match = Regex.Match(localPrintQueueInfo.QueueName, @"^\\\\([\S\s]+)\\([\S\s]+)$");
                if (match.Success)
                {
                    LogDebug("Parse success.");
                    var serverName = match.Groups[1];
                    var queueName  = match.Groups[2];

                    LogDebug($"Server Name: {serverName}");
                    LogDebug($"Queue Name: {queueName}");

                    PrintServer server = new PrintServer($@"\\{serverName}");
                    return(new PrintQueue(server, localPrintQueueInfo.QueueName));
                }
                else
                {
                    LogDebug("Parse failure.");
                }
            }

            // When Citrix auto-generates a print queue on the Citrix server, it creates a queue with the
            // same name as the local print queue on the client machine, but appends some session information
            // to the end.  To find the real name of the print queue on the Citrix server, we need to
            // find a print queue installed on the system that starts with the same text generated by the base class.
            LogDebug($"Looking for {printQueueInfo.QueueName}");

            List <string> queueNames = PrintQueueController.GetPrintQueues().Select(n => n.FullName).ToList();
            string        clientName = Environment.GetEnvironmentVariable("CLIENTNAME");

            RemotePrintQueueInfo remotePrintQueueInfo = printQueueInfo as RemotePrintQueueInfo;

            if (remotePrintQueueInfo != null)
            {
                string citrixQueueName = queueNames.FirstOrDefault(
                    n => n.StartsWith(remotePrintQueueInfo.QueueName, StringComparison.OrdinalIgnoreCase) &&
                    n.Contains(remotePrintQueueInfo.ServerHostName, StringComparison.OrdinalIgnoreCase) &&
                    n.Contains(clientName, StringComparison.OrdinalIgnoreCase));

                if (citrixQueueName != null)
                {
                    LogDebug($"Found Citrix queue {citrixQueueName}");
                    return(PrintQueueController.GetPrintQueue(citrixQueueName));
                }
                else
                {
                    LogDebug($"Did not find mapped queue.  Looking for directly attached queue.");
                    return(PrintQueueController.GetPrintQueue(remotePrintQueueInfo.GetPrinterName()));
                }
            }

            DynamicLocalPrintQueueInfo dynamicPrintQueueInfo = printQueueInfo as DynamicLocalPrintQueueInfo;

            if (dynamicPrintQueueInfo != null)
            {
                string citrixQueueName = queueNames.FirstOrDefault(
                    n => n.StartsWith(dynamicPrintQueueInfo.QueueName, StringComparison.OrdinalIgnoreCase) &&
                    n.Contains(clientName, StringComparison.OrdinalIgnoreCase));
                if (citrixQueueName != null)
                {
                    LogDebug($"Found Citrix queue {citrixQueueName}");
                    return(PrintQueueController.GetPrintQueue(citrixQueueName));
                }
                else
                {
                    throw new PrintQueueNotFoundException($"Could not find mapped queue for {dynamicPrintQueueInfo.QueueName}");
                }
            }

            // Default to the usual behavior
            return(PrintQueueController.Connect(printQueueInfo));
        }