SDK: ISync Flow Steps (Advanced)
  • 09 Aug 2024
  • 3 Minutes to read
  • Dark
    Light

SDK: ISync Flow Steps (Advanced)

  • Dark
    Light

Article summary

Version 7.x .NET Architecture Change

Overview

While creating simple steps using the Public Static method is easier, developers may want to write a full Decisions step to do complex things. This may include having multiple outcome paths or validate input data at design time (e.g. ensure that the value of one input property is set if the value of another property = X). 

Creating advanced Flow Steps will allow developers to control:

  • Variable inputs or outputs
  • Need advanced configuration
  • Need for custom validation
  • Hiding and showing properties
  • A better user experience when editing

ISyncStep

  • Design Time: Outcomes (Step paths to be connected to other steps)
  • Run Time: Run behavior, takes in Flow Data and returns outcome immediately
  • Complete and immediately return an example, don’t have to keep the history (run and throw away)

Example

Interfaces used ISyncStep, IDataConsumer. ISyncStep does XYZ. IDataConsumer means that this step will consume data from the Flow Engine. 

Validate loan step will have two outcomes: "Loan Valid", "Not Valid"

The step will get a loan, validate the loan and return to the Flow Engine because this is an ISync Step. When returning to the flow engine, ResultData will need to be returned. ResultData requires resultPath and data. Important: Result path that is return needs to match one of the designed outcomes (in this example: Loan Valid, Not Valid)

The method will need the [AutoRegisterStep] attribute to show in the product. 

Property

Developers can create properties on the step that will show in the Settings panel in the Flow Designer. In this example, public bool Test Mode is a property.

The property and Loan step has to be saved as a part of the Flow Engine. For Test Mode to be saved, it must be serialized, it can't just remain a common property. To make it serialized reference [Writable] and [WritableValue]. 

Input

Using IDataConsumer requires implementing an accessor that gets a list of Input data that this step requires to work. public DataDescription[] Input Data

Using the StartStepData dictionary will allow developers to use CurrentFlowStateData, FlowTrackingID, StepTrackingID, and Data which is a dictionary of all of the Flow Data that is handed into the step. The Flow Engine does not give the step more information than what it wants, so if the data is not defined in input data on the step definition the Flow Engine is not going to hand in additional data. Using the Data 


using System.Collections.Generic;
using System.Security.Permissions;
using DecisionsFramework.Design.ConfigurationStorage.Attributes;
using DecisionsFramework.Design.Flow;
using DecisionsFramework.Design.Flow.Mapping;
using DecisionsFramework.Design.Properties;
using DecisionsFramework.ServiceLayer;

namespace InvestementSDKConversation
{
    [Writable]
    [AutoRegisterStep("Run Loan Validation", "Investment Customizations")]
    public class ValidateLoanStep : ISyncStep, IDataConsumer
    {
        [WritableValue]
        public bool TestMode { get; set; }

        [WritableValue]
        [PropertyHiddenByValue("TestMode", true, false)]
        [SelectStringEditor("LoanResultValidValues")]
        public string LoanResultForTestMode { get; set; }

        [PropertyHidden]
        public string[] LoanResultValidValues
        {
            get
            {
                return new [] {
                    "Basic", "Premium", "High Risk"   
                } ;

            }
            set { return; }
        }

        public OutcomeScenarioData[] OutcomeScenarios {
            get {

                return new[] {
                new OutcomeScenarioData("Loan Valid"),
                new OutcomeScenarioData("Not Valid", new DataDescription(typeof(string), "Errors", true)), 
            }; 
            }
        }
        
        public ResultData Run(StepStartData data)
        {
            // Get a loan
            Loan thingToProcess = data.Data["Loan to Check"] as Loan;
            List validationMessages = new List();
            
            // Access default values from global settings object
            string serverName = ModuleSettingsAccessor.Instance.ServerName;
            // Server Name is not used and has no value in this class, but it is meant to
            // illustrate how to get access to the settings in your module settings object
            // for use in flow steps for things like credentials and global values.
            
            // Validate Loan
            if (thingToProcess != null && thingToProcess.Amount > 0)
            {
                // Return to the flow engine because this is a sync step.
                return new ResultData("Loan Valid");
            }
            else
            {
                validationMessages.Add("Amount of loan must be positive and greater than 0.");
            }

            if (thingToProcess.Term < 6)
            {
                validationMessages.Add("We don't do short term loans, go to your local bank.");
            }

            return new ResultData("Not Valid", new KeyValuePair("Errors", validationMessages.ToArray()));
        }

        public DataDescription[] InputData
        {
            get { return new[] { new DataDescription(typeof(Loan), "Loan to Check")  }; }
        }
    }
}




Was this article helpful?