Example #1
0
        /// <summary>
        /// Print Job Sepearator method will be called from non Printing Plugins.
        /// </summary>
        /// <param name="executionData"></param>
        public void PrintJobSeparator(PluginExecutionData executionData)
        {
            PrintQueueInfo printQueueInfo = executionData.PrintQueues.FirstOrDefault();
            PrintQueue     printQueue     = printQueue = PrintQueueController.Connect(printQueueInfo);

            PrintJobSeparator(executionData, printQueue);
        }
        /// <summary>
        /// Exexutes the Print Job
        /// </summary>
        /// <returns></returns>
        private PluginExecutionResult ExecutePrintJob()
        {
            PluginExecutionResult printResult = new PluginExecutionResult(PluginResult.Passed);

            try
            {
                PrintQueue     defaultPrintQueue;
                PrintQueueInfo printQueueInfo = ExecutionData.PrintQueues.GetRandom();
                UpdateStatus("Print Activity: Retrieving print queue for " + printQueueInfo.QueueName);
                defaultPrintQueue = PrintQueueController.Connect(printQueueInfo);
                PrintingEngine engine = new PrintingEngine();

                // Select a documents to print
                DocumentCollectionIterator documentIterator = new DocumentCollectionIterator(CollectionSelectorMode.ShuffledRoundRobin);
                Document document = documentIterator.GetNext(ExecutionData.Documents);

                // Download the document and log the starting information for the print job
                Guid     jobId     = SequentialGuid.NewGuid();
                FileInfo localFile = ExecutionServices.FileRepository.GetFile(document);

                UpdateStatus($"Print Activity: Printing {localFile.Name} to {defaultPrintQueue.FullName}");
                var result = engine.Print(localFile, defaultPrintQueue);
                UpdateStatus($"Print Activity: Finished printing {localFile.Name}");

                return(printResult);
            }
            catch (Exception genericException)
            {
                printResult = new PluginExecutionResult(PluginResult.Failed, genericException.ToString());
                ExecutionServices.SystemTrace.LogError(genericException.ToString());
                return(printResult);
            }
        }
Example #3
0
 public PrintQueueRow(PrintQueueInfo queue)
 {
     QueueName   = queue.QueueName;
     PrintServer = "Client";
     QueueType   = "Local";
     Device      = queue.AssociatedAssetId;
 }
Example #4
0
 private static void LogDevice(PluginExecutionData executionData, PrintQueueInfo printer)
 {
     if (!string.IsNullOrEmpty(printer.AssociatedAssetId))
     {
         var log = new ActivityExecutionAssetUsageLog(executionData, printer.AssociatedAssetId);
         ExecutionServices.DataLogger.Submit(log);
     }
 }
Example #5
0
        private static void LogServer(PluginExecutionData executionData, PrintQueueInfo printQueue)
        {
            RemotePrintQueueInfo remoteQueue = printQueue as RemotePrintQueueInfo;

            if (remoteQueue != null)
            {
                var log = new ActivityExecutionServerUsageLog(executionData, remoteQueue.ServerHostName);
                ExecutionServices.DataLogger.Submit(log);
            }
        }
