Exemplo n.º 1
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");
        }