StreamBase .NET Client Sample

The StreamBase .NET client sample contains three C# and one VB.NET applications that enqueue tuples to, and dequeue tuples from, a StreamBase application. The StreamBase application performs a simple Map operation on the incoming tuples. While the operation is trivial, the sample demonstrates how the StreamBase .NET API enables client applications to be created in a .NET-compatible language that runs with a StreamBase application.

Note

The .NET API and this sample are only available in the StreamBase installation for Microsoft Windows. You can run the pre-built samples without having Visual Studio .NET installed. However, they require version 2.0 or later of the .NET Framework, which can be downloaded from Microsoft's web site.

This topic describes the StreamBase .NET client sample.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, click FileLoad StreamBase Sample.

  • Select the dotnet sample from the Client APIs group.

  • Click OK.

StreamBase Studio creates a project for this sample.

Sample Location

By default, the sample files are installed in:

C:\Program Files\StreamBase Systems\StreamBase.n.m\sample\dotnet

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace. StreamBase Systems recommends that you use the workspace copy of the sample. In the default installation, the path to this sample in your Studio workspace is:

Windows XP:
  C:\Documents and Settings\username\My Documents\StreamBase Studio n.m Workspace\
      sample_dotnet
Windows Vista:
  C:\Users\username\Documents\StreamBase Studio n.m Workspace\
     sample_dotnet

This Sample's Files

The sample has the following files:

  • A StreamBase application, dotnet.sbapp.

  • One enqueuer and three dequeuer programs that use the StreamBase .NET API.

  • Microsoft Visual Studio .NET solution and project files, which can be used to build all of the sample source code. (In the Visual Studio project files, the paths to the StreamBase include files and libraries are configured for the standard default installation directory. You may need to adjust these paths for your PC.)

Running the .NET Client Sample

Running the .NET sample in StreamBase Studio

To run this sample using StreamBase Studio:

Note

Running the forms-based sample dequeuer, bin\SimpleDequeuerForm.exe, is not supported from StreamBase Studio.

  1. In the Package Explorer, double-click to open the dotnet.sbapp application. Make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. Open a StreamBase Command Prompt window, and navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  4. In the Command Prompt window, run the enqueuer by typing:

    bin\SimpleEnqueuer.exe

  5. Back in Studio, observe that ten tuples appear in the Application Output view.

  6. In the Command Prompt window, run the dequeuer by typing:

    bin\SimpleDequeuer.exe or bin\SimpleDequeuerVB.exe

  7. Back in Studio, in the Manual Input view, fill in the three fields and click Send Data.

  8. Observe that a modified version of the tuple is dequeued by the simple dequeuer sample program running in the Command Prompt window.

  9. When done, press F9 or click the Stop Running Application button.

Running the .NET sample in Command Prompt Windows

  1. Open three StreamBase Command Prompt windows. In each window, navigate to the directory where the sample is installed, or to your workspace copy of the sample, as described above.

  2. In window 1, run the StreamBase Server on dotnet.sbapp:

    sbd dotnet.sbapp

  3. In window 2, enter one of the following commands to run the dequeuer:

    • Console dequeuer command: bin\SimpleDequeuer.exe or bin\SimpleDequeuerVB.exe

    • Windows form-based dequeuer command: bin\SimpleDequeuerForm.exe

  4. If you are using the form-based dequeuer, click Connect.

  5. In window 3, enter the following command to run the enqueuer:

    bin\SimpleEnqueuer.exe

  6. Observe that tuples are displayed by the dequeuer. In the case of the form-based dequeuer, the last tuple dequeued is displayed.

  7. Run sbadmin shutdown to close the server.

Back to Top ^

How We Created the .NET Client Sample

Created the Enqueue and Dequeue Clients

  1. Launched Visual Studio.

  2. Created a new solution file named DotNetSamples.

  3. Added three C# projects to the solution: SimpleEnqueuer, SimpleDequeuer, and SimpleDequeuerForm. The first two are Console Applications, and the third is a Windows Application.

  4. Added references from each of the four projects to the following StreamBase-supplied assembly: sbclient.dll. This assembly is placed in C:\Program Files\StreamBase Systems\StreamBase.n.m\bin when StreamBase is installed.

  5. Added a class file to each of the projects to hold the application code.

  6. At the top of each class file, added using statements to access the StreamBase client .NET API namespaces:

    using System;
    using StreamBase.SB;
    using StreamBase.SB.Client;
    

    Note that the form-based dequeuing application uses several additional namespaces.

  7. In the enqueue and dequeue clients, created a StreamBaseClient object, representing a connection to the StreamBase Server:

    string SERVER="sb://localhost:10000";
    StreamBaseURI uri = new StreamBaseURI(SERVER);
    
  8. In the enqueue client:

    • Created a tuple to be enqueued to the StreamBase Server:

      string INPUT_STREAM="InputStream1";
      StreamProperties props = client.GetStreamProperties(INPUT_STREAM);
      Tuple t = props.GetSchema().CreateTuple();
      
    • Repeatedly initialized the tuple and enqueued it to the StreamBase Server:

      for (int i = 1; i <= NUM_TUPLES; i++) {
          t.SetInt(FIELD1, i);
          t.SetString(FIELD2, "Tuple #"+i);
          t.SetDouble(FIELD3, i / 10.0);
          client.Enqueue("InputStream1", t);}
      
  9. In the dequeue client:

    • Repeatedly dequeued a sequence of tuples from the StreamBase Server:

      DequeueResult dr = null;
      while((dr = client.Dequeue()) == DequeueResult.GOOD) {
          .
          .
      }
      
    • Processed each tuple in the sequence:

      foreach(Tuple tuple in dr) {
          Console.WriteLine("dequeue: " + tuple.ToString());
      }
      

Back to Top ^

Created the Sample StreamBase Application

  1. Launched StreamBase Studio.

  2. In the SB Authoring perspective, created the dotnet project: From the top menu, selected FileNew Project, entered dotnet in the Project name field, and clicked Finish.

  3. From the top menu, selected FileNewEventFlow Application. Selected the dotnet project, and entered simple.sbapp for the diagram name.

  4. Created an input stream:

    1. Dragged an input stream from the palette to the canvas.

    2. Selected the input stream's icon on the canvas, which invoked the Input Stream Properties view.

    3. On the Edit Schema tab, added:

      Field Name Type Size
      mystring string 32
      myint int 4
      mydouble double 8
  5. Set up the Map operator:

    1. Dragged a Map operator from the palette to the canvas and opened its Properties view.

    2. Dragged a connector from the Input Stream to the input of the Map1 operator.

    3. On the Output Settings tab, selected the explicitly specified fields option.

    4. Clicked the Add button three times to add three rows. Edited the row fields as follows:

      Output Field Name Expression
      myint -myint
      mystring mystring+"processed!"
      mydouble -mydouble
    5. Clicked the Add button to add another row:

      • Action: Add

      • Field Name : randomDouble

      • Exression: calljava('java.lang.Math', 'random')

  6. Created an output stream:

    1. Dragged an output stream from the palette to the canvas.

    2. Connected the Map1 operator to the output stream.

Back to Top ^