// methods
        public IEnumerable <BsonDocument> Execute(IReadBinding binding, CancellationToken cancellationToken)
        {
            var collectionNamespace = new CollectionNamespace(_databaseNamespace, "system.users");
            var filter    = _username == null ? new BsonDocument() : new BsonDocument("user", _username);
            var operation = new FindOperation <BsonDocument>(collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Filter = filter
            };
            var cursor = operation.Execute(binding, cancellationToken);

            return(cursor.ToList(cancellationToken));
        }
예제 #2
0
        private BsonDocument FindUser(IChannelSourceHandle channelSource, ICoreSessionHandle session, CollectionNamespace collectionNamespace, CancellationToken cancellationToken)
        {
            var operation = new FindOperation <BsonDocument>(collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Filter = new BsonDocument("user", _username),
                Limit  = -1
            };
            var cursor        = operation.Execute(channelSource, ReadPreference.Primary, session, cancellationToken);
            var userDocuments = cursor.ToList();

            return(userDocuments.FirstOrDefault());
        }
예제 #3
0
        private IAsyncCursor <BsonDocument> Query(IReadBinding binding, BsonDocument filter)
        {
            var findOp = new FindOperation <BsonDocument>(_collection, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Filter = filter,
                Limit  = -1
            };

            using (var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
                using (var linked = CancellationTokenSource.CreateLinkedTokenSource(timeout.Token, _cancellationTokenSource.Token))
                {
                    return(findOp.Execute(binding, linked.Token));
                }
        }
예제 #4
0
        private IAsyncCursor <BsonDocument> CreateAndRunFindOperation(RetryableReadContext context, bool async)
        {
            var findOperation = new FindOperation <BsonDocument>(
                _collectionNamespace,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings)
            {
                BatchSize = 1
            };

            if (async)
            {
                return(findOperation.ExecuteAsync(context, CancellationToken.None).GetAwaiter().GetResult());
            }
            else
            {
                return(findOperation.Execute(context, CancellationToken.None));
            }
        }
        public void Execute_should_throw_when_binding_is_null(
            [Values(false, true)]
            bool async)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var exception = Record.Exception(() =>
            {
                if (async)
                {
                    subject.ExecuteAsync(null, CancellationToken.None).GetAwaiter().GetResult();
                }
                else
                {
                    subject.Execute(null, CancellationToken.None);
                }
            });

            var argumentNullException = exception.Should().BeOfType<ArgumentNullException>().Subject;
            argumentNullException.ParamName.Should().Be("binding");
        }
예제 #6
0
        private IAsyncCursor<BsonDocument> Query(IReadBinding binding, BsonDocument filter)
        {
            var findOp = new FindOperation<BsonDocument>(_collection, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Filter = filter,
                Limit = -1
            };

            using (var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
            using (var linked = CancellationTokenSource.CreateLinkedTokenSource(timeout.Token, _cancellationTokenSource.Token))
            {
                return findOp.Execute(binding, linked.Token);
            }
        }