private async Task RunTransactionAsync(Func <CancellationToken, Task> txnFunc, IClientSessionHandle session, IClientSessionHandle parentSession = default(IClientSessionHandle), Action <Behavior> transactionBehaviorAction = default(Action <Behavior>), CancellationToken cancellationToken = default(CancellationToken)) { try { var transactionBehavior = new Behavior(); transactionBehaviorAction?.Invoke(transactionBehavior); transactionBehavior = transactionBehaviorAction == null ? this.configurationSource.Model.TransactionBehavior : default(Behavior); if (parentSession != null) { session.AdvanceClusterTime(parentSession.ClusterTime); session.AdvanceOperationTime(parentSession.OperationTime); } session.StartTransaction(transactionBehavior.ToTransactionOptions()); #if NETFULL await txnFunc(cancellationToken).ConfigureAwait(false); await commitRetryPolicy.ExecuteAsync((cToken) => CommitAsync(session, cToken), cancellationToken).ConfigureAwait(false); #else await txnFunc(cancellationToken); await commitRetryPolicy.ExecuteAsync((cToken) => CommitAsync(session, cToken), cancellationToken); #endif } catch (Exception) { #if NETFULL await session.AbortTransactionAsync(cancellationToken).ConfigureAwait(false); #else await session.AbortTransactionAsync(cancellationToken); #endif throw; } }
public void AdvanceOperationTime(BsonTimestamp newOperationTime) { _sessionHandle.AdvanceOperationTime(newOperationTime); }