Ejemplo n.º 1
0
            public Task <TResult> CommandAsync <TResult>(
                ICoreSession session,
                ReadPreference readPreference,
                DatabaseNamespace databaseNamespace,
                BsonDocument command,
                IEnumerable <Type1CommandMessageSection> commandPayloads,
                IElementNameValidator commandValidator,
                BsonDocument additionalOptions,
                Action <IMessageEncoderPostProcessor> postWriteAction,
                CommandResponseHandling responseHandling,
                IBsonSerializer <TResult> resultSerializer,
                MessageEncoderSettings messageEncoderSettings,
                CancellationToken cancellationToken)
            {
                var protocol = new CommandWireProtocol <TResult>(
                    CreateClusterClockAdvancingCoreSession(session),
                    readPreference,
                    databaseNamespace,
                    command,
                    commandPayloads,
                    commandValidator,
                    additionalOptions,
                    postWriteAction,
                    responseHandling,
                    resultSerializer,
                    messageEncoderSettings);

                return(ExecuteProtocolAsync(protocol, cancellationToken));
            }
        // constructors
        public CommandUsingCommandMessageWireProtocol(
            ICoreSession session,
            ReadPreference readPreference,
            DatabaseNamespace databaseNamespace,
            BsonDocument command,
            IEnumerable <Type1CommandMessageSection> commandPayloads,
            IElementNameValidator commandValidator,
            BsonDocument additionalOptions,
            CommandResponseHandling responseHandling,
            IBsonSerializer <TCommandResult> resultSerializer,
            MessageEncoderSettings messageEncoderSettings,
            Action <IMessageEncoderPostProcessor> postWriteAction)
        {
            if (responseHandling != CommandResponseHandling.Return && responseHandling != CommandResponseHandling.NoResponseExpected)
            {
                throw new ArgumentException("CommandResponseHandling must be Return or NoneExpected.", nameof(responseHandling));
            }

            _session                = Ensure.IsNotNull(session, nameof(session));
            _readPreference         = readPreference;
            _databaseNamespace      = Ensure.IsNotNull(databaseNamespace, nameof(databaseNamespace));
            _command                = Ensure.IsNotNull(command, nameof(command));
            _commandPayloads        = commandPayloads?.ToList(); // can be null
            _commandValidator       = Ensure.IsNotNull(commandValidator, nameof(commandValidator));
            _additionalOptions      = additionalOptions;         // can be null
            _responseHandling       = responseHandling;
            _resultSerializer       = Ensure.IsNotNull(resultSerializer, nameof(resultSerializer));
            _messageEncoderSettings = messageEncoderSettings;
            _postWriteAction        = postWriteAction; // can be null
        }
Ejemplo n.º 3
0
        public void ResponseHandling_set_should_have_expected_result(
            [Values(CommandResponseHandling.Return, CommandResponseHandling.Ignore)] CommandResponseHandling value)
        {
            var subject = new QueryMessage(_requestId, _collectionNamespace, _query, _fields, _queryValidator, _skip, _batchSize, false, false, false, false, false, false);

            subject.ResponseHandling = value;

            subject.ResponseHandling.Should().Be(value);
        }
Ejemplo n.º 4
0
        public void ResponseHandling_set_should_throw_when_value_is_invalid(
            [Values(-1, CommandResponseHandling.NoResponseExpected)] CommandResponseHandling value)
        {
            var subject = new QueryMessage(_requestId, _collectionNamespace, _query, _fields, _queryValidator, _skip, _batchSize, false, false, false, false, false, false);

            var exception = Record.Exception(() => subject.ResponseHandling = value);

            var e = exception.Should().BeOfType <ArgumentException>().Subject;

            e.ParamName.Should().Be("value");
        }
Ejemplo n.º 5
0
        public void ResponseHandling_get_should_return_expected_result(
            [Values(CommandResponseHandling.Return, CommandResponseHandling.Ignore)] CommandResponseHandling value)
        {
#pragma warning disable 618
            var subject = new QueryMessage(_requestId, _collectionNamespace, _query, _fields, _queryValidator, _skip, _batchSize, false, false, false, false, false, false)
            {
                ResponseHandling = value
            };
#pragma warning restore 618

            var result = subject.ResponseHandling;

            result.Should().Be(value);
        }
