private Task <BulkWriteOperationResult> ExecuteUpdatesAsync(IChannelHandle channel, IEnumerable <UpdateRequest> requests, CancellationToken cancellationToken)
        {
            var operation = new BulkUpdateOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                MaxBatchCount  = _maxBatchCount,
                MaxBatchLength = _maxBatchLength,
                IsOrdered      = _isOrdered,
                WriteConcern   = _writeConcern
            };

            return(operation.ExecuteAsync(channel, cancellationToken));
        }
Exemplo n.º 2
0
        private Task <BulkWriteResult> ExecuteUpdatesAsync(IConnectionHandle connection, IEnumerable <UpdateRequest> requests, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var operation = new BulkUpdateOperation(_databaseName, _collectionName, requests)
            {
                CheckElementNames = _checkElementNames,
                MaxBatchCount     = _maxBatchCount,
                MaxBatchLength    = _maxBatchLength,
                IsOrdered         = _isOrdered,
                ReaderSettings    = _readerSettings,
                WriteConcern      = _writeConcern,
                WriterSettings    = _writerSettings
            };

            return(operation.ExecuteAsync(connection, timeout, cancellationToken));
        }
        // methods
        public async Task <WriteConcernResult> ExecuteAsync(IConnectionHandle connection, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(connection, "connection");

            var requests = new[] { new UpdateRequest(_criteria, _update)
                                   {
                                       IsMultiUpdate = _isMulti, IsUpsert = _isUpsert
                                   } };

            var operation = new BulkUpdateOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                IsOrdered    = true,
                WriteConcern = _writeConcern
            };

            BulkWriteOperationResult    bulkWriteResult;
            BulkWriteOperationException bulkWriteException = null;

            try
            {
                bulkWriteResult = await operation.ExecuteAsync(connection, timeout, cancellationToken);
            }
            catch (BulkWriteOperationException ex)
            {
                bulkWriteResult    = ex.Result;
                bulkWriteException = ex;
            }

            var converter = new BulkWriteOperationResultConverter();

            if (bulkWriteException != null)
            {
                throw converter.ToWriteConcernException(bulkWriteException);
            }
            else
            {
                if (_writeConcern.IsAcknowledged)
                {
                    return(converter.ToWriteConcernResult(bulkWriteResult));
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 4
0
        // methods
        public async Task <WriteConcernResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(channel, "channel");

            var requests = new[] { _request };

            var operation = new BulkUpdateOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                IsOrdered    = true,
                WriteConcern = _writeConcern
            };

            BulkWriteOperationResult         bulkWriteResult;
            MongoBulkWriteOperationException bulkWriteException = null;

            try
            {
                bulkWriteResult = await operation.ExecuteAsync(channel, cancellationToken).ConfigureAwait(false);
            }
            catch (MongoBulkWriteOperationException ex)
            {
                bulkWriteResult    = ex.Result;
                bulkWriteException = ex;
            }

            var converter = new BulkWriteOperationResultConverter();

            if (bulkWriteException != null)
            {
                throw converter.ToWriteConcernException(channel.ConnectionDescription.ConnectionId, bulkWriteException);
            }
            else
            {
                if (_writeConcern.IsAcknowledged)
                {
                    return(converter.ToWriteConcernResult(bulkWriteResult));
                }
                else
                {
                    return(null);
                }
            }
        }
        // methods
        public async Task<WriteConcernResult> ExecuteAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(channel, "channel");

            var requests = new[] { _request };

            var operation = new BulkUpdateOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                IsOrdered = true,
                WriteConcern = _writeConcern
            };

            BulkWriteOperationResult bulkWriteResult;
            MongoBulkWriteOperationException bulkWriteException = null;
            try
            {
                bulkWriteResult = await operation.ExecuteAsync(channel, cancellationToken).ConfigureAwait(false);
            }
            catch (MongoBulkWriteOperationException ex)
            {
                bulkWriteResult = ex.Result;
                bulkWriteException = ex;
            }

            var converter = new BulkWriteOperationResultConverter();
            if (bulkWriteException != null)
            {
                throw converter.ToWriteConcernException(channel.ConnectionDescription.ConnectionId, bulkWriteException);
            }
            else
            {
                if (_writeConcern.IsAcknowledged)
                {
                    return converter.ToWriteConcernResult(bulkWriteResult);
                }
                else
                {
                    return null;
                }
            }
        }
        // methods
        public async Task<WriteConcernResult> ExecuteAsync(IConnectionHandle connection, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(connection, "connection");

            var requests = new[] { _request };

            var operation = new BulkUpdateOperation(_collectionNamespace, requests, _messageEncoderSettings)
            {
                IsOrdered = true,
                WriteConcern = _writeConcern
            };

            BulkWriteOperationResult bulkWriteResult;
            BulkWriteOperationException bulkWriteException = null;
            try
            {
                bulkWriteResult = await operation.ExecuteAsync(connection, timeout, cancellationToken);
            }
            catch (BulkWriteOperationException ex)
            {
                bulkWriteResult = ex.Result;
                bulkWriteException = ex;
            }

            var converter = new BulkWriteOperationResultConverter();
            if (bulkWriteException != null)
            {
                throw converter.ToWriteConcernException(bulkWriteException);
            }
            else
            {
                if (_writeConcern.IsAcknowledged)
                {
                    return converter.ToWriteConcernResult(bulkWriteResult);
                }
                else
                {
                    return null;
                }
            }
        }