// public methods
        public virtual BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty<WriteRequest>();
            var hasWriteErrors = false;

            var decoratedRequests = DecorateRequests(_args.Requests);
            using (var enumerator = decoratedRequests.GetEnumerator())
            {
                var originalIndex = 0;
                Batch<WriteRequest> batch = new FirstBatch<WriteRequest>(enumerator);
                while (batch != null)
                {
                    if (hasWriteErrors && _args.IsOrdered)
                    {
                        remainingRequests = remainingRequests.Concat(batch.RemainingItems);
                        break;
                    }

                    var batchResult = ExecuteBatch(connection, batch, originalIndex);
                    batchResults.Add(batchResult);

                    hasWriteErrors |= batchResult.HasWriteErrors;
                    originalIndex += batchResult.BatchCount;
                    batch = batchResult.NextBatch;
                }
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;
            if (!serverInstance.Supports(FeatureId.WriteOpcodes))
            {
                throw new NotSupportedException("Write opcodes are not supported.");
            }

            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = new List<WriteRequest>();
            var hasWriteErrors = false;

            var originalIndex = 0;
            foreach (WriteRequest request in _args.Requests)
            {
                if (hasWriteErrors && _args.IsOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = EmulateSingleRequest(connection, request, originalIndex);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
        // public methods
        public virtual BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty <WriteRequest>();
            var hasWriteErrors    = false;

            var decoratedRequests = DecorateRequests(_args.Requests);

            using (var enumerator = decoratedRequests.GetEnumerator())
            {
                var originalIndex          = 0;
                Batch <WriteRequest> batch = new FirstBatch <WriteRequest>(enumerator);
                while (batch != null)
                {
                    if (hasWriteErrors && _args.IsOrdered)
                    {
                        remainingRequests = remainingRequests.Concat(batch.RemainingItems);
                        break;
                    }

                    var batchResult = ExecuteBatch(connection, batch, originalIndex);
                    batchResults.Add(batchResult);

                    hasWriteErrors |= batchResult.HasWriteErrors;
                    originalIndex  += batchResult.BatchCount;
                    batch           = batchResult.NextBatch;
                }
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests));
        }
        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty <WriteRequest>();
            var hasWriteErrors    = false;

            var runCount = 0;

            foreach (var run in FindRuns())
            {
                runCount++;

                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests = remainingRequests.Concat(run.Requests);
                    continue;
                }

                var batchResult = ExecuteBatch(connection, run);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
            }

            if (runCount == 0)
            {
                throw new InvalidOperationException("Bulk write operation is empty.");
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.Enabled);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests));
        }
Example #5
0
        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;

            if (!serverInstance.Supports(FeatureId.WriteOpcodes))
            {
                throw new NotSupportedException("Write opcodes are not supported.");
            }

            var batchResults      = new List <BulkWriteBatchResult>();
            var remainingRequests = new List <WriteRequest>();
            var hasWriteErrors    = false;

            var originalIndex = 0;

            foreach (WriteRequest request in _args.Requests)
            {
                if (hasWriteErrors && _args.IsOrdered)
                {
                    remainingRequests.Add(request);
                    continue;
                }

                var batchResult = EmulateSingleRequest(connection, request, originalIndex);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
                originalIndex++;
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _args.WriteConcern.Enabled);

            return(combiner.CreateResultOrThrowIfHasErrors(remainingRequests));
        }
        // public methods
        public BulkWriteResult Execute(MongoConnection connection)
        {
            var batchResults = new List<BulkWriteBatchResult>();
            var remainingRequests = Enumerable.Empty<WriteRequest>();
            var hasWriteErrors = false;

            var runCount = 0;
            foreach (var run in FindRuns())
            {
                runCount++;

                if (hasWriteErrors && _isOrdered)
                {
                    remainingRequests = remainingRequests.Concat(run.Requests);
                    continue;
                }

                var batchResult = ExecuteBatch(connection, run);
                batchResults.Add(batchResult);

                hasWriteErrors |= batchResult.HasWriteErrors;
            }

            if (runCount == 0)
            {
                throw new InvalidOperationException("Bulk write operation is empty.");
            }

            var combiner = new BulkWriteBatchResultCombiner(batchResults, _writeConcern.Enabled);
            return combiner.CreateResultOrThrowIfHasErrors(remainingRequests);
        }
 private BulkWriteResult CombineResults(params BulkWriteBatchResult[] batchResults)
 {
     var combiner = new BulkWriteBatchResultCombiner(batchResults, true);
     return combiner.CreateResultOrThrowIfHasErrors(Enumerable.Empty<WriteRequest>());
 }