/// <inheritdoc/>
        public async Task <IEnumerable <WriteConcernResult> > ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (EventContext.BeginOperation())
                using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
                    using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
                    {
                        if (SupportedFeatures.AreWriteCommandsSupported(channel.ConnectionDescription.ServerVersion) && _writeConcern.IsAcknowledged)
                        {
                            var emulator = CreateEmulator();
                            var result   = await emulator.ExecuteAsync(channel, cancellationToken).ConfigureAwait(false);

                            return(new[] { result });
                        }
                        else
                        {
                            if (_documentSource.Batch == null)
                            {
                                return(await InsertMultipleBatchesAsync(channel, cancellationToken).ConfigureAwait(false));
                            }
                            else
                            {
                                var result = await InsertSingleBatchAsync(channel, cancellationToken).ConfigureAwait(false);

                                return(new[] { result });
                            }
                        }
                    }
        }
 public async Task <BulkWriteOperationResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
     {
         if (SupportedFeatures.AreWriteCommandsSupported(channel.ConnectionDescription.ServerVersion))
         {
             return(await ExecuteBatchesAsync(channel, cancellationToken).ConfigureAwait(false));
         }
         else
         {
             var emulator = CreateEmulator();
             return(await emulator.ExecuteAsync(channel, cancellationToken).ConfigureAwait(false));
         }
     }
 }
 // public methods
 public BulkWriteOperationResult Execute(IChannelHandle channel, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
     {
         if (SupportedFeatures.AreWriteCommandsSupported(channel.ConnectionDescription.ServerVersion))
         {
             return(ExecuteBatches(channel, cancellationToken));
         }
         else
         {
             var emulator = CreateEmulator();
             return(emulator.Execute(channel, cancellationToken));
         }
     }
 }
Esempio n. 4
0
        /// <inheritdoc/>
        public async Task <WriteConcernResult> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (EventContext.BeginOperation())
                using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
                    using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
                    {
                        if (SupportedFeatures.AreWriteCommandsSupported(channel.ConnectionDescription.ServerVersion) && _writeConcern.IsAcknowledged)
                        {
                            var emulator = CreateEmulator();
                            return(await emulator.ExecuteAsync(channel, cancellationToken).ConfigureAwait(false));
                        }
                        else
                        {
                            return(await ExecuteProtocolAsync(channel, cancellationToken).ConfigureAwait(false));
                        }
                    }
        }
Esempio n. 5
0
        // public methods
        /// <inheritdoc/>
        public WriteConcernResult Execute(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (EventContext.BeginOperation())
                using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
                    using (var channel = channelSource.GetChannel(cancellationToken))
                    {
                        if (SupportedFeatures.AreWriteCommandsSupported(channel.ConnectionDescription.ServerVersion) && _writeConcern.IsAcknowledged)
                        {
                            var emulator = CreateEmulator();
                            return(emulator.Execute(channel, cancellationToken));
                        }
                        else
                        {
                            return(ExecuteProtocol(channel, cancellationToken));
                        }
                    }
        }