Workflow - Component - Developer Guide - Inputs - Checkbox

Published on Wednesday, 9 November 2016

In this Article I'm going to explain how to add a Input of a Checkbox to gather more configuration from the User.

Table of Contents

Currently our Component Concatenates two strings together with a space.

public override void Run(IData data)
{
    data[_variableName] = _string1.GetValue<String>(data) + " " + _string2.GetValue<String>(data);
}

It would be nice to give the user the option to say whether they would like a space or not.

A Checkbox would be a good choice here.

First we can declare a variable to hold our choice.

Since it's either going to be Yes or No we can use a Boolean.

private bool _addSpace;

Next to create the Getter and Setter

[VariableType(typeof(Boolean), false), 
  PropertyIndex(3), 
  DisplayName("Add Space"), 
  Category("Configuration"), 
  ComponentDescription("Add a space between the two strings")
]
public bool AddSpace
{
    get
    {
        return this._addSpace;
    }
    set
    {
        this._addSpace = value;
        ((AbstractOrchestrationComponent)this).IsValid(true);
    }
}

As we are setting the VariableType this can be used in the Component back in Workflow.

Now to add the necessary code to the previous methods.

ReadFromStream

public override void ReadFromStream(ObjectReadStream info) {
    ...
    this._addSpace = (bool)info.GetValue("_addSpace", typeof(bool), (object)false);
}

WriteToStream

public override void WriteToStream(ObjectWriteStream info) {
    ...
    info.AddValue("_addSpace", _addSpace);
}

And finally we can use it in our Run method:

public override void Run(IData data) {
    bool space = this._addSpace;
    //if (_addSpace.GetValue<bool>(data)) {
    if (space) {
        data[_variableName] = _string1.GetValue<String>(data) + " " + _string2.GetValue<String>(data);
    } else {
        data[_variableName] = _string1.GetValue<String>(data) + _string2.GetValue<String>(data);
    }
}

Protirus.png