Exemple #1
0
        public async Task <IAsyncCursor <TDocument> > ExecuteAsync(IReadBinding binding, TimeSpan timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");

            var slidingTimeout = new SlidingTimeout(timeout);

            using (var connectionSource = await binding.GetReadConnectionSourceAsync(slidingTimeout, cancellationToken).ConfigureAwait(false))
            {
                var query    = CreateWrappedQuery(connectionSource.ServerDescription, binding.ReadPreference);
                var protocol = CreateProtocol(query, binding.ReadPreference);
                var batch    = await protocol.ExecuteAsync(connectionSource, slidingTimeout, cancellationToken).ConfigureAwait(false);

                return(new AsyncCursor <TDocument>(
                           connectionSource.Fork(),
                           _collectionNamespace,
                           query,
                           batch.Documents,
                           batch.CursorId,
                           _batchSize ?? 0,
                           Math.Abs(_limit ?? 0),
                           _resultSerializer,
                           _messageEncoderSettings,
                           timeout,
                           cancellationToken));
            }
        }
Exemple #2
0
        public static async Task <TResult> ExecuteAsync <TResult>(
            this IWireProtocol <TResult> protocol,
            IReadBinding binding,
            TimeSpan timeout = default(TimeSpan),
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(protocol, "protocol");
            var slidingTimeout = new SlidingTimeout(timeout);

            using (var connectionSource = await binding.GetReadConnectionSourceAsync(slidingTimeout, cancellationToken))
                using (var connection = await connectionSource.GetConnectionAsync(slidingTimeout, cancellationToken))
                {
                    return(await protocol.ExecuteAsync(connection, slidingTimeout, cancellationToken));
                }
        }
        public async Task <Cursor <BsonDocument> > ExecuteAsync(IReadBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(binding, "binding");
            EnsureIsReadOnlyPipeline();

            var slidingTimeout = new SlidingTimeout(timeout);

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

                return(CreateCursor(connectionSource, command, result, timeout, cancellationToken));
            }
        }
        // methods
        public async Task <IEnumerable <BsonDocument> > ExecuteAsync(IReadBinding binding, TimeSpan timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");

            var slidingTimeout = new SlidingTimeout(timeout);

            using (var connectionSource = await binding.GetReadConnectionSourceAsync(slidingTimeout, cancellationToken).ConfigureAwait(false))
            {
                if (connectionSource.ServerDescription.Version >= __serverVersionSupportingListIndexesCommand)
                {
                    return(await ExecuteUsingCommandAsync(connectionSource, binding.ReadPreference, slidingTimeout, cancellationToken).ConfigureAwait(false));
                }
                else
                {
                    return(await ExecuteUsingQueryAsync(connectionSource, binding.ReadPreference, slidingTimeout, cancellationToken).ConfigureAwait(false));
                }
            }
        }
Exemple #5
0
        // methods
        public async Task <IAsyncCursor <TResult> > ExecuteAsync(IReadBinding binding, TimeSpan timeout, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(binding, "binding");
            EnsureIsReadOnlyPipeline();

            var slidingTimeout = new SlidingTimeout(timeout);

            using (var connectionSource = await binding.GetReadConnectionSourceAsync(slidingTimeout, cancellationToken))
            {
                var command = CreateCommand(connectionSource.ServerDescription.Version);

                var serializer = new AggregateResultDeserializer(_resultSerializer);
                var operation  = new ReadCommandOperation <AggregateResult>(CollectionNamespace.DatabaseNamespace, command, serializer, MessageEncoderSettings);

                var result = await operation.ExecuteAsync(connectionSource, binding.ReadPreference, slidingTimeout, cancellationToken);

                return(CreateCursor(connectionSource, command, result, timeout, cancellationToken));
            }
        }
 // methods
 public Task <IConnectionSourceHandle> GetReadConnectionSourceAsync(TimeSpan timeout, System.Threading.CancellationToken cancellationToken)
 {
     ThrowIfDisposed();
     return(_readBinding.GetReadConnectionSourceAsync(timeout, cancellationToken));
 }
Exemple #7
0
 // static methods
 public static IConnectionSource GetReadConnectionSource(this IReadBinding binding, TimeSpan timeout = default(TimeSpan), CancellationToken cancellationToken = default(CancellationToken))
 {
     return(binding.GetReadConnectionSourceAsync(timeout, cancellationToken).GetAwaiter().GetResult());
 }