- 15 Apr 2024
- 1 Minute to read
- Print
- DarkLight
SDK: Consuming Data (Advanced)
- Updated on 15 Apr 2024
- 1 Minute to read
- Print
- DarkLight
Version 7.x .NET Architecture Change
- Versions 7.0.1 - 7.1 require .NET Core 3.1
- Versions 7.2 - 7.9 require .NET 5
- Versions 7.10+ require .NET 6
Overview
When writing an advanced step, the class must inherit from IDataConsumer for the step to have input data that can be mapped in at runtime. The below line of code illustrates a class that inherits from IDataConsumer.
public class SampleFlowStepInputs: BaseFlowAwareStep, ISyncStep, IDataConsumer
Example
After inheriting from IDataConsumer, the interface will need to be implemented. The implementation of this interface returns an array of DataDescription[]. The below sample code illustrates two inputs: single text input and an array text input.
public DataDescription[] InputData
{
get
{
return new DataDescription[]
{
new DataDescription(new DecisionsNativeType(typeof(string)), INPUT_TEXT),
new DataDescription(new DecisionsNativeType(typeof(string)), INPUT_TEXT_ARRAY, true, false, false)
};
}
}
Consuming Data for Flow step
The input value of a Flow step will be consumed in the run method. The input data values will be contained in a dictionary within the run method. This dictionary is data.Data. Use the name of the input data as the key to refer to it in the dictionary as shown below. In code example below, the variables ValueOfTextInput and ValueOfTextArrayInput[] have been populated with the respective input data.
public ResultData Run(StepStartData data)
{
string valueOfTextInput = (string)data.Data[INPUT_TEXT];
string[] valueOfTextArrayInput = (string[])data.Data[INPUT_TEXT_ARRAY];
return new ResultData("Done");
}
Consuming Data for a Rule step
Consuming Data for a Rule step is much the same as a Flow step with one exception. The anchor data of the Rule step is automatically available inside the run method of the Rule step. Therefore, it does not need to be handed in separately. This anchor data is available in the data.Data dictionary with the key to this.AnchorData.Name.
The code below shows an example of a Rule's run method that compares the anchor data to an additional input added to the Rule.
public override bool Run(RuleStepExecutionData data)
{
string input = (string)data.Data[this.AnchorData.Name];
string textToEval = (string)data.Data[INPUT_TEXT_TO_EVALUATE];
return input.Equals(textToEval, StringComparison.OrdinalIgnoreCase);
}