Exemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
                using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
                    using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel))
                    {
                        var          operation = CreateOperation(channel.ConnectionDescription.ServerVersion);
                        BsonDocument result;
                        try
                        {
                            result = await operation.ExecuteAsync(channelBinding, cancellationToken).ConfigureAwait(false);
                        }
                        catch (MongoCommandException ex)
                        {
                            if (!ShouldIgnoreException(ex))
                            {
                                throw;
                            }
                            result = ex.Result;
                        }
                        WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                        return(result);
                    }
        }
Exemplo n.º 2
0
        // public methods
        /// <inheritdoc/>
        public BsonDocument Execute(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
                using (var channel = channelSource.GetChannel(cancellationToken))
                    using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
                    {
                        var          operation = CreateOperation(channelBinding.Session, channel.ConnectionDescription);
                        BsonDocument result;
                        try
                        {
                            result = operation.Execute(channelBinding, cancellationToken);
                        }
                        catch (MongoCommandException ex)
                        {
                            if (!ShouldIgnoreException(ex))
                            {
                                throw;
                            }
                            result = ex.Result;
                        }
                        WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                        return(result);
                    }
        }
Exemplo n.º 3
0
        public void ThrowIfHasWriteConcernError_should_not_throw_when_there_is_no_write_concern_error()
        {
            var connectionId = CreateConnectionId();
            var result       = BsonDocument.Parse("{ ok : 1 }");

            WriteConcernErrorHelper.ThrowIfHasWriteConcernError(connectionId, result);
        }
Exemplo n.º 4
0
 // public methods
 /// <inheritdoc/>
 public BsonDocument Execute(IWriteBinding binding, CancellationToken cancellationToken)
 {
     using (EventContext.BeginOperation())
         using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
             using (var channel = channelSource.GetChannel(cancellationToken))
                 using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
                 {
                     var operation = CreateOperation(channel.ConnectionDescription.ServerVersion);
                     var result    = operation.Execute(channelBinding, cancellationToken);
                     WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                     return(result);
                 }
 }
Exemplo n.º 5
0
        // public methods
        /// <inheritdoc/>
        public BsonDocument Execute(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (var channelSource = binding.GetWriteChannelSource(cancellationToken))
                using (var channel = channelSource.GetChannel(cancellationToken))
                    using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel))
                    {
                        var operation = CreateOperation(channel.ConnectionDescription.ServerVersion);
                        var result    = operation.Execute(binding, cancellationToken);
                        WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                        return(result);
                    }
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            using (EventContext.BeginOperation())
                using (var channelSource = await binding.GetWriteChannelSourceAsync(cancellationToken).ConfigureAwait(false))
                    using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
                        using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
                        {
                            var operation = CreateOperation(channel.ConnectionDescription.ServerVersion);
                            var result    = await operation.ExecuteAsync(channelBinding, cancellationToken).ConfigureAwait(false);

                            WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                            return(result);
                        }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public virtual async Task <BsonDocument> ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));

            using (var channelSource = await binding.GetReadChannelSourceAsync(cancellationToken).ConfigureAwait(false))
                using (var channel = await channelSource.GetChannelAsync(cancellationToken).ConfigureAwait(false))
                    using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork()))
                    {
                        var operation = CreateOperation();
                        var result    = await operation.ExecuteAsync(channelBinding, cancellationToken).ConfigureAwait(false);

                        WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result);
                        return(result);
                    }
        }
Exemplo n.º 8
0
        public void ThrowIfHasWriteConcernError_should_throw_when_there_is_a_write_concern_error()
        {
            var connectionId = CreateConnectionId();
            var result       = BsonDocument.Parse("{ ok : 1, writeConcernError : { errmsg : 'message' } }");

            var exception = Record.Exception(() => WriteConcernErrorHelper.ThrowIfHasWriteConcernError(connectionId, result));

            var writeConcernException = exception.Should().BeOfType <MongoWriteConcernException>().Subject;

            writeConcernException.ConnectionId.Should().BeSameAs(connectionId);
            writeConcernException.Message.Should().Be(result["writeConcernError"]["errmsg"].AsString);
            var writeConcernResult = writeConcernException.WriteConcernResult;

            writeConcernResult.Response.Should().BeSameAs(result);
        }