Mapper Module
Mapper Module
Mapper module can be used in any application hosted in the ProconTEL 4 environment which is using components pipeline builder. Mapper allows the application to map data send to pipeline by producer to various .NET types that then can be used by consumers with those specific types.
Table of Contents
Definition
Namespace: ProconTel.Components.Mapping.Binary
Assembly: ProconTel.Components.Mapping.Binary.dll
Module Installation
To install a Mapper module into project, Nuget Package Manager Console can be used:
Install-Package ProconTel.Components.Mapping.Binary -ProjectName <ProjectName>
Nuget package can be found in the repository: https://nexus.macrix.eu/repository/pct2022/
Available Pipeline extensions and configuration methods
The list of currently available mappers:
- Binary to Object
- Binary to Xml
- Xml to Binary
- ASCII to Xml
- Xml to ASCII
The module provides extension methods that allows inject Mapper module to application. Below are shown extension methods for each mapper type:
public static BinaryMapperRegistrationSyntax<TelegramPayload<byte[]>, TObject> MapBinaryToObject<TObject>(this PipelineBootstrapper pipelineBootstrapper)
public static BinaryMapperRegistrationSyntax<TelegramPayload<byte[]>, TelegramPayload<XDocument>> MapBinaryToXml(this PipelineBootstrapper pipelineBootstrapper)
public static BinaryMapperRegistrationSyntax<TelegramPayload<XDocument>, TelegramPayload<byte[]>> MapXmlToBinary(this PipelineBootstrapper pipelineBootstrapper)
public static BinaryMapperRegistrationSyntax<TelegramPayload<string>, TelegramPayload<XDocument>> MapAsciiToXml(this PipelineBootstrapper pipelineBootstrapper)
public static BinaryMapperRegistrationSyntax<TelegramPayload<XDocument>, TelegramPayload<string>> MapXmlToAscii(this PipelineBootstrapper pipelineBootstrapper)
Methods injects Binary Mapper middleware to the pipeline. Mapping logic requires additional configuration. It can be provided by Xsbt files and registered with UseXsbtRules method. More about Xsbt and its registration can be found in Xsbt header definition and Xsbt mapping rules
Example of usage in code
The Mapper module can be used in conjunction with other components as a middleware in the pipeline. This example shows how to register Binary to XML mapper and use Xsbt files for mapper configuration.
using ProconTel.SDK;
await ProconTelApp.StartAsync(args, (services, configuration) => services.AddPipeline(pipeline =>
{
pipeline.AddProducer<TelegramPayload<byte[]>, MyProducer>();
pipeline.MapBinaryToXml().UseXsbtRules(opts => opts.XsbtFolderPath = configuration["Xsbt:XsbtsFolderPath"]);
pipeline.AddConsumer<TelegramPayload<XDocument>, MyConsumer>();
}));