Passing Data with DataModels
This section explains another way of passing data to and from Actions and Triggers, different than the one explained in
"Passing Data" section.
'DataModel' explained
A DataModel is a class (or instance of that class) with multiple data members, that can be understood by the Easybots platform.
The whole data object can be passed to other bots, or just the separate data members.
In code, they are classes decorated with
[Easybots.DataModels.EasybotsDataModelAttribute]
.
The members that you want to be available to other bots in the Easybots Studio, should be decorated with
[Easybots.DataModels.EasybotsDataMemberAttribute]
.
An example of a '
Area' datamodel, with three data members:
AreaMetric,
AreaImperial and
AreaText (from the example in
"Passing Data" section),
will be implemented in the following way:
[Serializable]
[EasybotsDataModel]
public class AreaDataModel
{
[EasybotsDataMember]
public int AreaMetric;
[EasybotsDataMember]
public int AreaImperial;
[EasybotsDataMember]
public string AreaText;
}
The method (Easybots Action) that will return this DataModel will look like this:
[Easybots.Apps.Action]
public AreaDataModel CalculateSquareAreaDataModel(
[ParameterDescription("x", "The side 'x' in meters", typeof(int), Order=0)]
[ParameterDescription("y", "The side 'y' in meters", typeof(int), Order=1)]
int[] inputs)
{
// 'unpack' the input parameters
int x = inputs[0];
int y = inputs[1];
// Return values
int metricArea = CalculateMetricArea(x, y);
int imperialArea = CalculateImperialArea(x, y);
string areaAsText = GetText(x, y);
// Construct the return object
AreaDataModel returnObject = new AreaDataModel();
returnObject.AreaMetric = metricArea;
returnObject.AreaImperial = imperialArea;
returnObject.AreaText = areaAsText;
return returnObject;
}
In Easybots Studio, that will result in:
These data members can be used with any other bot, as input to their actions.
Well Done! Now you know how to use the Easybots platform.
You can continue creating solutions and apps, save it to your private stores, or share it with other people.