private void Initialize(CancellationToken cancellationToken) { _channelSource = _binding.GetReadChannelSource(cancellationToken); try { _channel = _channelSource.GetChannel(cancellationToken); } catch (Exception ex) when(RetryableReadOperationExecutor.ShouldConnectionAcquireBeRetried(this, ex)) { ReplaceChannelSource(_binding.GetReadChannelSource(cancellationToken)); ReplaceChannel(_channelSource.GetChannel(cancellationToken)); } }
// public methods /// <inheritdoc /> public IChangeStreamCursor <TResult> Execute(IReadBinding binding, CancellationToken cancellationToken) { var bindingHandle = binding as IReadBindingHandle; if (bindingHandle == null) { throw new ArgumentException("The binding value passed to ChangeStreamOperation.Execute must implement IReadBindingHandle.", nameof(binding)); } IAsyncCursor <RawBsonDocument> cursor; ICursorBatchInfo cursorBatchInfo; BsonTimestamp initialOperationTime; 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())) { cursor = ExecuteAggregateOperation(channelBinding, cancellationToken); cursorBatchInfo = (ICursorBatchInfo)cursor; initialOperationTime = GetInitialOperationTimeIfRequired(channel, channelBinding, cursorBatchInfo); } var postBatchResumeToken = GetInitialPostBatchResumeTokenIfRequired(cursorBatchInfo); return(new ChangeStreamCursor <TResult>( cursor, _resultSerializer, bindingHandle.Fork(), this, postBatchResumeToken, initialOperationTime, _startAfter, _resumeAfter, _startAtOperationTime)); }
// public methods /// <inheritdoc /> public IAsyncCursor <TResult> Execute(IReadBinding binding, CancellationToken cancellationToken) { var bindingHandle = binding as IReadBindingHandle; if (bindingHandle == null) { throw new ArgumentException("The binding value passed to ChangeStreamOperation.Execute must implement IReadBindingHandle.", nameof(binding)); } IAsyncCursor <RawBsonDocument> cursor; 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())) { cursor = Resume(channelBinding, cancellationToken); if (_startAtOperationTime == null && _resumeAfter == null) { var maxWireVersion = channel.ConnectionDescription.IsMasterResult.MaxWireVersion; if (maxWireVersion >= 7) { _startAtOperationTime = binding.Session.OperationTime; } } } return(new ChangeStreamCursor <TResult>(cursor, _resultSerializer, bindingHandle.Fork(), this)); }
// methods /// <inheritdoc/> public TCommandResult Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) { return(ExecuteProtocol(channelSource, binding.ReadPreference, cancellationToken)); } }
// public methods public BsonDocument Execute(IReadBinding binding, CancellationToken cancellationToken = default(CancellationToken)) { using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference)) { var operation = CreateOperation(channel.ConnectionDescription.ServerVersion); return(operation.Execute(channelBinding, cancellationToken)); } }
/// <inheritdoc/> public 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())) { var operation = CreateOperation(); return(operation.Execute(channelBinding, cancellationToken)); } }
// public methods public BsonDocument Execute(IReadBinding binding, CancellationToken cancellationToken = default(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())) { var operation = new CurrentOpUsingCommandOperation(_databaseNamespace, _messageEncoderSettings); return(operation.Execute(channelBinding, cancellationToken)); } }
// public methods /// <inheritdoc/> public IEnumerable <TResult> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); 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())) { var operation = CreateOperation(); return(operation.Execute(channelBinding, cancellationToken)); } }
/// <inheritdoc/> public TResult Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference)) { var operation = CreateOperation(channel.ConnectionDescription.ServerVersion); return(operation.Execute(channelBinding, cancellationToken)); } }
// public methods /// <inheritdoc /> public virtual BsonDocument Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork())) { var operation = CreateOperation(); return(operation.Execute(channelBinding, cancellationToken)); } }
// public methods /// <inheritdoc/> public IAsyncCursor <TValue> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); 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())) { var operation = CreateOperation(channel, channelBinding); var values = operation.Execute(channelBinding, cancellationToken); return(new SingleBatchAsyncCursor <TValue>(values)); } }
// public methods /// <inheritdoc/> public IAsyncCursor <BsonDocument> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) { var operation = CreateOperation(); var result = operation.Execute(channelSource, binding.ReadPreference, cancellationToken); return(CreateCursor(channelSource, operation.Command, result)); } }
/// <inheritdoc/> public long Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); 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())) { var operation = CreateOperation(channel, channelBinding); var document = operation.Execute(channelBinding, cancellationToken); return(document["n"].ToInt64()); } }
private void Initialize(CancellationToken cancellationToken) { _channelSource = _binding.GetReadChannelSource(cancellationToken); var serverDescription = _channelSource.ServerDescription; try { _channel = _channelSource.GetChannel(cancellationToken); } catch (MongoConnectionPoolPausedException) { if (RetryableReadOperationExecutor.ShouldConnectionAcquireBeRetried(this, serverDescription)) { ReplaceChannelSource(_binding.GetReadChannelSource(cancellationToken)); ReplaceChannel(_channelSource.GetChannel(cancellationToken)); } else { throw; } } }
// public methods /// <inheritdoc/> public long Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); 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())) { var operation = CreateOperation(); var cursor = operation.Execute(channelBinding, cancellationToken); var result = cursor.ToList(cancellationToken); return(ExtractCountFromResult(result)); } }
// public methods /// <inheritdoc/> public IAsyncCursor <BsonDocument> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference)) { var operation = CreateOperation(channel); return(operation.Execute(channelBinding, cancellationToken)); } }
/// <inheritdoc/> public IReadOnlyList <IAsyncCursor <TDocument> > Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) 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())) { var operation = CreateOperation(channel, channelBinding); var result = operation.Execute(channelBinding, cancellationToken); return(CreateCursors(channelSource, operation.Command, result)); } }
// 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())) { var operation = new FindUsersUsingUserManagementCommandsOperation( _databaseNamespace, _username, _messageEncoderSettings); return(operation.Execute(channelBinding, cancellationToken)); } }
// public methods /// <inheritdoc /> public virtual BsonDocument Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadWriteBinding(channelSource.Server, channel, binding.Session.Fork())) { var operation = CreateOperation(); var result = operation.Execute(channelBinding, cancellationToken); WriteConcernErrorHelper.ThrowIfHasWriteConcernError(channel.ConnectionDescription.ConnectionId, result); return(result); } }
// methods /// <inheritdoc/> public IAsyncCursor <TResult> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); EnsureIsReadOnlyPipeline(); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference)) { var operation = CreateOperation(channel); var result = operation.Execute(channelBinding, cancellationToken); return(CreateCursor(channelSource, channel, operation.Command, result)); } }
/// <inheritdoc/> public IAsyncCursor <TDocument> Execute(IReadBinding binding, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) 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())) { var readPreference = binding.ReadPreference; using (EventContext.BeginFind(_batchSize, _limit)) { var operation = CreateOperation(channel, channelBinding); var commandResult = operation.Execute(channelBinding, cancellationToken); return(CreateCursor(channelSource, commandResult)); } } }
/// <inheritdoc/> public IAsyncCursor <TDocument> Execute(IReadBinding binding, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) { var readPreference = binding.ReadPreference; var slaveOk = readPreference != null && readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary; CursorBatch <TDocument> batch; using (EventContext.BeginFind(_batchSize, _limit)) { batch = ExecuteProtocol(channel, channelSource.ServerDescription, readPreference, slaveOk, cancellationToken); } return(CreateCursor(channelSource, batch, slaveOk)); } }
// 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)); } }
/// <inheritdoc/> public IAsyncCursor <TDocument> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) { var readPreference = binding.ReadPreference; var serverDescription = channelSource.ServerDescription; var wrappedQuery = CreateWrappedQuery(serverDescription.Type, readPreference); var slaveOk = readPreference != null && readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary; using (EventContext.BeginFind(_batchSize, _limit)) { var batch = ExecuteProtocol(channel, wrappedQuery, slaveOk, cancellationToken); return(CreateCursor(channelSource, wrappedQuery, batch)); } } }
/// <inheritdoc/> public IAsyncCursor <TDocument> Execute(IReadBinding binding, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) using (var channel = channelSource.GetChannel(cancellationToken)) using (var channelBinding = new ChannelReadBinding(channelSource.Server, channel, binding.ReadPreference)) { var readPreference = binding.ReadPreference; var slaveOk = readPreference != null && readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary; using (EventContext.BeginFind(_batchSize, _limit)) { var operation = CreateOperation(channel.ConnectionDescription.ServerVersion, channelSource.ServerDescription.Type); var commandResult = operation.Execute(binding, cancellationToken); return(CreateCursor(channelSource, commandResult, slaveOk)); } } }
// public methods /// <inheritdoc /> public IAsyncCursor <TResult> Execute(IReadBinding binding, CancellationToken cancellationToken) { var bindingHandle = binding as IReadBindingHandle; if (bindingHandle == null) { throw new ArgumentException("The binding value passed to ChangeStreamOperation.Execute must implement IReadBindingHandle.", nameof(binding)); } IAsyncCursor <RawBsonDocument> cursor; 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())) { cursor = ExecuteAggregateOperation(channelBinding, resuming: false, cancellationToken); SaveInitialOperationTimeIfRequired(channel, channelBinding, cursor); } return(new ChangeStreamCursor <TResult>(cursor, _resultSerializer, bindingHandle.Fork(), this)); }
// public methods /// <inheritdoc/> public IAsyncCursor <BsonDocument> Execute(IReadBinding binding, CancellationToken cancellationToken) { Ensure.IsNotNull(binding, nameof(binding)); using (EventContext.BeginOperation()) using (var channelSource = binding.GetReadChannelSource(cancellationToken)) { var operation = CreateOperation(); try { var result = operation.Execute(channelSource, binding.ReadPreference, binding.Session, cancellationToken); return(CreateCursor(channelSource, result, operation.Command)); } catch (MongoCommandException ex) { if (IsCollectionNotFoundException(ex)) { return(new SingleBatchAsyncCursor <BsonDocument>(new List <BsonDocument>())); } throw; } } }
// methods /// <inheritdoc/> public IChannelSourceHandle GetReadChannelSource(CancellationToken cancellationToken) { ThrowIfDisposed(); return(_readBinding.GetReadChannelSource(cancellationToken)); }
private void Initialize(CancellationToken cancellationToken) { _channelSource = _binding.GetReadChannelSource(cancellationToken); _channel = _channelSource.GetChannel(cancellationToken); }