How to set List field values using the StreamBase .NET API

How to set List field values using the StreamBase .NET API

book

Article ID: KB0076353

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

How to set List field values using the StreamBase .NET API.

Issue/Introduction

How to set List field values using the StreamBase .NET API

Resolution

Create a List of type 'object' and use the SetList() method in the StreamBase .NET API to set the value of your List field. For a working example, you may enhance the SimpleEnqueuer.cs code provided in the StreamBase .NET Client Sample as follows:

  1. Add a fourth field named myIntListto the input schema:
     
    //
    // Field names in Schema
    //
    private const String FIELD1 = "myint";
    private const String FIELD2 = "mystring";
    private const String FIELD3 = "mydouble";
    private const String FIELD4 = "myIntList"; //add


    ---

    The myIntList field should also be added to the dotnet.sbapp application's Input Stream schema. In addition, add myIntList to the Map Operator's Additional Expressions so its values can be seen on the application's Output Stream.

    ---

  2. In the Main method, create the Field object for myIntList:
     
    // turn the field names into Field objects outside the enqueue loop,
    // for efficiency of the loop
    Schema.Field field1 = schema.GetField(FIELD1);
    Schema.Field field2 = schema.GetField(FIELD2);
    Schema.Field field3 = schema.GetField(FIELD3);
    Schema.Field field4 = schema.GetField(FIELD4); //add

  3. Create a List object and populate it with some values:
     
    List<object> myAL = new List<object>(); //add
    myAL.Add( 1 );
    myAL.Add( -2 );
    myAL.Add( 1 );

  4. Use the Field object, field4, to set the values of myIntListin the enqueue loop:
     
    for (int i = 1; i <= NUM_TUPLES; i++) {
    // initialize the tuple's fields
    tuple.SetInt(field1, i);
    tuple.SetString(field2, "Tuple #"+i);
    tuple.SetDouble(field3, i / 10.0);
    tuple.SetList(field4, myAL); //add

For details on using the SetList() method, refer to the .NET API Help included with your installation of StreamBase.