DBWriter module
Database Writer Module
Databaase Writer module can be used in any application hosted in the ProconTEL 4 environment. It can save any XML (XDocument) to a relational database.
Table of Contents
Definition
Namespace: ProconTel.Components.Communication.DBWriter
Assembly: ProconTel.Components.Communication.DBWriter.dll
Module Installation
To install the DBWriter module into a project, Nuget Package Manager Console can be used:
Install-Package ProconTel.Components.Communication.DBWriter -ProjectName <ProjectName>
The NuGet package can be found in the repository: https://nexus.macrix.eu/repository/pct2022/
Example of usage in code
Overview
To use the DB writer module, it is necessary to add the module to the flow in the pipeline using the AddDbWriter extension as below. It can be done in two different ways (using minimal API or standard dotnet way - details below in this documentation)
flow.AddDbWriter(new DbWriterConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
});
Configuration
The AddDBWriter extension accepts an instance of the DbWriterConfiguration class that can be used to configure the DbWriter module. All parameters that can be set are listed below.
| Parameter | Default value | Description |
|---|---|---|
| TableName | TCP_TEL_HIST | The table name where XML will be stored |
| Provider | Oracle | The database provider we are connecting to |
| ConnectionString | Connection string to database | |
| RetryPolicy | Max delay and max number of retries of the | |
| retry policy applied for each db call |
Using minimal API
using ProconTel.Components.Communications.DBWriter;
using ProconTel.SDK;
await ProconTelApp.StartAsync(args, services => services
.AddPipeline(flow =>
flow.AddDbWriter(new DbWriterConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
})));
Using standard dotnet way
using ProconTel.Components.Communications.DBWriter;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureProcontel(builder.Configuration);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddProconTel(builder.Configuration);
builder.Services.AddPipeline(flow =>
flow.AddDbWriter(new DbWriterConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
}));
var app = builder.Build();
app.UseProconTel();
app.MapProconTel();
await app.RunAsync();
Store values from XML as a separate column in the database
Overview
To store values from XML as s separate column mapping configuration should be configured. The mappings are used for parsing data from XML telegram data.
The default mappers for DBWriter module requires to install additional package:
Install-Package ProconTel.Components.Communication.DBWriter.Mappers -ProjectName <ProjectName>
After installed the mappers package add mappers configuration .AddDbWriterMappers().WithConfiguration() in the flow after AddDbWriter extension
.AddDbWriter(new DbWriterConfiguration()
{
ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=XE)));User Id=<USER>;Password=<PASSWORD>>;",
Provider = DbProvider.Oracle,
RetryPolicy = new RetryPolicyConfiguration() { MaxDelayInSeconds = 30, RetryCount = 10 }
}).AddDbWriterMappers().WithConfiguration(new DbWriterMapperConfiguration()
{
TransformationConfiguration = new Dictionary<int, Dictionary<string, string>>()
{
{
10, new Dictionary<string, string>()
{
{
"KEY_1", "SequenceId"
},
{
"KEY_5", "TransferStatus"
}
}
}
}
})
Mappers configuration
The WithConfiguration extension accepts an instance of the DbWriterMapperConfiguration class that can be used to configure the DbWriter mappers. All parameters that can be set are listed below.
| Parameter | Description |
|---|---|
| TransformationConfiguration | The XDocument transformation configuration. Contains dictionary where the key is schema id and value is a dictionary of database columns (key) where will be stored values from XML element value (value) |