Example #1
0
        // methods
        public async Task <IEnumerable <BsonDocument> > ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
        {
            using (var channelSource = await binding.GetReadChannelSourceAsync(cancellationToken).ConfigureAwait(false))
            {
                IReadOperation <IEnumerable <BsonDocument> > operation;

                if (channelSource.ServerDescription.Version >= __serverVersionSupportingUserManagementCommands)
                {
                    operation = new FindUsersUsingUserManagementCommandsOperation(_databaseNamespace, _username, _messageEncoderSettings);
                }
                else
                {
                    operation = new FindUsersUsingSystemUsersCollectionOperation(_databaseNamespace, _username, _messageEncoderSettings);
                }

                return(await operation.ExecuteAsync(channelSource, binding.ReadPreference, cancellationToken).ConfigureAwait(false));
            }
        }
Example #2
0
        // methods
        public IEnumerable <BsonDocument> Execute(IReadBinding binding, CancellationToken cancellationToken)
        {
            using (var channelSource = binding.GetReadChannelSource(cancellationToken))
                using (var channel = channelSource.GetChannel(cancellationToken))
                    using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference, binding.Session.Fork()))
                    {
                        IReadOperation <IEnumerable <BsonDocument> > operation;

                        if (Feature.UserManagementCommands.IsSupported(channel.ConnectionDescription.ServerVersion))
                        {
                            operation = new FindUsersUsingUserManagementCommandsOperation(_databaseNamespace, _username, _messageEncoderSettings);
                        }
                        else
                        {
                            operation = new FindUsersUsingSystemUsersCollectionOperation(_databaseNamespace, _username, _messageEncoderSettings);
                        }

                        return(operation.Execute(channelBinding, cancellationToken));
                    }
        }