The C# Binding

Currently, Silk Performer supports all kernel, web, and browser BDL functions for C# binding. In Visual Studio you can access these functions by calling their equivalent static C# class methods, such as Kernel.MeasureStart(), Web.PageUrl(), or Browser.Click().

In other words: For each built-in Silk Performer .bdh file, you will find a corresponding C# class in the PerfRunDotNet assembly. And for each API function defined in that .bdh file, there is an equivalent static method in the corresponding C# class.

C# script structure

A C# class that is intended to be used for load testing in Silk Performer contains a VirtualUser attribute and a CodePage attribute. VirtualUser specifies a UserName and a ScriptName property. CodePage specifies the codepage of the recording system. Methods with the Transaction attribute will be mapped to transactions when exported to Silk Performer.

namespace SilkPerformerRecorder
{
  [VirtualUser(UserName = "VUser", ScriptName = "MyScript")]
  [CodePage(1252)]
  public class MyScript
  {
    [Transaction(ETransactionType.TRANSTYPE_INIT)]
    public void TInit()
    {
    }

    [Transaction(ETransactionType.TRANSTYPE_MAIN)]
    public void TMain()

Data Type Mapping

To pass parameters from .Net/C# to BDL and vice versa, some built-in data types have to be converted.

Strings

While Silk Performer and its BDL are based on the multi-byte character set (MBCS) encoding, the C# language works with Unicode. Thus, every string has to be converted when passed between the two worlds. The PerfRunDotNet assembly works with the BdlString class, which handles all these conversions. Moreover, it also takes care about binary buffers. For convenience, the BdlString class is assignment compatible with the C# string.

Sizespec and lenspec variables have been removed in the C# mapping, since C# strings typically know their length.

Static parameter values

Some static integer values, like severity parameters, have been replaced by specific enums.

Forms

BDL forms are mapped to a BdlForm class in C#:

private static readonly BdlForm ZIP_SEARCH001 = new BdlForm()
    {
      Entries = new BdlFormEntries()
      {
        { "zip-search", "", Kernel.USE_HTML_VAL }, // hidden, unchanged, value: "zip-search"
        { "zip-search:zipcode", "", Kernel.USE_HTML_VAL }, // unchanged, value: ""
        { "javax.faces.ViewState", "", Kernel.USE_HTML_VAL }, // hidden, unchanged, value: "j_id3:j_id4"
        { "zip-search:search-zipcode.x", "62" }, // added
        { "zip-search:search-zipcode.y", "4" } // added
      }
    };

Code page dependent replay

Due to Silk Performer being a MBCS-based application, the recorder automatically generates a codepage attribute in the C# script, which gets carried over to the .bdf script stub. It also takes care about converting all Unicode strings that cannot be represented in the system codepage into hex-byte arrays.

If the CodePage attribute is defined in a C# script, the following applies:

  • All classes in the project must have the same codepage.
  • Each string used in the C# script has to be convertible to MBCS strings using that codepage.
  • The defined codepage is used to convert C# strings (Unicode) into MBCS strings, and also to interpret the hex byte arrays generated by the recorder. Therefore the codepage attribute should always be set, especially if the recorder generated hex byte arrays when encountering otherwise unprintable characters.
  • A compiletime-check makes sure that all strings work for the defined codepage.

If the CodePage attribute is not defined in a C# script, the system codepage is used during replay.