Click or drag to resize

Sample Plugin

The report miner plugin is a .Net framework class library which implements the IPlugin interface:

C#
namespace Opait.ReportMiner.Api
{
    /// <summary>
    /// Interface defines a plugin for the report miner processing engine.
    /// </summary>
    public interface IPlugin
    {
        /// <summary>
        /// Called when a new job is about to start.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        ActionCode OnJobStartup(IEngine engine);

        /// <summary>
        /// Called when the source file for an export job has been initialized.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        /// <param name="document">The initialized PDF source document.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        ActionCode OnSourceReady(IEngine engine, IDocument document);

        /// <summary>
        /// Called when the export job has finished processing global fields.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        ActionCode OnGlobalsReady(IEngine engine);

        /// <summary>
        /// Called when a page is about to be parsed.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        /// <param name="page">The current page.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        ActionCode OnPageReady(IEngine engine, IPage page);

        /// <summary>
        /// Called when a record has been parsed and is ready for save.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        /// <param name="record">The parsed record.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        ActionCode OnRecordReady(IEngine engine, IRecord record);

        /// <summary>
        /// Called when the export job has finished processing.
        /// </summary>
        /// <param name="engine">The export engine.</param>
        void OnJobCompleted(IEngine engine);
    }
}

The plugin is dynamically loaded by the processing engine during runtime. The methods defined in the IPlugin interface are called by the engine as it processes the report file. The Plugin code can act on these callbacks and modify the processing workflow by returning certain action codes.

The return codes from each plugin callback is one of the following values:

C#
namespace Opait.ReportMiner.Api
{
    /// <summary>
    /// Action codes that are returned from plugin callbacks.
    /// </summary>
    public enum ActionCode
    {
        /// <summary>
        /// Continue with the normal processing of the workflow.
        /// </summary>
        Continue,

        /// <summary>
        /// Continue processing after skipping current operation. Used
        /// in page ready and record ready callbacks.
        /// </summary>
        Skip,

        /// <summary>
        /// Cancel the processing loop.
        /// </summary>
        Cancel,

        /// <summary>
        /// Fail the current job and move the report file to the failed folder.
        /// </summary>
        Fail,

        /// <summary>
        /// Processing is complete. Move the report file to the done folder.
        /// </summary>
        Done,

        /// <summary>
        /// Restart the processing of the report file with altered job parameters.
        /// </summary>
        Restart
    }
}

The callback functions may also include various other interfaces and classes related to the processing phase of the workflow. These are documented in the reference portion of this guide.

If you are only interested in one or two of the callbacks, then you could derive you class from the base Plugin class and override one or two virtual methods. This will save you from having to implement all functions of the interface. The following code illustrates this point by only overriding one callback function.

C#
using Opait.ReportMiner.Api;

namespace ReportMinerPlugin
{
    public class MyPlugin : Plugin
    {
        /// <summary>
        /// This function is called after the engine has processed a record
        /// and extracted all the data structures. We can perform all of our
        /// post processing on the data that is available through the Record class.
        /// </summary>
        /// <param name="engine">The processing engine.</param>
        /// <param name="record">The extracted record.</param>
        /// <returns>A code to instruct the engine on how to proceed.</returns>
        public override ActionCode OnRecordReady(IEngine engine, Record record)
        {
            // Custom processing code will go here.
            // Custom processing code will go here.
            // Custom processing code will go here.

            // Return the base class ActionCode which is normally
            // Continue. You may also return another ActionCode.
            return base.OnRecordReady(engine, record);
        }
    }
}