 | CTInterfaceOnBatchOperationTemplatePreLoad Event |
Allows dynamic changes for Batch Operation Templates, and to attach a tag after the Template name.
Note that if you are applying dynamic changes, user might save those changes to the object.
Tag is useful to indicate for user that an add-in is attached for handling specific template(s). Othwise this
event is very useful for pre-mapping Template IDs for possible
OnBatchOperationsLaunched and
OnBatchOperationsCompleted events.
Namespace: ATR.CT.CTInterfaceAssembly: CTInterface (in CTInterface.dll) Version: 25.0
Syntax
Example
This example shows how to bind scripts to specific Batch Opearation Templates in order to collect
and post-process all converted documents of that template when the operation has been finished.
This example requires a template named 'My Template' and will attach [Report] -tag on it.
Language: C#
Class name: BatchOpDocCollector
using ATR.CT.CTInterface;
using CTExtensions;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Example
{
public class BatchOpDocCollector : CTExtension
{
static readonly string ATTACH_TO_TEMPLATE = "My Template";
private bool mbCollectDocuments = false;
private List<string> moCollection;
private int miBatchTemplateID = 0;
public override bool Hook(CTInterface oCTInterface)
{
bool bHooked = false;
if (oCTInterface != null)
{
oCTInterface.OnBatchOperationTemplatePreLoad += HandleBatchOperationTemplatePreLoad;
oCTInterface.OnBatchOperationsLaunched += HandleBatchOperationsLaunched;
oCTInterface.NotifyDialogAccess += HandleNotifyDialogAccess;
oCTInterface.OnBatchOperationsCompleted += HandleBatchOperationsCompleted;
oCTInterface.OnPostFileConversion += HandlePostFileConversion;
bHooked = true;
}
return bHooked;
}
public override void UnHook(CTInterface oCTInterface)
{
if (oCTInterface != null)
{
oCTInterface.OnBatchOperationTemplatePreLoad -= HandleBatchOperationTemplatePreLoad;
oCTInterface.OnBatchOperationsLaunched -= HandleBatchOperationsLaunched;
oCTInterface.NotifyDialogAccess -= HandleNotifyDialogAccess;
oCTInterface.OnBatchOperationsCompleted -= HandleBatchOperationsCompleted;
oCTInterface.OnPostFileConversion -= HandlePostFileConversion;
}
}
private void Init()
{
moCollection = new List<string>();
mbCollectDocuments = false;
miBatchTemplateID = 0;
}
private void HandleNotifyDialogAccess(object sender, NotifyDialogAccessArgs e)
{
if (e.Dialog == DialogAccess.PrintAndConvert)
Init();
}
private void HandleBatchOperationTemplatePreLoad(object sender, CTInterface.BatchOperationTemplatePreLoadArgs e)
{
if (string.Compare(e.BatchOpTemplate.Name, ATTACH_TO_TEMPLATE, true) == 0)
{
e.Tag = "Report";
miBatchTemplateID = e.BatchOpTemplate.ID;
}
}
private void HandleBatchOperationsLaunched(object sender, CTInterface.BatchOperationsLaunchedArgs e)
{
if (e.BatchOpTemplateID != 0 && e.BatchOpTemplateID == miBatchTemplateID)
mbCollectDocuments = true;
else
mbCollectDocuments = false;
}
private void HandlePostFileConversion(object sender, CTInterface.PostFileConversionArgs e)
{
if (mbCollectDocuments)
{
if (moCollection.Find(x => string.Compare(x, e.TargetFileName, true) == 0) == null)
moCollection.Add(e.TargetFileName);
}
}
private void HandleBatchOperationsCompleted(object sender, CTInterface.BatchOperationsCompletedArgs e)
{
if (mbCollectDocuments)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("The process resulted in following converted documents:");
sb.AppendLine();
foreach (var file in moCollection)
{
sb.AppendLine("- " + file);
}
MessageBox.Show(sb.ToString());
Init();
}
}
}
}
Revision HistoryDate | Version | Description |
---|
- | 2021 SP1 | First Release |
See Also