Plugin Execution Flow
The IPublishPostProcess plugins share a number of characteristics and an execution flow.
Basic Terms And Definitions
- Plugin
- A custom module which execution can be triggered by the certain actions (like Publish).
- Action
- The main operation that triggers plugin execution.
- Sequence
- An indication that the plugins run in the order they are defined in the configuration file. Publish plugins are not executed as part of the transaction. If the plugin fails with an exception, the publish fails.
- Plugin Engine
- An application module that is responsible for executing plugins.
- Plugin Category
-
A logical category which defines when a plugin will be executed and what it is allowed to do. Currently the only supported category is the
PublishPostProcesscategory. - PublishPostProcess Plugins
-
A category of plugins that can be executed after the content files (topics, images, etc.) and their metadata are dropped by the publish export process. The plugins are run by the .NET
Publishbackground task.
Data access
These plugins are run after the topics, illustrations, etc. have been put on the file system by the PublishService during a Publish operation.
Via the plugin context, the plugin has access to:
- the object that was used to start the publish
- information of where the content and metadata files were exported, so they can be accessed
- the condition set used
- output format fields
- whether the publish needs to compare versions
- whether the publish needs to combine multiple languages into one output result
Plugin Execution Flow
When executing plugins, plugin engine goes through the following stages:
- Create plugin instances
- Filter the publish plugin configuration by applying the conditions to get the list of plugins. As a result, there should be no more than 1 postprocess elements. If there are no postprocess elements, plugins don't run. If there is more than one, an exception is thrown.
- Create plugin instances. Plugin engine uses the value of the handler attribute of the plugin element specified in the configuration to find matching plugin implementation.
- Initialize all plugins. Plugin engine makes sure every plugin is initialized before any plugin is executed.
- Run all plugins. Plugin engine fills the context and passes to every plugin.
- Cleanup. Plugin engine calls Dispose for every plugin.
Error Handling
If a plugin cannot finish what it is expected to do, it should throw any appropriate exception (e.g. InvalidArgumentException,...). Every exception thrown in the plugin code will be caught by the plugin engine which will log the exception and wrap it inside a
BackgroundTaskException.