Steam Sensor Example for the .NET SDK > Additional .NET SDK Example
Additional .NET SDK Example
The following examples are provided to outline common, but more complex, operations that can be performed with the .NET SDK. These examples are for demonstration purposes only.
Property/Service with INFOTABLE Base Type
The following example illustrates how to create a property and service that use a base type of INFOTABLE. The infotable contains an ID (base type INTEGER) and a Value (base type STRING):
The property is defined as an infotable, using annotations.
The service takes an infotable as a property and returns the same infotable.
// Class Annotations for the property

[ThingworxPropertyDefinition(
name="StringIndex",
description="String Index Property",
baseType="INFOTABLE",
aspects = new string [] {
"dataChangeType:NEVER",
"dataChangeThreshold:0",
"cacheTime:-1",
"isPersistent:FALSE",
"isReadOnly:FALSE",
"pushType:VALUE",
"dataShape:StringMap"
}
)]

// This needs to be in the constructor or a method called from the
// constructor.
// First a Data Shape definition needs to be added to the VirtualThing

FieldDefinitionCollection fields = new FieldDefinitionCollection();

// Define the fields
fields.addFieldDefinition(new FieldDefinition("ID", BaseTypes.INTEGER));
fields.addFieldDefinition(new FieldDefinition("Value", BaseTypes.STRING));

// Add the DataShapeDefinition to the VirtualThing
this.defineDataShapeDefinition("StringMap", fields);

// Service Definition
[method: ThingworxServiceDefinition(
name="StringMapService",
description = "Returns the passed in String Map",
aspects=new string[]{"dataShape:StringMap"})]
[return: ThingworxServiceResult(
name=CommonPropertyNames.PROP_RESULT,
baseType="INFOTABLE",
description="",
aspects = new string[] { "dataShape:StringMap" })]
public InfoTable StringMapService(
[ThingworxServiceParameter(
name="value",
baseType="INFOTABLE",
description="",
aspects=new string[]{
"dataShape:StringMap"})] InfoTable value )
{
return value;
}
Was this helpful?