This is a four part series on building reusable Pipeline Components for BizTalk (2004/2006). The four part series starts of with laying a foundation with a couple of base classes and the other three installments will cover one component each. The following components will be discussed.
- Static Message Context Component
A Pipeline Component that can add statically configured properties to a message (context).
- Outbound File Location Component
A Pipeline Component that can create sub folders in an Outbound Transport Location based on message (context) properties or literal expressions.
- Build SourceFileName Component
A Pipeline Component that can set the value for the %SourceFileName% macro used in Send Ports. This is a convenient way to custom-name the output files.
The Pipeline Components use a collection of configured properties that are configured during design-time in the (BizTalk) Pipeline Designer. Once the Pipeline is deployed no configured properties can be added or removed but the values of the existing properties can be changed.
A quick analysis of the three components shows us that we see 2 common needs here: (1) we can probably make a base class for each Pipeline Component to derive from and (2) all components use (some sort of) configurable Context Properties to build some internal state.
The following class diagram shows the base classes:
The PipelineComponentBase class provides the initial layer of Pipeline Component functionality. It (partially) implements the IBaseComponent, IComponent and IPersistPropertyBag interfaces most commonly found in Pipeline Components. Note that the base class does not declare any (class) attributes for registering Pipeline Components. These class attributes should be added on the implementation class that (indirectly) derives from the PipelineComponentBase class.
Both the Name and Description properties of the Pipeline Component are abstract: the derived class has to implement them. The class also introduces an abstract ExecuteInternal (template) method that is call from the IComponent.Execute method implementation. This method has the exact same signature as the IComponent.Execute method but is only called if the Enabled property is set to true (default). When Enabled is set to false the incoming message is returned and no operations are performed. This allows you to switch Pipeline Components on and off through configuration – even in production.
The PipelineComponentWithResourceBase class derives from the PipelineComponentBase class and takes an instance of a ResourceManager in its constructor (with an optional name prefix). The ResourceManager instance passed to the constructor can be taken from the Visual Studio generated Settings class. Through a naming convention it looks for resources in the assembly for the Name and Description properties. The class also implements the IComponentUI interface and its Icon property. The implementation of the Icon property fall back to a generic Icon if there is no Component specific Icon resource found.
The naming convention used for the implementation of the Name, Description and Icon properties is: [prefix] + “Component” + PropertyName. For instance a Pipeline Component class that specifies “MyComponent” as prefix would provide the resource key “MyComponentComponentName” with a string value “My Component” to implement the Name property. Note that you must supply the Name and Description property resources. The Icon property resource is optional and defaults to “ComponentIcon”. Use the prefix if you have more than one Pipeline Component in a single assembly.
The ContextPropertyDef class provides a base class for component specific configurable Context Property instances.
I’ve also included the MessageContextBase class in the class diagram. This class provides a basis for implementing Typed Message Context classes like the SystemMessageContext implemented by BizTalk. The Build SourceFileName Component uses the FileAdapterMessageContext (which derives from MessageContextBase) to access the FILE.ReceivedFileName context property.
Download the source code here.