本文整理汇总了C#中ISessionImplementor.AfterTransactionCompletion方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionImplementor.AfterTransactionCompletion方法的具体用法?C# ISessionImplementor.AfterTransactionCompletion怎么用?C# ISessionImplementor.AfterTransactionCompletion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionImplementor
的用法示例。
在下文中一共展示了ISessionImplementor.AfterTransactionCompletion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnlistInDistributedTransactionIfNeeded
public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
{
if (session.TransactionContext != null)
return;
if (System.Transactions.Transaction.Current == null)
return;
var transactionContext = new DistributedTransactionContext(session, System.Transactions.Transaction.Current);
session.TransactionContext = transactionContext;
logger.DebugFormat("enlisted into DTC transaction: {0}", transactionContext.AmbientTransation.IsolationLevel);
session.AfterTransactionBegin(null);
transactionContext.AmbientTransation.TransactionCompleted += delegate(object sender, TransactionEventArgs e)
{
bool wasSuccessful = false;
try
{
wasSuccessful = e.Transaction.TransactionInformation.Status
== TransactionStatus.Committed;
}
catch (ObjectDisposedException ode)
{
logger.Warn("Completed transaction was disposed, assuming transaction rollback", ode);
}
session.AfterTransactionCompletion(wasSuccessful, null);
if (transactionContext.ShouldCloseSessionOnDistributedTransactionCompleted)
{
session.CloseSessionFromDistributedTransaction();
}
session.TransactionContext = null;
};
transactionContext.AmbientTransation.EnlistVolatile(transactionContext, EnlistmentOptions.EnlistDuringPrepareRequired);
}