public AuditProcess Get(IEventSource session) { var transaction = (object)session.GetCurrentTransaction() ?? System.Transactions.Transaction.Current; if (!_auditProcesses.TryGetValue(transaction, out var auditProcess)) { // No worries about registering a transaction twice - a transaction is single thread auditProcess = new AuditProcess(_revisionInfoGenerator, session); _auditProcesses[transaction] = auditProcess; var tranProcess = new transactionCompletionProcess(_auditProcesses, transaction); session.ActionQueue.RegisterProcess((IBeforeTransactionCompletionProcess)tranProcess); session.ActionQueue.RegisterProcess((IAfterTransactionCompletionProcess)tranProcess); } return(auditProcess); }
/// <summary> /// Gets the versioned transaction processor associated with the transaction. /// </summary> /// <exception cref="InvalidOperationException">If the session does not have a transaction.</exception> public VersionedTransactionProcessor Get(IEventSource session) { var transaction = session.GetCurrentTransaction(); if (transaction == null) { throw new InvalidOperationException("acts as versioned: transaction is required"); } return(_processors.GetOrAdd(transaction, tx => { var vp = new VersionedTransactionProcessor(session); // Register with the session so that the versioned transaction processor is invoked // just prior to the transaction commit, and that it is cleaned up after the transaction // has completed. var transactionCompletionProcess = new TransactionCompletionProcess(_processors, tx); session.ActionQueue.RegisterProcess((IBeforeTransactionCompletionProcess)transactionCompletionProcess); session.ActionQueue.RegisterProcess((IAfterTransactionCompletionProcess)transactionCompletionProcess); return vp; })); }