/// <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); } }
private void LoadAdf(string address, int pageCount) { if (!ExecutionData.Documents.Any()) { throw new ArgumentException("Document selection data resulted in 0 documents."); } // Clear the ADF before we do anything else AdfSimulator.Clear(address); // Iterate over the documents until we reach the desired page count DocumentCollectionIterator iterator = new DocumentCollectionIterator(CollectionSelectorMode.RoundRobin); for (int i = 0; i < pageCount; i++) { // Select and log document(s) Document document = iterator.GetNext(ExecutionData.Documents); ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(ExecutionData, document); ExecutionServices.DataLogger.Submit(documentLog); // Convert relative paths to absolute network paths string sharePath = ExecutionServices.FileRepository.AsInternal().GetDocumentSharePath(document); // Load it into the ADF AdfSimulator.LoadPage(address, sharePath); } }
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> /// Sets the HpcrActivityData runtime information. /// </summary> private void SetRuntimeData() { // Massage originator email with runtime information (if necessary) _runtimeOriginator = ReplaceCurrentUser(_runtimeOriginator); // Massage recipient with runtime information (if necessary) if (_runtimeRecipients.Any(x => x.Equals(Constants.RANDOM_DISTRIBUTION))) { var distributionNames = ProxyClient.GetDistributions(_pluginExecutionData.Servers.First().Address, _runtimeOriginator).Select(x => x.Title); var revisedRecipients = new Collection <string>(); foreach (var recipient in _runtimeRecipients) { revisedRecipients.Add(ReplaceRandomDistribution(recipient, distributionNames)); } _runtimeRecipients = revisedRecipients; } UpdateStatus("Fetching documents..."); //Cap at 2 documents max (chosen at random if more than 2 exist). if (_pluginExecutionData.Documents.Count > 2) { DocumentCollectionIterator iterator = new DocumentCollectionIterator(CollectionSelectorMode.ShuffledRoundRobin); string path1 = ExecutionServices.FileRepository.AsInternal().GetDocumentSharePath(iterator.GetNext(_pluginExecutionData.Documents)); string path2 = ExecutionServices.FileRepository.AsInternal().GetDocumentSharePath(iterator.GetNext(_pluginExecutionData.Documents)); _runtimeDocumentPaths.Add(path1); _runtimeDocumentPaths.Add(path2); } else { string path = ExecutionServices.FileRepository.AsInternal().GetDocumentSharePath(_pluginExecutionData.Documents.First()); _runtimeDocumentPaths = new Collection <string>(); _runtimeDocumentPaths.Add(path); } }
/// <summary> /// Executes this plug-in'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) { _executionData = executionData; _performanceLogger = new DeviceWorkflowLogger(_executionData); _activityData = _executionData.GetMetadata <DriverlessPrintingActivityData>(); var printer = executionData.Assets.OfType <PrintDeviceInfo>().FirstOrDefault(); if (printer == null) { return(new PluginExecutionResult(PluginResult.Skipped, "No assets available for execution.")); } if (!printer.Attributes.HasFlag(AssetAttributes.Printer)) { return(new PluginExecutionResult(PluginResult.Skipped, "The device has no print capability.")); } var address = printer.Address; var iteratorMode = _activityData.ShuffleDocuments ? CollectionSelectorMode.ShuffledRoundRobin : CollectionSelectorMode.Random; var documentIterator = new DocumentCollectionIterator(iteratorMode); var document = documentIterator.GetNext(executionData.Documents); FileInfo localFile = ExecutionServices.FileRepository.GetFile(document); if (_activityData.PinProtected) { AddPinProtection(localFile, _activityData.Pin); } if (_activityData.PrintMethod == PrintMethod.Random) { Random newRandom = new Random(4); var randomInt = newRandom.Next(0, 999) % 4; _activityData.PrintMethod = (PrintMethod)randomInt; } _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobBegin); UpdateStatus($"Printing {document.FileName} via {_activityData.PrintMethod}."); switch (_activityData.PrintMethod) { default: Print9100(address, localFile); break; case PrintMethod.Ftp: PrintFtp(address, "admin", printer.AdminPassword, localFile, true); break; case PrintMethod.Ipp: PrintIpp(address, localFile); break; case PrintMethod.Ews: PrintEws(address, printer.AdminPassword, localFile); break; } _performanceLogger.RecordEvent(DeviceWorkflowMarker.PrintJobEnd); _performanceLogger.RecordExecutionDetail(DeviceWorkflowMarker.PrintJobEnd, _activityData.PrintMethod.ToString()); ActivityExecutionDocumentUsageLog documentLog = new ActivityExecutionDocumentUsageLog(executionData, document); ExecutionServices.DataLogger.Submit(documentLog); if (_activityData.PrintJobSeparator) { UpdateStatus("Printing Job Separator."); PrintJobSeparator(address); } localFile.Delete(); return(_result); }
/// <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)); }