/// <summary>
        /// Determines if the print job is rendered on the client or on the server.
        /// </summary>
        /// <param name="queues">The list of queues.</param>
        /// <returns>
        ///   <c>true</c> if Render Print Jobs on Client is set for the specified queue name; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">queues</exception>
        public SerializableDictionary <string, string> GetJobRenderLocation(Collection <string> queues)
        {
            if (queues == null)
            {
                throw new ArgumentNullException("queues");
            }

            SerializableDictionary <string, string> values = new SerializableDictionary <string, string>();

            foreach (string queueName in queues)
            {
                PrintQueue queue    = PrintQueueController.GetPrintQueue(queueName);
                var        location = PrintQueueController.GetJobRenderLocation(queue);
                values.Add(queueName, location.ToString());
                TraceFactory.Logger.Debug("Render On Client {0}:{1}".FormatWith(queueName, location));
            }

            return(values);
        }
Example #2
0
        private MonitoredQueueInfoCache GetQueueInfo(string queueName)
        {
            MonitoredQueueInfoCache cachedInfo = null;

            try
            {
                //Try to retrieve from the cache
                if (!_cache.TryGetValue(queueName, out cachedInfo))
                {
                    cachedInfo = new MonitoredQueueInfoCache(queueName)
                    {
                        PrintServer   = Environment.MachineName,
                        PrintServerOS = Environment.OSVersion.ToString()
                    };
                    _cache.Add(queueName, cachedInfo);
                }

                // Refresh queue data if older than 5 minutes
                if (cachedInfo.QueueSettingsRetrieved < DateTime.Now.AddMinutes(-5))
                {
                    PrintQueue queue = PrintQueueController.GetPrintQueue(queueName);
                    cachedInfo.Refresh(queue);

                    PrintJobRenderLocation location = PrintQueueController.GetJobRenderLocation(queue);
                    if (location != PrintJobRenderLocation.Unknown)
                    {
                        cachedInfo.RenderOnClient = (location == PrintJobRenderLocation.Client);
                    }
                    else
                    {
                        cachedInfo.RenderOnClient = null;
                    }

                    cachedInfo.QueueSettingsRetrieved = DateTime.Now;
                }
            }
            catch (Win32Exception ex)
            {
                TraceFactory.Logger.Error("Unable to get queue data for {0}".FormatWith(queueName), ex);
            }

            return(cachedInfo);
        }
        /// <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");
        }
Example #4
0
        /// <summary>
        /// Sets the client rendering mode for Vista and above.
        /// </summary>
        public void EnableClientRendering()
        {
            PrintQueue queue = PrintQueueController.GetPrintQueue(QueueName);

            PrintQueueController.SetJobRenderLocation(queue, IsRenderedOnClient ? PrintJobRenderLocation.Client : PrintJobRenderLocation.Server);
        }
Example #5
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));
        }