Ejemplo n.º 1
0
        /// <inheritdoc/>
        public Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation <BsonDocument>(CollectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, MessageEncoderSettings);

            return(operation.ExecuteAsync(binding, cancellationToken));
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));
            var command   = CreateCommand();
            var operation = new WriteCommandOperation <BsonDocument>(_collectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false));
        }
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation(_databaseNamespace, command, _messageEncoderSettings);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 4
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation("admin", command);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
Ejemplo n.º 5
0
 // constructors
 public Builder(WriteCommandOperation <TCommandResult> other)
 {
     _additionalOptions = other.AdditionalOptions;
     _command           = other.Command;
     _comment           = other.Comment;
     _databaseName      = other.DatabaseName;
     _resultSerializer  = other.ResultSerializer;
 }
        public async Task <BsonDocument> ExecuteCommandAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation(_collectionNamespace.DatabaseNamespace, command, _messageEncoderSettings);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public async Task <BsonValue> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation <BsonDocument>(_databaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
            var result    = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);

            return(result["retval"]);
        }
Ejemplo n.º 8
0
        public async Task <BsonValue> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation(_databaseNamespace, command, _messageEncoderSettings);
            var result    = await operation.ExecuteAsync(binding, timeout, cancellationToken).ConfigureAwait(false);

            return(result["retval"]);
        }
        private Task <BsonDocument> ExecuteUsingCommandAsync(IChannelSourceHandle channelSource, CancellationToken cancellationToken)
        {
            var databaseNamespace = _collectionNamespace.DatabaseNamespace;
            var command           = CreateCommand();
            var resultSerializer  = BsonDocumentSerializer.Instance;
            var operation         = new WriteCommandOperation <BsonDocument>(databaseNamespace, command, resultSerializer, _messageEncoderSettings);

            return(operation.ExecuteAsync(channelSource, cancellationToken));
        }
Ejemplo n.º 10
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            EnsureIsOutputToCollectionPipeline();

            var command   = CreateCommand();
            var operation = new WriteCommandOperation(DatabaseName, command);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
        private WriteCommandOperation <BsonDocument> CreateOperation(ICoreSessionHandle session, ConnectionDescription connectionDescription, ReadPreference effectiveReadPreference)
        {
            var command   = CreateCommand(session, connectionDescription);
            var operation = new WriteCommandOperation <BsonDocument>(_databaseNamespace, command, BsonDocumentSerializer.Instance, MessageEncoderSettings);

            if (effectiveReadPreference != null)
            {
                operation.ReadPreference = effectiveReadPreference;
            }
            return(operation);
        }
Ejemplo n.º 12
0
        /// <inheritdoc/>
        public Task <TResult> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation <TResult>(_collectionNamespace.DatabaseNamespace, command, _resultSerializer, _messageEncoderSettings)
            {
                CommandValidator = GetCommandValidator()
            };

            return(operation.ExecuteAsync(binding, cancellationToken));
        }
        protected Profiler Profile(DatabaseNamespace databaseNamespace)
        {
            var op = new WriteCommandOperation <BsonDocument>(
                _databaseNamespace,
                new BsonDocument("profile", 2),
                BsonDocumentSerializer.Instance,
                new MessageEncoderSettings());

            ExecuteOperation(op);

            return(new Profiler(this, databaseNamespace));
        }