Example #6
0
        private void ExecuteHandler()
        {
            ExecutionServices.SystemTrace.LogDebug($"Plugin exec data print queues = {_printQueues.Count}");
            foreach (var x in _printQueues)
            {
                ExecutionServices.SystemTrace.LogDebug($"Queue={x.QueueName}");
            }

            // Check to make sure we have something in the pool...
            if (_printQueues.Count == 0)
            {
                var msg = "None of the selected print queues are available.";

                ExecutionServices.SystemTrace.LogDebug(msg);
                throw new PrintQueueNotAvailableException(msg);
            }

            // Pick a print queue and log the device/server if applicable
            PrintQueueInfo queueInfo = _printQueues.GetRandom();

            LogDevice(_pluginData, queueInfo);
            LogServer(_pluginData, queueInfo);

            // Connect to the print queue
            ExecutionServices.SystemTrace.LogDebug($"Connecting to queue: {queueInfo.QueueName}");
            PrintQueue printQueue = PrintQueueController.Connect(queueInfo);

            _serverName = printQueue.HostingPrintServer.Name.TrimStart('\\');
            ExecutionServices.SystemTrace.LogDebug($"Connected to queue: {printQueue.FullName}");

            // Select a document to print
            Document document = _documentIterator.GetNext(_pluginData.Documents);
            ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(_pluginData, document);

            ExecutionServices.DataLogger.Submit(documentLog);

            // Download the document and log the starting information for the print job
            Guid              jobId     = SequentialGuid.NewGuid();
            FileInfo          localFile = ExecutionServices.FileRepository.GetFile(document);
            PrintJobClientLog log       = LogPrintJobStart(_pluginData, localFile, printQueue, jobId);

            // Print the job
            PrintingEngineResult result = _engine.Print(localFile, printQueue, jobId);

            _printJobId = result.UniqueFileId;

            if (result == null)
            {
                throw new FilePrintException($"Failed to print {localFile}.");
            }

            // Log the ending information
            LogPrintJobEnd(log, result);
            ExecutionServices.SystemTrace.LogDebug("Controller execution completed");
        }
        /// <summary>
        /// Executes this plugin's workflow using the specified <see cref="PluginExecutionData" />.
        /// </summary>
        /// <param name="executionData">The execution data.</param>
        /// <returns>A <see cref="PluginExecutionResult" /> indicating the outcome of the execution.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            try
            {
                DriverConfigurationPrintActivityData data = executionData.GetMetadata <DriverConfigurationPrintActivityData>();
                PrintQueueInfo item = executionData.PrintQueues.GetRandom();
                _engine.ConfigureDriverSettings(data.PrinterPreference, item.QueueName);

                return(_engine.ProcessActivity(executionData));
            }
            catch (Exception ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex));
            }
        }
            public PrintQueueRow(PrintQueueInfo queue)
            {
                QueueName   = queue.QueueName;
                PrintServer = "Client";
                QueueType   = "Local";
                Device      = queue.AssociatedAssetId;

                RemotePrintQueueInfo remoteQueue = queue as RemotePrintQueueInfo;

                if (remoteQueue != null)
                {
                    PrintServer = remoteQueue.ServerHostName;
                    QueueType   = "Remote";
                }
            }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            if (!_setupDone)
            {
                AddOfficeRegistryEntries();
                _setupDone = true;
            }

            _mailMergeData            = executionData.GetMetadata <MailMergeActivityData>();
            _printQueueInfoCollection = executionData.PrintQueues;
            _userName  = executionData.Credential.UserName;
            _sessionId = executionData.SessionId;

            _tempDataSourceFileName = Path.Combine(Path.GetTempPath(), $"{_userName}_{Guid.NewGuid()}_tempDataSourceFile.doc");

            //install the local printer or remote print queue
            // Set up the list of print devices
            if (_printQueueInfoCollection.Count == 0)
            {
                return(new PluginExecutionResult(PluginResult.Skipped));
            }

            PrintQueueInfo printQueueInfo = _printQueueInfoCollection.First();
            PrintQueue     printQueue     = PrintQueueController.Connect(printQueueInfo);

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


            if (_mailMergeData.PrintJobSeparator)
            {
                PrintTag(printQueue, executionData);
            }

            _defaultPrintQueue = printQueue.FullName;

            //generate the mail merge doc and print it to default print queue
            try
            {
                ExecutionServices.CriticalSection.Run(new Framework.Synchronization.LocalLockToken(printQueueInfo.AssociatedAssetId, new TimeSpan(0, 0, 30), new TimeSpan(0, 5, 0)), PrintMailMerge);
            }
            catch (Exception ex)
            {
                return(new PluginExecutionResult(PluginResult.Failed, ex.Message));
            }

            return(new PluginExecutionResult(PluginResult.Passed));
        }
Example #10
0
        /// <summary>
        /// Connects to and returns a <see cref="PrintQueue" /> object represented by the specified <see cref="PrintQueueInfo" />.
        /// </summary>
        /// <param name="printQueueInfo">The <see cref="PrintQueueInfo" /> specifying the print queue.</param>
        /// <returns>A <see cref="PrintQueue" /> object.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="printQueueInfo" /> is null.</exception>
        /// <exception cref="PrintQueueNotFoundException">The queue specified by <paramref name="printQueueInfo" /> could not be found.</exception>
        public static PrintQueue Connect(PrintQueueInfo printQueueInfo)
        {
            if (printQueueInfo == null)
            {
                throw new ArgumentNullException(nameof(printQueueInfo));
            }

            if (printQueueInfo is RemotePrintQueueInfo remotePrintQueueInfo)
            {
                string printerName = remotePrintQueueInfo.GetPrinterName();
                ConnectToRemoteQueue(printerName);
                return(GetPrintQueue(printerName));
            }
            else
            {
                return(GetPrintQueue(printQueueInfo.QueueName));
            }
        }
Example #11
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="executionData">
        /// The execution data.
        /// </param>
        /// <returns>
        /// The <see cref="PluginExecutionResult"/>.
        /// </returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            CopyData       data        = executionData.GetMetadata <CopyData>(ConverterProvider.GetMetadataConverters());
            PrintQueueInfo item        = executionData.PrintQueues.GetRandom();
            ScanOptions    scanOptions = new ScanOptions()
            {
                LockTimeouts = data.LockTimeouts,
                PageCount    = data.PageCount
            };

            if (data.PrintJobSeparator)
            {
                _engine.PrintJobSeparator(executionData);
            }
            var manager = new CopyManager(executionData, scanOptions);

            manager.ActivityStatusChanged += UpdateStatus;
            manager.DeviceSelected        += UpdateDevice;
            return(manager.RunScanActivity());
        }
