ContextUtil 类

定义

获取有关 COM+ 对象上下文的信息。Obtains information about the COM+ object context. 无法继承此类。This class cannot be inherited.

public ref class ContextUtil sealed
public sealed class ContextUtil
type ContextUtil = class
Public NotInheritable Class ContextUtil
继承
ContextUtil

示例

下面的代码示例演示如何使用 ContextUtil 创建事务 ServicedComponentThe following code example demonstrates how to use ContextUtil to create a transactional ServicedComponent.


[assembly:System::Reflection::AssemblyKeyFile("Transaction.snk")];
[Transaction]
public ref class TransactionalComponent: public ServicedComponent
{
public:
   void TransactionalMethod( String^ data )
   {
      ContextUtil::DeactivateOnReturn = true;
      ContextUtil::MyTransactionVote = TransactionVote::Abort;
      
      // do work with data
      ContextUtil::MyTransactionVote = TransactionVote::Commit;
   }

};

[Transaction]
public class TransactionalComponent : ServicedComponent
{

    public void TransactionalMethod (string data)
    {

      ContextUtil.DeactivateOnReturn = true;
      ContextUtil.MyTransactionVote = TransactionVote.Abort;

      // Do work with data. Return if any errors occur.

      // Vote to commit. If any errors occur, this code will not execute.
      ContextUtil.MyTransactionVote = TransactionVote.Commit;
    }
}
<Transaction()>  _
Public Class TransactionalComponent
    Inherits ServicedComponent
    
    
    Public Sub TransactionalMethod(ByVal data As String) 
        
        ContextUtil.DeactivateOnReturn = True
        ContextUtil.MyTransactionVote = TransactionVote.Abort
        
        ' Do work with data. Return if any errors occur.
        ' Vote to commit. If any errors occur, this code will not execute.
        ContextUtil.MyTransactionVote = TransactionVote.Commit
    
    End Sub
End Class

注解

ContextUtil 是用于获取 COM + 上下文信息的首选类。ContextUtil is the preferred class to use for obtaining COM+ context information. 由于此类的成员全部 staticshared 在 Visual Basic 中),因此,在使用之前无需对其进行实例化。Because the members of this class are all static (shared in Visual Basic), it is not necessary to instantiate it before using them.

属性

ActivityId

获取一个 GUID,它表示包含组件的活动。Gets a GUID representing the activity containing the component.

ApplicationId

获取当前应用程序的 GUID。Gets a GUID for the current application.

ApplicationInstanceId

获取当前应用程序实例的 GUID。Gets a GUID for the current application instance.

ContextId

获取当前上下文的 GUID。Gets a GUID for the current context.

DeactivateOnReturn

获取或设置 COM+ 上下文中的 done 位。Gets or sets the done bit in the COM+ context.

IsInTransaction

获取一个值,该值指示当前上下文是否为事务性上下文。Gets a value that indicates whether the current context is transactional.

IsSecurityEnabled

获取一个值,该值指示基于角色的安全性在当前上下文中是否处于活动状态。Gets a value that indicates whether role-based security is active in the current context.

MyTransactionVote

获取或设置 COM+ 上下文中的 consistent 位。Gets or sets the consistent bit in the COM+ context.

PartitionId

获取当前分区的 GUID。Gets a GUID for the current partition.

SystemTransaction

获取当前事务上下文。Gets the current transaction context.

Transaction

获取描述当前 COM+ DTC 事务的对象。Gets an object describing the current COM+ DTC transaction.

TransactionId

获取当前 COM+ DTC 事务的 GUID。Gets the GUID of the current COM+ DTC transaction.

方法

DisableCommit()

在 COM+ 上下文中将 consistent 位和 done 位设置为 falseSets both the consistent bit and the done bit to false in the COM+ context.

EnableCommit()

在 COM+ 上下文中将 consistent 位设置为 true,并将 done 位设置为 falseSets the consistent bit to true and the done bit to false in the COM+ context.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetNamedProperty(String)

从 COM+ 上下文返回命名的属性。Returns a named property from the COM+ context.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsCallerInRole(String)

确定调用方是否属于指定角色。Determines whether the caller is in the specified role.

IsDefaultContext()

确定已维护的组件在默认上下文中是否激活。Determines whether the serviced component is activated in the default context. 在默认上下文中激活那些没有 COM+ 目录信息的已维护组件。Serviced components that do not have COM+ catalog information are activated in the default context.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetAbort()

在 COM+ 上下文中将 consistent 位设置为 false,并将 done 位设置为 trueSets the consistent bit to false and the done bit to true in the COM+ context.

SetComplete()

在 COM+ 上下文中设置 consistent 位,并将 done 位设置为 trueSets the consistent bit and the done bit to true in the COM+ context.

SetNamedProperty(String, Object)

设置 COM+ 上下文的命名属性。Sets the named property for the COM+ context.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于