Create Settings
Settings are optional but recommended for almost all modules. Settings define configurable properties that users can adjust in Flow Studio.
Tip
Required namespaces:
using Crosser.EdgeNode.Common.Abstractions.Utilities.Validationusing Crosser.EdgeNode.Flows.Abstractionsusing System.ComponentModelusing System.ComponentModel.DataAnnotations
To create a settings class we must inherit the class FlowModuleSettings:
For simplicity we will add the class to same file as the module, but in a real-world scenario it is recommended to create a separate file for better organization.
public class RandomNumberModuleSettings : FlowModuleSettings
{
[Display(Name = "Minimum Value", Description = "The lowest value in the random range")]
[DefaultValue(1)]
[Range(1, 10000)]
public int TargetMin { get; set; } = 1;
[Display(Name = "Maximum Value", Description = "The highest value in the random range")]
[DefaultValue(100)]
[Range(1, 10000)]
public int TargetMax { get; set; } = 100;
[Display(Name = "Target Property", Description = "The property to store the random value in")]
[DefaultValue("data")]
[MinLength(1)]
[MaxLength(64)]
public string TargetName { get; set; } = "data";
}
Tip
Note that by using the DefaultValue, Description and Display attributes we will get automatic default values, names and descriptions in the FlowStudio UI when the users are using your module.
Add Validation
Now we will add validation for the properties so that users can't save modules if settings are invalid. Below we override the Validate method and use the built-in extensions for validation. We also show how to add errors based on custom conditions.
public class RandomNumberModuleSettings : FlowModuleSettings
{
// Properties hidden for readability
public override void Validate(SettingsValidator validator)
{
// Built-in validators
validator.Validate(nameof(this.TargetMin), this.TargetMin)
.MinValue(0)
.MaxValue(10000);
validator.Validate(nameof(this.TargetMax), this.TargetMax)
.MinValue(1)
.MaxValue(10000);
validator.Validate(nameof(this.TargetName), this.TargetName)
.NotNull()
.MinLength(1)
.MaxLength(64);
// Custom validation logic
if (this.TargetMin >= this.TargetMax)
{
validator.AddError(nameof(this.TargetMin),
"Minimum value must be less than maximum value");
}
}
}
Tip
See Module Settings Guidelines for more attributes and validation options.