Microsoft .NET Operator Sample

This topic describes the use of the TIBCO StreamBase® Operator for Microsoft .NET in a sample application to execute code contained in a .NET assembly. For more information about this operator, see Using the Microsoft .NET Operator.

Note

This operator (and hence this sample) is only meaningful on Windows-based platforms; when used on Linux or other non-Windows platforms the operator becomes inactive and swallows all tuples sent to it without performing any work or emitting output tuples.

Note

The .NET code in this sample is delivered in both source code and binary forms. As with all StreamBase-enabled .NET code you will need Microsoft's .NET Framework 4.0 installed to run the sample.

Sample Overview

This sample includes a .NET Operator which loads a .NET class called DotNETOperatorSample.DotNETSample from an assembly located in the .\DotNETCode\bin\Release subdirectory of the project. This class has been written to extend StreamBase's StreamBase.SB.Operator class, and is invoked whenever a tuple is received by the operator. The .NET class then processes the tuple (using the StreamBase .NET Client API facilities) and sends another tuple to the operator which is emitted to its output port. In this sample the processing performed by the .NET class is simple: the tuple's intValue value is squared and set in the output tuple's field named answer.

This Sample's Files

This sample has the following files:

  • The sample EventFlow application, DotNETOperator.sbapp.

  • A DotNETCode directory containing the C# project used to create the .NET assembly loaded by the sample (including the source code located in DotNETCode\DotNETOperatorSample.cs), as well as a pre-built copy of the resulting binary (DotNETCode\bin\Release\DotNETOperatorSample.dll) for your convenience.

    Note

    If you wish to rebuild the assembly using the included .NET solution, you may need to change the reference to StreamBase.SB.Client to correctly point to your StreamBase installation's copy (located in either the bin or bin64 subdirectory of your installation). When you change the reference, make sure you set its Copy Local attribute to FALSE.

Running This Sample in StreamBase Studio

The steps to run this sample in Studio are as follows:

  1. In the Package Explorer, double-click to open the DotNETOperator.sbapp application.

  2. Make sure the application is the currently active tab in the EventFlow Editor, then click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Manual Input view, select the InputStream input stream.

  4. Enter any integer in the intValue field.

    Click Send Data, and observe that the output stream that received the data is the OutputStream stream, with a value for the answer field equal to the square of the input value. This result value was calculated and placed in the output tuple by the .NET code located in the DotNETOperatorSample.dll assembly.

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

Running This Sample in Terminal Windows

This section describes how to run this sample in Windows command prompt windows. Be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows.

  2. In window 1, navigate to the directory location where your project resides, then start StreamBase Server with the .sbapp file as its argument. For example:

       cd /d "C:\Users\myusername\My Documents\StreamBase Studio X.Y Workspace\sample_dotnet-operator
       sbd DotNETOperator.sbapp
  3. In window 2, type:

    sbc dequeue

    This window will display tuples dequeued from the application's output ports.

  4. In window 3, type:

    sbc enq InputStream

    This window is now ready to accept tuples typed with CSV syntax.

  5. In window 3, type:

    7

  6. Observe in window 2 one tuple is emitted on the OutputStream stream, and its answer field contains the square of the given value:

    OutputStream,49

  7. In window 2, type Ctrl+C to terminate the dequeuer. Then type the following command to shut down the server:

    sbadmin shutdown

Importing This Sample into StreamBase Studio

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

  • From the top menu, select FileLoad StreamBase Sample.

  • Select Microsoft .NET Operator from the Extending StreamBase category.

  • Click OK.

StreamBase Studio creates a project for the .NET Operator sample in your current Studio workspace.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_dotnet-operator

See Default Installation Directories for the location of studio-workspace on your system.

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/dotnet-operator

See Default Installation Directories for the default location of studio-workspace on your system.