Example #12
0
            public PrintQueueRow(PrintQueueInfo queue)
            {
                QueueName   = queue.QueueName;
                PrintServer = "Client";
                QueueType   = "Local";
                Device      = queue.AssociatedAssetId;

                RemotePrintQueueInfo remoteQueue = queue as RemotePrintQueueInfo;

                if (remoteQueue != null)
                {
                    PrintServer = remoteQueue.ServerHostName;
                    QueueType   = "Remote";
                }

                DynamicLocalPrintQueueInfo dynamicLocalQueue = queue as DynamicLocalPrintQueueInfo;

                if (dynamicLocalQueue != null)
                {
                    QueueName = string.Format("{0}\\{1} on {2}", dynamicLocalQueue.PrintDriver.PackageName, dynamicLocalQueue.PrintDriver.DriverName, dynamicLocalQueue.AssociatedAssetId);
                }
            }
Example #13
0
        /// <summary>
        /// Defines and executes the PluginFax workflow.
        /// </summary>
        /// <param name="executionData">Information used in the execution of this workflow.</param>
        /// <returns>The result of executing the workflow.</returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _faxActivityData = executionData.GetMetadata <FaxActivityData>(ConverterProvider.GetMetadataConverters());
            PrintQueueInfo item = executionData.PrintQueues.GetRandom();

            if (_faxActivityData.PrintJobSeparator)
            {
                _engine.PrintJobSeparator(executionData);
            }
            FaxScanManager manager;

            if (string.IsNullOrWhiteSpace(_faxActivityData.DigitalSendServer))
            {
                manager = new FaxScanManager(executionData);
            }
            else
            {
                manager = new FaxScanManager(executionData, _faxActivityData.DigitalSendServer);
            }

            manager.ActivityStatusChanged += UpdateStatus;
            manager.DeviceSelected        += UpdateDevice;
            return(manager.RunScanActivity());
        }
Example #14
0
 private LocalPrintQueueRow(PrintQueueInfo queue)
 {
     PrintQueueInfo = queue;
     Device         = queue.AssociatedAssetId;
 }
Example #15
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);
        }
Example #16
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));
        }
Example #17
0
        /// <summary>
        /// Start the activity.
        /// </summary>
        /// <param name="executionData">Serialized activity data.</param>
        public PluginExecutionResult ProcessActivity(PluginExecutionData executionData)
        {
            PrintingActivityData     data        = executionData.GetMetadata <PrintingActivityData>();
            PrintQueueInfoCollection printQueues = executionData.PrintQueues;

            // Initialize the document iterator, if it is not already created
            if (_documentIterator == null)
            {
                CollectionSelectorMode mode = data.ShuffleDocuments ? CollectionSelectorMode.ShuffledRoundRobin : CollectionSelectorMode.RoundRobin;
                _documentIterator = new DocumentCollectionIterator(mode);
            }

            // Check to make sure we have something in the pool...
            if (printQueues.Count == 0)
            {
                return(new PluginExecutionResult(PluginResult.Skipped, "None of the selected print queues are available.", "No available print queues."));
            }

            // Select a print queue and log the device/server if applicable
            PrintQueueInfo printQueueInfo = printQueues.GetRandom();

            LogDevice(executionData, printQueueInfo);
            LogServer(executionData, printQueueInfo);

            // Get the corresponding system print queue
            LogDebug(string.Format("Retrieving print queue for {0}", printQueueInfo.QueueName));
            PrintQueue printQueue;

            if (ExecutionServices.SessionRuntime.AsInternal().IsCitrixEnvironment())
            {
                printQueue = GetCitrixPrintQueue(printQueueInfo);
            }
            else
            {
                printQueue = PrintQueueController.Connect(printQueueInfo);
            }

            LogDebug(string.Format("Found queue: {0}", printQueue.FullName));

            if (data.JobThrottling)
            {
                // Make sure that there is enough room in the print queue for this job.
                if (!CheckJobCountInQueue(printQueue, data.MaxJobsInQueue))
                {
                    // Skip the activity.
                    return(new PluginExecutionResult(PluginResult.Skipped, "Print Queue cannot accept any more jobs.", "Print queue throttling."));
                }
            }

            LogDebug("Executing print controller");
            if (data.PrintJobSeparator)
            {
                PrintTag(printQueue, executionData);
            }

            // Select a document to print
            Document document = _documentIterator.GetNext(executionData.Documents);
            ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(executionData, document);

            ExecutionServices.DataLogger.Submit(documentLog);

            // Download the document and log the starting information for the print job
            Guid              jobId     = SequentialGuid.NewGuid();
            FileInfo          localFile = ExecutionServices.FileRepository.GetFile(document);
            PrintJobClientLog log       = LogPrintJobStart(executionData, localFile, printQueue, jobId);

            // Print the job
            var engine = new Print.PrintingEngine();

            engine.StatusChanged += (s, e) => StatusChanged?.Invoke(s, e);
            var result = engine.Print(localFile, printQueue, jobId);

            // Log the ending information
            LogPrintJobEnd(log, result);
            LogDebug("Controller execution completed");
            return(new PluginExecutionResult(PluginResult.Passed));
        }