예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginExecutionData" /> class.
 /// </summary>
 /// <param name="metadata">An <see cref="XElement" /> containing plugin-specific XML metadata.</param>
 /// <param name="metadataVersion">The plugin-defined schema version of the XML metadata.</param>
 /// <param name="assets">The assets available for this plugin execution.</param>
 /// <param name="documents">The documents available for this plugin execution.</param>
 /// <param name="servers">The servers available for this plugin execution.</param>
 /// <param name="printQueues">The print queues available for this plugin execution.</param>
 /// <param name="environment">Information about the plugin execution environment.</param>
 /// <param name="context">Contextual/environmental information about this plugin execution.</param>
 /// <param name="retrySettings">Retry configuration for this plugin execution.</param>
 /// <param name="externalCredentials">External credentials used by this plugin execution.</param>
 /// <exception cref="ArgumentNullException"><paramref name="metadata" /> is null.</exception>
 public PluginExecutionData(XElement metadata, string metadataVersion, AssetInfoCollection assets, DocumentCollection documents, ServerInfoCollection servers, PrintQueueInfoCollection printQueues,
                            PluginEnvironment environment, PluginExecutionContext context, PluginRetrySettingDictionary retrySettings, ExternalCredentialInfoCollection externalCredentials)
     : base(metadata, metadataVersion)
 {
     _assets              = assets;
     _documents           = documents;
     _servers             = servers;
     _printQueues         = printQueues;
     _environment         = environment;
     _context             = context;
     _credential          = new Lazy <NetworkCredential>(CreateCredential);
     _retrySettings       = retrySettings;
     _externalCredentials = externalCredentials;
 }
        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));
        }
예제 #3
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));
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginExecutionData" /> class.
 /// </summary>
 /// <param name="metadata">An <see cref="XElement" /> containing plugin-specific XML metadata.</param>
 /// <param name="metadataVersion">The plugin-defined schema version of the XML metadata.</param>
 /// <param name="assets">The assets available for this plugin execution.</param>
 /// <param name="documents">The documents available for this plugin execution.</param>
 /// <param name="servers">The servers available for this plugin execution.</param>
 /// <param name="printQueues">The print queues available for this plugin execution.</param>
 /// <param name="environment">Information about the plugin execution environment.</param>
 /// <param name="context">Contextual/environmental information about this plugin execution.</param>
 /// <param name="retrySettings">Retry configuration for this plugin execution.</param>
 /// <exception cref="ArgumentNullException"><paramref name="metadata" /> is null.</exception>
 public PluginExecutionData(XElement metadata, string metadataVersion, AssetInfoCollection assets, DocumentCollection documents, ServerInfoCollection servers, PrintQueueInfoCollection printQueues,
                            PluginEnvironment environment, PluginExecutionContext context, PluginRetrySettingDictionary retrySettings)
     : this(metadata, metadataVersion, assets, documents, servers, printQueues, environment, context, retrySettings, new ExternalCredentialInfoCollection(new List <ExternalCredentialInfo>()))
 {
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrintManager"/> class.
 /// </summary>
 /// <param name="pluginExecData">The plugin execute data.</param>
 /// <param name="documentIterator">The document iterator.</param>
 public PrintManager(PluginExecutionData pluginExecData, DocumentCollectionIterator documentIterator)
 {
     _pluginData       = pluginExecData;
     _printQueues      = _pluginData.PrintQueues;
     _documentIterator = documentIterator;
 }