Ejemplo n.º 14
0
        /// <inheritdoc/>
        public Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            var command = CreateCommand();

            var operation = new WriteCommandOperation <BsonDocument>(
                _databaseNamespace,
                command,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings);

            return(operation.ExecuteAsync(binding, cancellationToken));
        }
        public async Task <BsonDocument> ExplainAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            EnsureIsOutputToCollectionPipeline();

            var command = CreateCommand();

            command["explain"] = true;
            var operation = new WriteCommandOperation(CollectionNamespace.DatabaseNamespace, command, MessageEncoderSettings);

            return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
        public Task <TResult> ExecuteAsync(IWriteBinding binding, TimeSpan timeout, System.Threading.CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command = CreateCommand();
            var nullableDeserializer = new PossiblyNullDeserializer(_resultSerializer);
            var serializer           = new ElementDeserializer <TResult>("value", nullableDeserializer);
            var operation            = new WriteCommandOperation <TResult>(_collectionNamespace.DatabaseNamespace, command, serializer, _messageEncoderSettings)
            {
                CommandValidator = GetCommandValidator()
            };

            return(operation.ExecuteAsync(binding, timeout, cancellationToken));
        }
            public void Dispose()
            {
                var turnOff = new WriteCommandOperation <BsonDocument>(
                    _databaseNamespace,
                    new BsonDocument("profile", 0),
                    BsonDocumentSerializer.Instance,
                    new MessageEncoderSettings());

                _testBase.ExecuteOperation(turnOff);

                var drop = new DropCollectionOperation(CollectionNamespace, new MessageEncoderSettings());

                _testBase.ExecuteOperation(drop);
            }
Ejemplo n.º 18
0
        // methods
        public async Task <Cursor <BsonDocument> > ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");

            var slidingTimeout = new SlidingTimeout(timeout);

            using (var connectionSource = await binding.GetWriteConnectionSourceAsync(slidingTimeout, cancellationToken))
            {
                var command   = CreateCommand();
                var operation = new WriteCommandOperation(CollectionNamespace.DatabaseNamespace, command, MessageEncoderSettings);
                var result    = await operation.ExecuteAsync(connectionSource, slidingTimeout, cancellationToken);

                return(CreateCursor(connectionSource, command, result, timeout, cancellationToken));
            }
        }
Ejemplo n.º 19
0
        public void constructor_should_initialize_instance()
        {
            var databaseNamespace      = new DatabaseNamespace("databaseName");
            var command                = new BsonDocument("command", 1);
            var resultSerializer       = BsonDocumentSerializer.Instance;
            var messageEncoderSettings = new MessageEncoderSettings();

            var result = new WriteCommandOperation <BsonDocument>(databaseNamespace, command, resultSerializer, messageEncoderSettings);

            result.AdditionalOptions.Should().BeNull();
            result.Command.Should().BeSameAs(command);
            result.CommandValidator.Should().BeOfType <NoOpElementNameValidator>();
            result.Comment.Should().BeNull();
            result.DatabaseNamespace.Should().BeSameAs(databaseNamespace);
            result.MessageEncoderSettings.Should().BeSameAs(messageEncoderSettings);
            result.ResultSerializer.Should().BeSameAs(resultSerializer);
        }
Ejemplo n.º 20
0
        /// <inheritdoc/>
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation <BsonDocument>(_collectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            try
            {
                return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false));
            }
            catch (MongoCommandException ex)
            {
                if (ex.ErrorMessage != null && ex.ErrorMessage.Contains("ns not found"))
                {
                    return(ex.Result);
                }
                throw;
            }
        }
Ejemplo n.º 21
0
        public async Task <BsonDocument> ExecuteAsync(IWriteBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            var command   = CreateCommand();
            var operation = new WriteCommandOperation(_collectionNamespace.DatabaseNamespace, command, _messageEncoderSettings);

            try
            {
                return(await operation.ExecuteAsync(binding, timeout, cancellationToken));
            }
            catch (MongoCommandException ex)
            {
                var result = ex.Result;
                if ((string)result["errmsg"] == "ns not found")
                {
                    return(result);
                }
                throw;
            }
        }
Ejemplo n.º 22
0
        protected void CreateCollection(CollectionNamespace collectionNamespace, bool changeStreamPreAndPostImages = false)
        {
            var operation = new CreateCollectionOperation(collectionNamespace, _messageEncoderSettings);

            ExecuteOperation(operation);

            if (changeStreamPreAndPostImages)
            {
                var command = new BsonDocument()
                {
                    { "collMod", _collectionNamespace.CollectionName },
                    { "changeStreamPreAndPostImages", new BsonDocument()
                      {
                          { "enabled", true }
                      } }
                };

                var collModOperation = new WriteCommandOperation <BsonDocument>(_collectionNamespace.DatabaseNamespace, command, BsonDocumentSerializer.Instance, _messageEncoderSettings);
                ExecuteOperation(collModOperation);
            }
        }