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 macOS 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 source code form. As with all StreamBase-enabled .NET code, you must have Microsoft's .NET Framework 4.0 installed to run the sample.
This sample includes a .NET Operator that loads a .NET class named DotNETOperatorSample.DotNETSample
from an assembly that you must build from the provided C# source code. This class was 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 from 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
.
The Assembly Name or Full Path operator property is used to associate the sample's .NET assembly with the .NET Operator. The .NET assembly can be specified
using the assembly's simple or strong name, the location of your assembly on disk, or a resource path if the assembly resides
in one of your Studio project's resource directories. The project's pom.xml
configures the .\DotNETCode\bin
as a project resource directory and the Assembly Name or Full Path property is set to Release/DotNETOperatorSample.dll
.
This sample is in StreamBase 10's Maven project format, and 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
).Note
You must build the assembly from the source code. If you wish to use the included .NET solution file, you may need to change the reference to StreamBase.SB.Client to correctly point to your StreamBase installation's copy (located in the
bin
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:
-
Using Microsoft Visual Studio, build the provided C# code into a .NET assembly in DLL form.
-
Copy the built assembly DLL and its associated app.config file to the
src/main/resources
folder of the StreamBase Studio project. -
In StreamBase Studio's Project Explorer view, double-click to open the
DotNETOperator.sbapp
application fromsrc/main/eventflow/com.tibco/sb.sample.adapter.dotnetoperator
.If the project folder shows red marks, wait a few moments for the project's dependencies to load. If the red marks persist, select the project's name, right-click, and select
→ . -
Make sure the application is the currently active tab in the EventFlow Editor, then click the
Run button, or right-click and select → . This opens the SB Test/Debug perspective, loads the fragment into a StreamBase Runtime node, and starts the node.
-
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.
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 location of studio-workspace
on your system.