private GridFSFindOptions <ObjectId> WrapFindOptions(GridFSFindOptions options) { if (options != null) { var renderedSort = options.Sort == null ? null : options.Sort.Render(GridFSFileInfoSerializer.Instance, BsonSerializer.SerializerRegistry); var wrappedSort = renderedSort == null ? null : new BsonDocumentSortDefinition <GridFSFileInfo <ObjectId> >(renderedSort); return(new GridFSFindOptions <ObjectId> { BatchSize = options.BatchSize, Limit = options.Limit, MaxTime = options.MaxTime, NoCursorTimeout = options.NoCursorTimeout, Skip = options.Skip, Sort = wrappedSort }); } else { return(null); } }
/// <inheritdoc /> public async Task<IAsyncCursor<GridFSFileInfo>> FindAsync(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions(); var filesCollectionNamespace = GetFilesCollectionNamespace(); var serializerRegistry = _database.Settings.SerializerRegistry; var fileInfoSerializer = serializerRegistry.GetSerializer<GridFSFileInfo>(); var messageEncoderSettings = GetMessageEncoderSettings(); var renderedFilter = filter.Render(fileInfoSerializer, serializerRegistry); var renderedSort = options.Sort == null ? null : options.Sort.Render(fileInfoSerializer, serializerRegistry); var operation = new FindOperation<GridFSFileInfo>( filesCollectionNamespace, fileInfoSerializer, messageEncoderSettings) { BatchSize = options.BatchSize, Filter = renderedFilter, Limit = options.Limit, MaxTime = options.MaxTime, NoCursorTimeout = options.NoCursorTimeout ?? false, Skip = options.Skip, Sort = renderedSort }; using (var binding = await GetSingleServerReadBindingAsync(cancellationToken).ConfigureAwait(false)) { return await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false); } }
/// <inheritdoc /> public async Task <IAsyncCursor <GridFSFileInfo> > FindAsync(FilterDefinition <GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); var wrappedFilter = WrapFilter(filter); var wrappedOptions = WrapFindOptions(options); var cursor = await base.FindAsync(wrappedFilter, wrappedOptions, cancellationToken).ConfigureAwait(false); return(new BatchTransformingAsyncCursor <GridFSFileInfo <ObjectId>, GridFSFileInfo>(cursor, TransformFileInfos)); }
/// <inheritdoc /> public async Task <IAsyncCursor <GridFSFileInfo <TFileId> > > FindAsync(FilterDefinition <GridFSFileInfo <TFileId> > filter, GridFSFindOptions <TFileId> options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions <TFileId>(); var operation = CreateFindOperation(filter, options); using (var binding = await GetSingleServerReadBindingAsync(cancellationToken).ConfigureAwait(false)) { return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false)); } }
private FindOperation <GridFSFileInfo <TFileId> > CreateFindOperation(FilterDefinition <GridFSFileInfo <TFileId> > filter, GridFSFindOptions <TFileId> options) { var filesCollectionNamespace = this.GetFilesCollectionNamespace(); var messageEncoderSettings = this.GetMessageEncoderSettings(); var renderedFilter = filter.Render(_fileInfoSerializer, _options.SerializerRegistry); var renderedSort = options.Sort == null ? null : options.Sort.Render(_fileInfoSerializer, _options.SerializerRegistry); return(new FindOperation <GridFSFileInfo <TFileId> >( filesCollectionNamespace, _fileInfoSerializer, messageEncoderSettings) { BatchSize = options.BatchSize, Filter = renderedFilter, Limit = options.Limit, MaxTime = options.MaxTime, NoCursorTimeout = options.NoCursorTimeout ?? false, ReadConcern = GetReadConcern(), RetryRequested = _database.Client.Settings.RetryReads, Skip = options.Skip, Sort = renderedSort }); }
/// <inheritdoc /> public IAsyncCursor <GridFSFileInfo <TFileId> > Find(FilterDefinition <GridFSFileInfo <TFileId> > filter, GridFSFindOptions <TFileId> options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions <TFileId>(); var operation = CreateFindOperation(filter, options); using (var binding = GetSingleServerReadBinding(cancellationToken)) { return(operation.Execute(binding, cancellationToken)); } }
/// <inheritdoc /> public async Task <IAsyncCursor <GridFSFileInfo> > FindAsync(FilterDefinition <GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions(); var filesCollectionNamespace = GetFilesCollectionNamespace(); var serializerRegistry = _database.Settings.SerializerRegistry; var fileInfoSerializer = serializerRegistry.GetSerializer <GridFSFileInfo>(); var messageEncoderSettings = GetMessageEncoderSettings(); var renderedFilter = filter.Render(fileInfoSerializer, serializerRegistry); var renderedSort = options.Sort == null ? null : options.Sort.Render(fileInfoSerializer, serializerRegistry); var operation = new FindOperation <GridFSFileInfo>( filesCollectionNamespace, fileInfoSerializer, messageEncoderSettings) { BatchSize = options.BatchSize, Filter = renderedFilter, Limit = options.Limit, MaxTime = options.MaxTime, NoCursorTimeout = options.NoCursorTimeout ?? false, Skip = options.Skip, Sort = renderedSort }; using (var binding = await GetSingleServerReadBindingAsync(cancellationToken).ConfigureAwait(false)) { return(await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false)); } }
private FindOperation<GridFSFileInfo> CreateFindOperation(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options) { var filesCollectionNamespace = GetFilesCollectionNamespace(); var serializerRegistry = _database.Settings.SerializerRegistry; var fileInfoSerializer = serializerRegistry.GetSerializer<GridFSFileInfo>(); var messageEncoderSettings = GetMessageEncoderSettings(); var renderedFilter = filter.Render(fileInfoSerializer, serializerRegistry); var renderedSort = options.Sort == null ? null : options.Sort.Render(fileInfoSerializer, serializerRegistry); return new FindOperation<GridFSFileInfo>( filesCollectionNamespace, fileInfoSerializer, messageEncoderSettings) { BatchSize = options.BatchSize, Filter = renderedFilter, Limit = options.Limit, MaxTime = options.MaxTime, NoCursorTimeout = options.NoCursorTimeout ?? false, ReadConcern = GetReadConcern(), Skip = options.Skip, Sort = renderedSort }; }
/// <inheritdoc /> public async Task<IAsyncCursor<GridFSFileInfo>> FindAsync(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions(); var operation = CreateFindOperation(filter, options); using (var binding = await GetSingleServerReadBindingAsync(cancellationToken).ConfigureAwait(false)) { return await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false); } }
/// <inheritdoc /> public IAsyncCursor<GridFSFileInfo> Find(FilterDefinition<GridFSFileInfo> filter, GridFSFindOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new GridFSFindOptions(); var operation = CreateFindOperation(filter, options); using (var binding = GetSingleServerReadBinding(cancellationToken)) { return operation.Execute(binding, cancellationToken); } }