Ejemplo n.º 6
0
 internal static CommandWireProtocol <BsonDocument> CreateProtocol(
     BsonDocument isMasterCommand,
     ServerApi serverApi,
     CommandResponseHandling commandResponseHandling = CommandResponseHandling.Return)
 {
     return(new CommandWireProtocol <BsonDocument>(
                databaseNamespace: DatabaseNamespace.Admin,
                command: isMasterCommand,
                slaveOk: true,
                commandResponseHandling: commandResponseHandling,
                resultSerializer: BsonDocumentSerializer.Instance,
                messageEncoderSettings: null,
                serverApi));
 }
Ejemplo n.º 7
0
 public CommandWireProtocol(
     DatabaseNamespace databaseNamespace,
     BsonDocument command,
     bool slaveOk,
     CommandResponseHandling commandResponseHandling,
     IBsonSerializer <TCommandResult> resultSerializer,
     MessageEncoderSettings messageEncoderSettings)
     : this(
         NoCoreSession.Instance,
         slaveOk ? ReadPreference.PrimaryPreferred : ReadPreference.Primary,
         databaseNamespace,
         command,
         null, // commandPayloads
         NoOpElementNameValidator.Instance,
         null, // additionalOptions
         null, // postWriteAction
         commandResponseHandling,
         resultSerializer,
         messageEncoderSettings)
 {
 }
        private int _previousRequestId;   // RequestId from the previous response

        // constructors
        public CommandUsingCommandMessageWireProtocol(
            ICoreSession session,
            ReadPreference readPreference,
            DatabaseNamespace databaseNamespace,
            BsonDocument command,
            IEnumerable <Type1CommandMessageSection> commandPayloads,
            IElementNameValidator commandValidator,
            BsonDocument additionalOptions,
            CommandResponseHandling responseHandling,
            IBsonSerializer <TCommandResult> resultSerializer,
            MessageEncoderSettings messageEncoderSettings,
            Action <IMessageEncoderPostProcessor> postWriteAction,
            ServerApi serverApi)
        {
            if (responseHandling != CommandResponseHandling.Return &&
                responseHandling != CommandResponseHandling.NoResponseExpected &&
                responseHandling != CommandResponseHandling.ExhaustAllowed)
            {
                throw new ArgumentException("CommandResponseHandling must be Return, NoneExpected or ExhaustAllowed.", nameof(responseHandling));
            }

            _session                = Ensure.IsNotNull(session, nameof(session));
            _readPreference         = readPreference;
            _databaseNamespace      = Ensure.IsNotNull(databaseNamespace, nameof(databaseNamespace));
            _command                = Ensure.IsNotNull(command, nameof(command));
            _commandPayloads        = commandPayloads?.ToList(); // can be null
            _commandValidator       = Ensure.IsNotNull(commandValidator, nameof(commandValidator));
            _additionalOptions      = additionalOptions;         // can be null
            _responseHandling       = responseHandling;
            _resultSerializer       = Ensure.IsNotNull(resultSerializer, nameof(resultSerializer));
            _messageEncoderSettings = messageEncoderSettings;
            _postWriteAction        = postWriteAction; // can be null
            _serverApi              = serverApi;       // can be null

            if (messageEncoderSettings != null)
            {
                _documentFieldDecryptor = messageEncoderSettings.GetOrDefault <IBinaryDocumentFieldDecryptor>(MessageEncoderSettingsName.BinaryDocumentFieldDecryptor, null);
                _documentFieldEncryptor = messageEncoderSettings.GetOrDefault <IBinaryCommandFieldEncryptor>(MessageEncoderSettingsName.BinaryDocumentFieldEncryptor, null);
            }
        }
Ejemplo n.º 9
0
 public static void _responseHandling(this CommandWireProtocol <BsonDocument> commandWireProtocol, CommandResponseHandling commandResponseHandling)
 {
     Reflector.SetFieldValue(commandWireProtocol, nameof(_responseHandling), commandResponseHandling);
 }