Ejemplo n.º 1
0
        private ReadCommandOperation <TValue[]> CreateOperation(SemanticVersion serverVersion)
        {
            var command = CreateCommand(serverVersion);
            var valueArraySerializer = new ArraySerializer <TValue>(_valueSerializer);
            var resultSerializer     = new ElementDeserializer <TValue[]>("values", valueArraySerializer);

            return(new ReadCommandOperation <TValue[]>(_collectionNamespace.DatabaseNamespace, command, resultSerializer, _messageEncoderSettings));
        }
Ejemplo n.º 2
0
        private ReadCommandOperation <TValue[]> CreateOperation(IChannel channel, IBinding binding)
        {
            var command = CreateCommand(channel.ConnectionDescription, binding.Session);
            var valueArraySerializer = new ArraySerializer <TValue>(_valueSerializer);
            var resultSerializer     = new ElementDeserializer <TValue[]>("values", valueArraySerializer);

            return(new ReadCommandOperation <TValue[]>(_collectionNamespace.DatabaseNamespace, command, resultSerializer, _messageEncoderSettings));
        }
Ejemplo n.º 3
0
        private ReadCommandOperation <TResult[]> CreateOperation(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var command = CreateCommand(session, connectionDescription);
            var resultArraySerializer = new ArraySerializer <TResult>(_resultSerializer);
            var resultSerializer      = new ElementDeserializer <TResult[]>("results", resultArraySerializer);

            return(new ReadCommandOperation <TResult[]>(CollectionNamespace.DatabaseNamespace, command, resultSerializer, MessageEncoderSettings));
        }
Ejemplo n.º 4
0
        private ReadCommandOperation <TResult[]> CreateOperation(SemanticVersion serverVersion)
        {
            var command = CreateCommand(serverVersion);
            var resultArraySerializer = new ArraySerializer <TResult>(_resultSerializer);
            var resultSerializer      = new ElementDeserializer <TResult[]>("results", resultArraySerializer);

            return(new ReadCommandOperation <TResult[]>(CollectionNamespace.DatabaseNamespace, command, resultSerializer, MessageEncoderSettings));
        }
Ejemplo n.º 5
0
        private ReadCommandOperation <TResult[]> CreateOperation()
        {
            var command                 = CreateCommand();
            var resultSerializer        = _resultSerializer ?? BsonSerializer.LookupSerializer <TResult>();
            var resultArraySerializer   = new ArraySerializer <TResult>(resultSerializer);
            var commandResultSerializer = new ElementDeserializer <TResult[]>("retval", resultArraySerializer);

            return(new ReadCommandOperation <TResult[]>(_collectionNamespace.DatabaseNamespace, command, commandResultSerializer, _messageEncoderSettings));
        }
Ejemplo n.º 6
0
        public async Task <IReadOnlyList <TValue> > ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            var command = CreateCommand();
            var valueArraySerializer = new ArraySerializer <TValue>(_valueSerializer);
            var resultSerializer     = new ElementDeserializer <TValue[]>("values", valueArraySerializer);
            var operation            = new ReadCommandOperation <TValue[]>(_collectionNamespace.DatabaseNamespace, command, resultSerializer, _messageEncoderSettings);

            return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public async Task <IAsyncCursor <TResult> > ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));
            var command = CreateCommand();
            var resultArraySerializer = new ArraySerializer <TResult>(_resultSerializer);
            var resultSerializer      = new ElementDeserializer <TResult[]>("results", resultArraySerializer);
            var operation             = new ReadCommandOperation <TResult[]>(CollectionNamespace.DatabaseNamespace, command, resultSerializer, MessageEncoderSettings);
            var result = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false);

            return(new SingleBatchAsyncCursor <TResult>(result));
        }
        /// <inheritdoc/>
        public async Task <IEnumerable <TResult> > ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, nameof(binding));
            var command                 = CreateCommand();
            var resultSerializer        = _resultSerializer ?? BsonSerializer.LookupSerializer <TResult>();
            var resultArraySerializer   = new ArraySerializer <TResult>(resultSerializer);
            var commandResultSerializer = new ElementDeserializer <TResult[]>("retval", resultArraySerializer);
            var operation               = new ReadCommandOperation <TResult[]>(_collectionNamespace.DatabaseNamespace, command, commandResultSerializer, _messageEncoderSettings);

            return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 9
0
        private ReadCommandOperation <TResult[]> CreateOperation(SemanticVersion serverVersion)
        {
            var command                 = CreateCommand(serverVersion);
            var resultSerializer        = _resultSerializer ?? BsonSerializer.LookupSerializer <TResult>();
            var resultArraySerializer   = new ArraySerializer <TResult>(resultSerializer);
            var commandResultSerializer = new ElementDeserializer <TResult[]>("retval", resultArraySerializer);

            return(new ReadCommandOperation <TResult[]>(_collectionNamespace.DatabaseNamespace, command, commandResultSerializer, _messageEncoderSettings)
            {
                RetryRequested = false
            });
        }
        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 Execute_should_return_expected_results_when_ResultSerializer_is_set(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            EnsureTestData();
            var resultSerializer = new ElementDeserializer <double>("value", new DoubleSerializer());
            var subject          = new MapReduceOperation <double>(_collectionNamespace, _mapFunction, _reduceFunction, resultSerializer, _messageEncoderSettings);

            var cursor  = ExecuteOperation(subject, async);
            var results = ReadCursorToEnd(cursor, async);

            results.Should().Equal(3, 4);
        }
        public void Execute_should_return_expected_result_when_ResultSerializer_is_used(
            [Values(false, true)]
            bool async)
        {
            RequireServer.Check();
            EnsureTestData();
            var resultSerializer = new ElementDeserializer <int>("x", new Int32Serializer());
            var subject          = new GroupOperation <int>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
            {
                ResultSerializer = resultSerializer
            };

            var result = ExecuteOperation(subject, async);

            result.Should().Equal(1, 2, 3);
        }