Clerk Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Writes records of transactional actions to a log.

Namespace:   System.EnterpriseServices.CompensatingResourceManager
Assembly:  System.EnterpriseServices (in System.EnterpriseServices.dll)

System.Object
  System.EnterpriseServices.CompensatingResourceManager.Clerk

public sealed class Clerk

NameDescription
System_CAPS_pubmethodClerk(String, String, CompensatorOptions)

Initializes a new instance of the Clerk class.

System_CAPS_pubmethodClerk(Type, String, CompensatorOptions)

Initializes a new instance of the Clerk class.

NameDescription
System_CAPS_pubpropertyLogRecordCount

Gets the number of log records.

System_CAPS_pubpropertyTransactionUOW

Gets a value representing the transaction unit of work (UOW).

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Frees the resources of the current Clerk before it is reclaimed by the garbage collector.(Overrides Object.Finalize().)

System_CAPS_pubmethodForceLog()

Forces all log records to disk.

System_CAPS_pubmethodForceTransactionToAbort()

Performs an immediate abort call on the transaction.

System_CAPS_pubmethodForgetLogRecord()

Does not deliver the last log record that was written by this instance of this interface.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodWriteLogRecord(Object)

Writes unstructured log records to the log.

Each clerk is associated with a compensator, which is called back to perform actions during the two-phase commit of the transaction.

The following code example demonstrates the use of this class.

// A CRM Worker
[Transaction]
public class Account : ServicedComponent
{

    // A data member for the account file name.
    private string filename;

    public string Filename
    {
        get
        {
            return(filename);
        }
        set
        {
            filename = value;
        }
    }


    // A boolean data member that determines whether to commit or abort the transaction.
    private bool commit;

    public bool AllowCommit
    {
        get
        {
            return(commit);
        }
        set
        {
            commit = value;
        }
    }



    // Debit the account, 
    public void DebitAccount (int ammount)
    {

        // Create a new clerk using the AccountCompensator class.
        Clerk clerk = new Clerk(typeof(AccountCompensator),
          "An account transaction compensator", CompensatorOptions.AllPhases);

        // Create a record of previous account status, and deliver it to the clerk.
        int balance = AccountManager.ReadAccountBalance(filename);

	Object[] record = new Object[2];
	record[0] = filename;
        record[1] = balance;

        clerk.WriteLogRecord(record);
        clerk.ForceLog();

        // Perform the transaction
        balance -= ammount;
        AccountManager.WriteAccountBalance(filename, balance);

        // Commit or abort the transaction 
        if (commit)
        {
            ContextUtil.SetComplete();
        }
        else
        {
            ContextUtil.SetAbort();
        }

    }

}

The following code example demonstrates the corresponding Compensator class.

using System;

public class CrmClient
{

    public static void Main ()
    {

        // Create a new account object. The object is created in a COM+ server application.
        Account account = new Account();

        // Transactionally debit the account.
        try
        {
            account.Filename = System.IO.Path.GetFullPath("JohnDoe");
            account.AllowCommit = true;
            account.DebitAccount(3);
        }
        finally
        {
            account.Dispose();
        }

    }

}

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: