当前位置: 首页>>代码示例>>C#>>正文


C# FindOperation.ExecuteAsync方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:14,代码来源:CoreApi.cs

示例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);
        }
开发者ID:rtfmpliz,项目名称:mongo-csharp-driver,代码行数:22,代码来源:GridFSForwardOnlyDownloadStream.cs

示例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;
        }
开发者ID:vienitdev,项目名称:mongo-csharp-driver,代码行数:25,代码来源:GridFSBucket.cs

示例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");
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:8,代码来源:FindOperationTests.cs

示例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;
            }
        }
开发者ID:vienitdev,项目名称:mongo-csharp-driver,代码行数:29,代码来源:GridFSBucket.cs

示例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;
            }
        }
开发者ID:vienitdev,项目名称:mongo-csharp-driver,代码行数:33,代码来源:GridFSBucket.cs

示例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);
            }
        }
开发者ID:vienitdev,项目名称:mongo-csharp-driver,代码行数:32,代码来源:GridFSBucket.cs

示例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");
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:21,代码来源:FindOperationTests.cs

示例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);
        }
开发者ID:rmattos,项目名称:mongo-csharp-driver,代码行数:9,代码来源:Program.cs

示例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;
            }
        }
开发者ID:robblovell,项目名称:mongo-csharp-driver,代码行数:49,代码来源:GridFSSeekableDownloadStream.cs

示例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);
        }
开发者ID:Nakro,项目名称:mongo-csharp-driver,代码行数:10,代码来源:Program.cs


注:本文中的FindOperation.ExecuteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。