Working with configuration - COPA-DATA/DriverExtensions GitHub Wiki

To configure a driver extension, configuration files are used. These files must be located in the Files\Driver area of the project

It is important to define the configuration file name in the corresponding GenericNet's assembly settings.

During loading of the driver extension, the full path to the configuration file is passed to the argument configFilePath of the InitializeAsync method. The sample here loads the configuration file by using Microsoft's Microsoft.Extensions.Configuration.Json library available on NuGet.

public Task InitializeAsync(ILogger logger, IValueCallback valueCallback, string configFilePath)
{
  _logger = logger;
  _valueCallback = valueCallback;

  var configurationBuilder = new ConfigurationBuilder()
      .AddJsonFile(configFilePath, optional: true);
  var configuration = configurationBuilder.Build();
  var serverAddress = configuration["MqttServerAddress"] ?? "localhost";

  return Task.CompletedTask;
}