Contents
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.
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 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 inDotNETCode\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
orbin64
subdirectory of your installation). When you change the reference, make sure you set itsCopy Local
attribute toFALSE
.
The steps to run this sample in Studio are as follows:
-
In the Package Explorer, double-click to open the
DotNETOperator.sbapp
application. -
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.
-
In the Manual Input view, select the
InputStream
input stream. -
Enter any integer in the
intValue
field.Click
, and observe that the output stream that received the data is theOutputStream
stream, with a value for theanswer
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 theDotNETOperatorSample.dll
assembly. -
When done, press F9 or click the Stop Running Application button.
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.
-
Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows.
-
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
-
In window 2, type:
sbc dequeue
This window will display tuples dequeued from the application's output ports.
-
In window 3, type:
sbc enq InputStream
This window is now ready to accept tuples typed with CSV syntax.
-
In window 3, type:
7
-
Observe in window 2 one tuple is emitted on the
OutputStream
stream, and itsanswer
field contains the square of the given value:OutputStream,49
-
In window 2, type Ctrl+C to terminate the dequeuer. Then type the following command to shut down the server:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
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.
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 default 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.