- Index

< Previous |  | Next >

# 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 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.

## Sample Overview

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`.

## Importing This Sample into StreamBase Studio

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

- From the top-level menu, select File → Load StreamBase Sample.

- Enter `operator` to narrow the list of options.

- 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.

## Running This Sample in StreamBase Studio

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

1. Using Microsoft Visual Studio, build the provided C# code into a .NET assembly in DLL form.

2. Copy the built assembly DLL and its associated `app.config` file to the `src/main/resources` folder of the StreamBase Studio project.

3. In the Project Explorer view, open the sample you just loaded.

   If you see red marks on a project folder, wait a moment for the project to load its features.

   If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven → Update Project from the context menu.

4. Open the `src/main/eventflow/`packageName`` folder.

5. Open the `DotNETOperator.sbapp` file and click the Run button, or right-click and select Run As → EventFlow Fragment. This opens the SB Test/Debug perspective, loads the fragment into a StreamBase Runtime node, and starts the node.

6. In the Manual Input view, select the `InputStream` input stream.

7. 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.

8. When done, press F9 or click the Terminate EventFlow Fragment button.

## This Sample's Files

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 in `DotNETCode\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 its `Copy Local` attribute to `FALSE`.

## 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 default location of `studio-workspace` on your system.