Module Settings
Tip
Namespaces used on this page
- using Crosser.EdgeNode.Common.Abstractions.Utilities.Validation;
- using Crosser.EdgeNode.Flows.Abstractions;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
Most modules will require some kind of settings. Settings are created by creating a new class that inherits FlowModuleSettings
You can name the settings class whatever you like, but it would make sense to have the same name as the module with the prefix Settings
.
Example: If you have a module named RandomNumberModule
the settings class would be named RandomNumberModuleSettings
Keep Properties Simple
By this we mean that you should try to avoid complex properties and instead use built-in types or enums.
The reason for this is that the UI is automatically generated and using complex types is not supported today.
Set DefaultValue and Display Attributes
As already mentioned the UI for the module is generated automatically, so setting the default value and display information with attributes is crucial.
Right now we support DefaultValue
and Display
but to support more complex scenarios we might add new attributes in the future.
When using the DefaultValue
attribute the value will be automatically written to the property, so there is no need to set the value on the property as well when using the DefaultValue
attribute.
[Display(Name = "Minimum value", Description = "The smallest value allowed for a random number")]
[DefaultValue(0)]
public int MinValue {get;set;}
[Display(Name = "Maximum value", Description = "The highest value allowed for a random number")]
[DefaultValue(100)]
public int MaxValue {get;set;}
If you write complex modules that need a custom UI, contact us and we will try to help out.
Tip
The settings specified are used to automatically build a UI for the module. Try to use intuitive display names, declare the settings in a logical order and provide relevant descriptions.
Add Validation if needed
The FlowModuleSettings class have a virtual method for validation. You can use helpers to validate built-in types, but also add custom logic to add custom validation errors if needed.
public override void Validate(SettingsValidator validator)
{
validator.Validate(nameof(this.MinValue), this.MinValue).MinValue(1).MaxValue(1000);
if(this.MinValue >= this.MaxValue)
{
validator.AddError("MinValue","The minimum value can't be equal to or higher than the maximum value");
}
}