本文整理汇总了VB.NET中System.EnterpriseServices.CompensatingResourceManager.Compensator类的典型用法代码示例。如果您正苦于以下问题:VB.NET Compensator类的具体用法?VB.NET Compensator怎么用?VB.NET Compensator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Compensator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: AccountCompensator
' A CRM Compensator
Public Class AccountCompensator
Inherits Compensator
Private receivedPrepareRecord As Boolean = False
Public Overrides Sub BeginPrepare()
End Sub
' nothing to do
Public Overrides Function PrepareRecord(ByVal log As LogRecord) As Boolean
' Check the validity of the record.
If log Is Nothing Then
Return True
End If
Dim record As [Object]() = log.Record
If record Is Nothing Then
Return True
End If
If record.Length <> 2 Then
Return True
End If
' The record is valid.
receivedPrepareRecord = True
Return False
End Function 'PrepareRecord
Public Overrides Function EndPrepare() As Boolean
' Allow the transaction to proceed onlyif we have received a prepare record.
If receivedPrepareRecord Then
Return True
Else
Return False
End If
End Function 'EndPrepare
Public Overrides Sub BeginCommit(ByVal commit As Boolean)
End Sub
' nothing to do
Public Overrides Function CommitRecord(ByVal log As LogRecord) As Boolean
' nothing to do
Return False
End Function 'CommitRecord
Public Overrides Sub EndCommit()
End Sub
' nothing to do
Public Overrides Sub BeginAbort(ByVal abort As Boolean)
End Sub
' nothing to do
Public Overrides Function AbortRecord(ByVal log As LogRecord) As Boolean
' Check the validity of the record.
If log Is Nothing Then
Return True
End If
Dim record As [Object]() = log.Record
If record Is Nothing Then
Return True
End If
If record.Length <> 2 Then
Return True
End If
' Extract old account data from the record.
Dim filename As String = CStr(record(0))
Dim balance As Integer = Fix(record(1))
' Restore the old state of the account.
AccountManager.WriteAccountBalance(filename, balance)
Return False
End Function 'AbortRecord
Public Overrides Sub EndAbort()
End Sub
End Class
示例2: Account
' A CRM Worker
<Transaction()> _
Public Class Account
Inherits ServicedComponent
' A data member for the account file name.
Private filename As String
Public Property Filenam() As String
Get
Return Filename
End Get
Set(ByVal value As String)
filename = Value
End Set
End Property
' A boolean data member that determines whether to commit or abort the transaction.
Private commit As Boolean
Public Property AllowCommit() As Boolean
Get
Return commit
End Get
Set
commit = value
End Set
End Property
' Debit the account,
Public Sub DebitAccount(ByVal ammount As Integer)
' Create a new clerk using the AccountCompensator class.
Dim clerk As New Clerk(GetType(AccountCompensator), "An account transaction compensator", CompensatorOptions.AllPhases)
' Create a record of previous account status, and deliver it to the clerk.
Dim balance As Integer = AccountManager.ReadAccountBalance(Filenam)
Dim record(1) As [Object]
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 Then
ContextUtil.SetComplete()
Else
ContextUtil.SetAbort()
End If
End Sub
End Class
示例3: Main
Public Class CrmClient
Public Shared Sub Main()
' Create a new account object. The object is created in a COM+ server application.
Dim account As New Account()
' Transactionally debit the account.
Try
account.Filenam = System.IO.Path.GetFullPath("JohnDoe")
account.AllowCommit = True
account.DebitAccount(3)
Finally
account.Dispose()
End Try
End Sub
End Class