Defining a Transaction in .NET

A transaction in .NET is a public (non virtual) .NET method of your virtual user class that has the SilkPerformer.Transaction attribute applied to it. There are three types of transactions, init, main, and end. There can only be one init and one end transaction for each virtual user class, but there can be multiple main transaction methods.

The transaction type is passed as the first parameter. ETransactionType is an enum that defines the possible types.

SilkPerformer.ETransactionType:
  • TRANSTYPE_INIT
  • TRANSTYPE_MAIN
  • TRANSTYPE_END

Transactions of type main have an optional second parameter that defines the number of transaction calls - the default value is 1.

Example

C# Code BDL Script
[VirtualUser("Vuser1")]
public class MyTestUser1
{
  [Transaction(
    Etranstype.TRANSTYPE_INIT)]
  public void TInit()
  {
  }
  [Transaction(
    Etranstype.TRANSTYPE_MAIN)]
  public void TMain()
  {
  }
  [Transaction(
    Etranstype.TRANSTYPE_MAIN, 5)]
  public void TMain2()
  {
  }
  [Transaction(
    Etranstype.TRANSTYPE_END)]
  public void TEnd()
  {
  }
}
dcluser
  user
    Vuser1
  transactions
    TInit : begin;
    TMain : 1;
    TMain2 : 5;
    TEnd : end;

var hVuser1 : number;

dcltrans
  transaction TInit
  begin
    hVuser1:=
    DotNetLoadObject("..","MyTestUser1");
    DotNetCallMethod(hVuser1,"TInit");
  end;
  
  transaction TMain
  begin
    DotNetCallMethod(hVuser1,"TMain");
  end;
  transaction TMain2
  begin
    DotNetCallMethod(hVuser1,"TMain2");
  end;

  transaction TEnd
  begin
    DotNetCallMethod(hVuser1,"TEnd");
    DotNetFreeObject(hVuser1);
  end;

The add-on script generator scripts an init and an end transaction even if there are no corresponding .NET methods. These are used to load the .NET object in the init transaction and free it in the end transaction.

As you can see from the sample above, the transactions contain a DotNetCallMethod to call the .NET test driver method.