public async Task <IClientSessionHandle> BeginSessionAsync(Action <SessionBehavior> sessionBehaviorAction = default(Action <SessionBehavior>), CancellationToken cancellationToken = default(CancellationToken)) { var sessionBehavior = new SessionBehavior(); sessionBehaviorAction?.Invoke(sessionBehavior); sessionBehavior = sessionBehaviorAction == null ? this.configurationSource.Model.SessionBehavior : default(SessionBehavior); var task = this.configurationSource.Source.StartSessionAsync(sessionBehavior.ToClientSessionOptions(), cancellationToken); #if NETFULL this.clientSessionHandle = await task.ConfigureAwait(false); #else this.clientSessionHandle = await task; #endif return(this.clientSessionHandle); }
public async Task DoTransactionAsync(Func <CancellationToken, Task> txnAction, Action <Behavior> transactionBehaviorAction = default(Action <Behavior>), Action <SessionBehavior> sessionBehaviorAction = default(Action <SessionBehavior>), IClientSessionHandle parentSession = default(IClientSessionHandle), CancellationToken cancellationToken = default(CancellationToken)) { var sessionBehavior = new SessionBehavior(); sessionBehaviorAction?.Invoke(sessionBehavior); sessionBehavior = sessionBehaviorAction == null ? this.configurationSource.Model.SessionBehavior : default(SessionBehavior); using (var session = await this.configurationSource.Source.StartSessionAsync(sessionBehavior.ToClientSessionOptions(), cancellationToken).ConfigureAwait(false)) { try { this.clientSessionHandle = session; var task = transactionRetryPolicy.ExecuteAsync((cToken) => RunTransactionAsync(txnAction, session, parentSession, transactionBehaviorAction, cToken), cancellationToken); #if NETFULL await task.ConfigureAwait(false); #else await task; #endif } catch (Exception) { this.clientSessionHandle = default(IClientSessionHandle); throw; } } this.clientSessionHandle = default(IClientSessionHandle); }