private async Task <CursorBatch <TDocument> > ExecuteGetMoreCommandAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var          command = CreateGetMoreCommand();
            BsonDocument result;

            try
            {
                result = await channel.CommandAsync <BsonDocument>(
                    _channelSource.Session,
                    null, // readPreference
                    _collectionNamespace.DatabaseNamespace,
                    command,
                    null, // commandPayloads
                    NoOpElementNameValidator.Instance,
                    null, // additionalOptions
                    null, // postWriteAction
                    CommandResponseHandling.Return,
                    __getMoreCommandResultSerializer,
                    _messageEncoderSettings,
                    cancellationToken).ConfigureAwait(false);
            }
            catch (MongoCommandException ex) when(IsMongoCursorNotFoundException(ex))
            {
                throw new MongoCursorNotFoundException(channel.ConnectionDescription.ConnectionId, _cursorId, command);
            }

            return(CreateCursorBatch(result));
        }
 private async Task <BsonDocument> ExecuteProtocolAsync(IChannelHandle channel, BsonDocument command, Func <CommandResponseHandling> responseHandling, CancellationToken cancellationToken)
 {
     return((await channel.CommandAsync <BsonDocument>(
                 _collectionNamespace.DatabaseNamespace,
                 command,
                 NoOpElementNameValidator.Instance,
                 responseHandling,
                 false, // slaveOk
                 BsonDocumentSerializer.Instance,
                 _messageEncoderSettings,
                 cancellationToken).ConfigureAwait(false)) ?? new BsonDocument("ok", 1));
 }
Exemplo n.º 3
0
        private Task <BsonDocument> ExecuteProtocolAsync(IChannelHandle channel, BsonDocument command, CancellationToken cancellationToken)
        {
            var commandValidator = NoOpElementNameValidator.Instance;

            return(channel.CommandAsync <BsonDocument>(
                       _collectionNamespace.DatabaseNamespace,
                       command,
                       commandValidator,
                       false, // slaveOk
                       BsonDocumentSerializer.Instance,
                       _messageEncoderSettings,
                       cancellationToken));
        }
Exemplo n.º 4
0
        private Task <TCommandResult> ExecuteProtocolAsync(IChannelHandle channel, ServerDescription serverDescription, ReadPreference readPreference, CancellationToken cancellationToken)
        {
            var wrappedCommand = CreateWrappedCommand(serverDescription, readPreference);
            var slaveOk        = readPreference != null && readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary;

            return(channel.CommandAsync <TCommandResult>(
                       _databaseNamespace,
                       wrappedCommand,
                       _commandValidator,
                       slaveOk,
                       _resultSerializer,
                       _messageEncoderSettings,
                       cancellationToken));
        }
Exemplo n.º 5
0
        private async Task <CursorBatch <TDocument> > ExecuteGetMoreCommandAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateGetMoreCommand();
            var result  = await channel.CommandAsync <BsonDocument>(
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                () => CommandResponseHandling.Return,
                false, // slaveOk
                __getMoreCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken).ConfigureAwait(false);

            return(CreateCursorBatch(result));
        }
Exemplo n.º 6
0
        private async Task <CursorBatch <TDocument> > ExecuteProtocolAsync(IChannelHandle channel, ServerDescription serverDescription, ReadPreference readPreference, bool slaveOk, CancellationToken cancellationToken)
        {
            var command = CreateCommand(serverDescription, readPreference);

            var result = await channel.CommandAsync <BsonDocument>(
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                () => CommandResponseHandling.Return,
                slaveOk,
                __findCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken).ConfigureAwait(false);

            return(CreateCursorBatch(result));
        }
Exemplo n.º 7
0
        private Task <TCommandResult> ExecuteProtocolAsync(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
        {
            var additionalOptions = GetEffectiveAdditionalOptions();

            return(channel.CommandAsync(
                       session,
                       readPreference,
                       _databaseNamespace,
                       _command,
                       _commandValidator,
                       additionalOptions,
                       () => CommandResponseHandling.Return,
                       _resultSerializer,
                       _messageEncoderSettings,
                       cancellationToken));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Executes the protocol.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="session">The session.</param>
        /// <param name="readPreference">The read preference.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A Task whose result is the command result.
        /// </returns>
        protected Task <TCommandResult> ExecuteProtocolAsync(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
        {
            var additionalOptions = GetEffectiveAdditionalOptions();

            return(channel.CommandAsync(
                       session,
                       readPreference,
                       _databaseNamespace,
                       _command,
                       null, // TODO: support commandPayloads
                       _commandValidator,
                       additionalOptions,
                       null, // postWriteAction,
                       CommandResponseHandling.Return,
                       _resultSerializer,
                       _messageEncoderSettings,
                       cancellationToken));
        }
Exemplo n.º 9
0
        private async Task <CursorBatch <TDocument> > ExecuteGetMoreCommandAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateGetMoreCommand();
            var result  = await channel.CommandAsync <BsonDocument>(
                _channelSource.Session,
                null, // readPreference
                _collectionNamespace.DatabaseNamespace,
                command,
                null, // commandPayloads
                NoOpElementNameValidator.Instance,
                null, // additionalOptions
                null, // postWriteAction
                CommandResponseHandling.Return,
                __getMoreCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken).ConfigureAwait(false);

            return(CreateCursorBatch(result));
        }
        private async Task ExecuteKillCursorsCommandAsync(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateKillCursorsCommand();
            var result  = await channel.CommandAsync(
                _channelSource.Session,
                null, // readPreference
                _collectionNamespace.DatabaseNamespace,
                command,
                null, // commandPayloads
                NoOpElementNameValidator.Instance,
                null, // additionalOptions
                null, // postWriteAction
                CommandResponseHandling.Return,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings,
                cancellationToken)
                          .ConfigureAwait(false);

            ThrowIfKillCursorsCommandFailed(result, channel.ConnectionDescription.ConnectionId);
        }