Configuration Properties
Properties of a ILisrtModule implementation can be marked as configuration property using the ConfigurationAttribute. This means the values can be saved and loaded from a configuration file. By default, this is an XML file located in the configuration path.
Example
Decorate a property with [Configuration(DefaultValue = 42)]
, the value '42' is used as default if the configuration file doesn't contain a value.
Module containing configuration properties
public class MyModule : LisrtModule
{
private const int DefaultTimeout = 12;
// Properties of a value type must have a default value
[Configuration(DefaultTimeout, Description = "Communication timeout", Unit = "s")]
public int Timeout { get; set; } = DefaultTimeout;
[Configuration]
public CalibrationData CalibrationData { get; set; } = new CalibrationData();
// A configuration property that represents a collection,
// must implement the System.Collections.IList interface.
[Configuration]
public IList<int> Items { get; set; } = new List<int>();
[Configuration]
public IList<CalibrationData> ChannelCalibrations { get; set; }
= new List<CalibrationData>();
}
// Classes that are used in a configuration property,
// must be decorated with the ConfigurationClass attribute.
[ConfigurationClass]
public CalibrationData
{
[Configuration(1.0)]
public double Factor { get; set; }
[Configuration(0.0)]
public double Offset { get; set; }
}
Note
Configuration properties must have a setter. This can be private.
Note
Configuration attributes are inherited, but be careful: It can not be removed in an inherited class.
Load and Save
A user can load and save the configuration via the module tree tool bar. To do this, the user requires the LoadModuleConfiguration and the SaveModuleConfiguration permissions.
From code you load and save configuration using the methods of the IModulesService implementation.
var moduleService = IoC.Get<IModulesService>();
moduleService.LoadConfigurationToRootModule("station.config");
If you loaded a configuration but not all sub- and sub-sub-modules existed while loading, don't panic. Your loaded configuration is stored in ModuleConfigurations. The default ModulesService gets notified when a new module is added, and its configuration is applied.