本文整理汇总了C#中FindOperation.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FindOperation.ExecuteAsync方法的具体用法?C# FindOperation.ExecuteAsync怎么用?C# FindOperation.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FindOperation
的用法示例。
在下文中一共展示了FindOperation.ExecuteAsync方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Query
private async Task<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 await findOp.ExecuteAsync(binding, linked.Token);
}
}
示例2: GetFirstBatchAsync
// private methods
private async Task GetFirstBatchAsync(CancellationToken cancellationToken)
{
var chunksCollectionNamespace = Bucket.GetChunksCollectionNamespace();
var messageEncoderSettings = Bucket.GetMessageEncoderSettings();
#pragma warning disable 618
var filter = new BsonDocument("files_id", FilesCollectionDocument.IdAsBsonValue);
#pragma warning restore
var sort = new BsonDocument("n", 1);
var operation = new FindOperation<BsonDocument>(
chunksCollectionNamespace,
BsonDocumentSerializer.Instance,
messageEncoderSettings)
{
Filter = filter,
Sort = sort
};
_cursor = await operation.ExecuteAsync(Binding, cancellationToken).ConfigureAwait(false);
await GetNextBatchAsync(cancellationToken).ConfigureAwait(false);
}
示例3: IsFilesCollectionEmptyAsync
private async Task<bool> IsFilesCollectionEmptyAsync(IReadWriteBindingHandle binding, CancellationToken cancellationToken)
{
var filesCollectionNamespace = GetFilesCollectionNamespace();
var messageEncoderSettings = GetMessageEncoderSettings();
var operation = new FindOperation<BsonDocument>(filesCollectionNamespace, BsonDocumentSerializer.Instance, messageEncoderSettings)
{
Limit = 1,
SingleBatch = true,
Projection = new BsonDocument("_id", 1)
};
using (var cursor = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false))
{
if (await cursor.MoveNextAsync(cancellationToken).ConfigureAwait(false))
{
var batch = cursor.Current;
if (batch.Count() > 0)
{
return false;
}
}
}
return true;
}
示例4: ExecuteAsync_should_throw_when_binding_is_null
public void ExecuteAsync_should_throw_when_binding_is_null()
{
var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
Func<Task> action = () => subject.ExecuteAsync(null, CancellationToken.None);
action.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("binding");
}
示例5: GetFileInfoAsync
private async Task<GridFSFileInfo> GetFileInfoAsync(IReadBindingHandle binding, BsonValue id, CancellationToken cancellationToken)
{
var filesCollectionNamespace = GetFilesCollectionNamespace();
var serializerRegistry = _database.Settings.SerializerRegistry;
var fileInfoSerializer = serializerRegistry.GetSerializer<GridFSFileInfo>();
var messageEncoderSettings = GetMessageEncoderSettings();
var filter = new BsonDocument("_id", id);
var operation = new FindOperation<GridFSFileInfo>(
filesCollectionNamespace,
fileInfoSerializer,
messageEncoderSettings)
{
Filter = filter,
Limit = 1,
SingleBatch = true
};
using (var cursor = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false))
{
var fileInfoList = await cursor.ToListAsync(cancellationToken).ConfigureAwait(false);
var fileInfo = fileInfoList.FirstOrDefault();
if (fileInfo == null)
{
throw new GridFSFileNotFoundException(id);
}
return fileInfo;
}
}
示例6: GetFileInfoByNameAsync
private async Task<GridFSFileInfo> GetFileInfoByNameAsync(IReadBindingHandle binding, string filename, int revision, CancellationToken cancellationToken)
{
var collectionNamespace = GetFilesCollectionNamespace();
var serializerRegistry = _database.Settings.SerializerRegistry;
var fileInfoSerializer = serializerRegistry.GetSerializer<GridFSFileInfo>();
var messageEncoderSettings = GetMessageEncoderSettings();
var filter = new BsonDocument("filename", filename);
var skip = revision >= 0 ? revision : -revision - 1;
var limit = 1;
var sort = new BsonDocument("uploadDate", revision >= 0 ? 1 : -1);
var operation = new FindOperation<GridFSFileInfo>(
collectionNamespace,
fileInfoSerializer,
messageEncoderSettings)
{
Filter = filter,
Limit = limit,
Skip = skip,
Sort = sort
};
using (var cursor = await operation.ExecuteAsync(binding, cancellationToken).ConfigureAwait(false))
{
var fileInfoList = await cursor.ToListAsync(cancellationToken).ConfigureAwait(false);
var fileInfo = fileInfoList.FirstOrDefault();
if (fileInfo == null)
{
throw new GridFSFileNotFoundException(filename, revision);
}
return fileInfo;
}
}
示例7: FindAsync
/// <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);
}
}
示例8: Execute_should_throw_when_binding_is_null
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");
}
示例9: Query
private static Task<Cursor<BsonDocument>> Query(IReadBinding binding, BsonDocument query)
{
var queryOp = new FindOperation<BsonDocument>(__collection, query, BsonDocumentSerializer.Instance, __messageEncoderSettings)
{
Limit = 1
};
return queryOp.ExecuteAsync(binding);
}
示例10: GetChunkAsync
// private methods
private async Task GetChunkAsync(long n, CancellationToken cancellationToken)
{
var chunksCollectionNamespace = Bucket.GetChunksCollectionNamespace();
var messageEncoderSettings = Bucket.GetMessageEncoderSettings();
#pragma warning disable 618
var filter = new BsonDocument
{
{ "files_id", FileInfo.IdAsBsonValue },
{ "n", n }
};
#pragma warning restore
var operation = new FindOperation<BsonDocument>(
chunksCollectionNamespace,
BsonDocumentSerializer.Instance,
messageEncoderSettings)
{
Filter = filter,
Limit = -1
};
using (var cursor = await operation.ExecuteAsync(Binding, cancellationToken).ConfigureAwait(false))
{
var documents = await cursor.ToListAsync().ConfigureAwait(false);
if (documents.Count == 0)
{
#pragma warning disable 618
throw new GridFSChunkException(FileInfo.IdAsBsonValue, n, "missing");
#pragma warning restore
}
var document = documents[0];
var data = document["data"].AsBsonBinaryData.Bytes;
var chunkSizeBytes = FileInfo.ChunkSizeBytes;
var lastChunk = 0;
var expectedChunkSize = n == lastChunk ? FileInfo.Length % chunkSizeBytes : chunkSizeBytes;
if (data.Length != expectedChunkSize)
{
#pragma warning disable 618
throw new GridFSChunkException(FileInfo.IdAsBsonValue, n, "the wrong size");
#pragma warning restore
}
_chunk = data;
_n = n;
}
}
示例11: Query
private static Task<Cursor<BsonDocument>> Query(IReadBinding binding, BsonDocument query)
{
var queryOp = new FindOperation<BsonDocument>(
_database,
_collection,
BsonDocumentSerializer.Instance,
query).WithLimit(1);
return queryOp.ExecuteAsync(binding);
}