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


C# FindOperation类代码示例

本文整理汇总了C#中FindOperation的典型用法代码示例。如果您正苦于以下问题:C# FindOperation类的具体用法?C# FindOperation怎么用?C# FindOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FindOperation类属于命名空间,在下文中一共展示了FindOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateWrappedQuery_should_create_the_correct_query_when_not_connected_to_a_shard_router

        public void CreateWrappedQuery_should_create_the_correct_query_when_not_connected_to_a_shard_router()
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                Comment = "funny",
                Filter = BsonDocument.Parse("{x: 1}"),
                MaxTime = TimeSpan.FromSeconds(20),
                Modifiers = BsonDocument.Parse("{$comment: \"notfunny\", $snapshot: true}"),
                Projection = BsonDocument.Parse("{y: 1}"),
                Sort = BsonDocument.Parse("{a: 1}")
            };

            var expectedResult = new BsonDocument
            {
                { "$query", BsonDocument.Parse("{x: 1}") },
                { "$orderby", BsonDocument.Parse("{a: 1}") },
                { "$comment", "funny" },
                { "$maxTimeMS", 20000 },
                { "$snapshot", true }
            };


            var result = subject.CreateWrappedQuery(ServerType.ReplicaSetArbiter, ReadPreference.Secondary);

            result.Should().Be(expectedResult);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:26,代码来源:FindOperationTests.cs

示例2: EnumerateChildrenInternal

        internal static IEnumerable<IFileSystemInformation> EnumerateChildrenInternal(
            string directory,
            ChildType childType,
            string searchPattern,
            System.IO.SearchOption searchOption,
            FileAttributes excludeAttributes,
            IFileService fileService)
        {
            // We want to be able to see all files as we recurse and open new find handles (that might be over MAX_PATH).
            // We've already normalized our base directory.
            string extendedDirectory = Paths.AddExtendedPrefix(directory);

            // The assertion here is that we want to find files that match the desired pattern in all subdirectories, even if the
            // subdirectories themselves don't match the pattern. That requires two passes to avoid overallocating for directories
            // with a large number of files.

            // First look for items that match the given search pattern in the current directory
            using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, searchPattern)))
            {
                FindResult findResult;
                while ((findResult = findOperation.GetNextResult()) != null)
                {
                    bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;

                    if ((findResult.Attributes & excludeAttributes) == 0
                        && findResult.FileName != "."
                        && findResult.FileName != ".."
                        && ((isDirectory && childType == ChildType.Directory)
                            || (!isDirectory && childType == ChildType.File)))
                    {
                        yield return FileSystemInformation.Create(findResult, directory, fileService);
                    }
                }
            }

            if (searchOption != System.IO.SearchOption.AllDirectories) yield break;

            // Now recurse into each subdirectory
            using (FindOperation findOperation = new FindOperation(Paths.Combine(extendedDirectory, "*"), directoriesOnly: true))
            {
                FindResult findResult;
                while ((findResult = findOperation.GetNextResult()) != null)
                {
                    // Unfortunately there is no guarantee that the API will return only directories even if we ask for it
                    bool isDirectory = (findResult.Attributes & FileAttributes.FILE_ATTRIBUTE_DIRECTORY) == FileAttributes.FILE_ATTRIBUTE_DIRECTORY;

                    if ((findResult.Attributes & excludeAttributes) == 0
                        && isDirectory
                        && findResult.FileName != "."
                        && findResult.FileName != "..")
                    {
                        foreach (var child in EnumerateChildrenInternal(Paths.Combine(directory, findResult.FileName), childType, searchPattern,
                            searchOption, excludeAttributes, fileService))
                        {
                            yield return child;
                        }
                    }
                }
            }
        }
开发者ID:JeremyKuhne,项目名称:XTask,代码行数:60,代码来源:DirectoryInformation.cs

示例3: Constructor_should_initialize_object

        public void Constructor_should_initialize_object()
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.CollectionNamespace.Should().Be(_collectionNamespace);
            subject.ResultSerializer.Should().NotBeNull();
            subject.MessageEncoderSettings.Should().BeEquivalentTo(_messageEncoderSettings);
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:8,代码来源:FindOperationTests.cs

示例4: BatchSize_set_should_throw_when_value_is_invalid

        public void BatchSize_set_should_throw_when_value_is_invalid(
            [Values(-1)]
            int value)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            Action action = () => subject.BatchSize = value;

            action.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("value");
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:10,代码来源:FindOperationTests.cs

示例5: BatchSize_get_and_set_should_work

        public void BatchSize_get_and_set_should_work(
            [Values(null, 0, 1)]
            int? value)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.BatchSize = value;
            var result = subject.BatchSize;

            result.Should().Be(value);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:11,代码来源:FindOperationTests.cs

示例6: BatchSize_set_should_throw_when_value_is_invalid

        public void BatchSize_set_should_throw_when_value_is_invalid(
            [Values(-1)]
            int value)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var exception = Record.Exception(() => { subject.BatchSize = value; });

            var argumentOutOfRangeException = exception.Should().BeOfType<ArgumentOutOfRangeException>().Subject;
            argumentOutOfRangeException.ParamName.Should().Be("value");
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:11,代码来源:FindOperationTests.cs

示例7: AllowPartialResults_get_and_set_should_work

        public void AllowPartialResults_get_and_set_should_work(
            [Values(null, false, true)]
            bool? value)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.AllowPartialResults = value;
            var result = subject.AllowPartialResults;

            result.Should().Be(value);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:11,代码来源:FindOperationTests.cs

示例8: Collation_get_and_set_should_work

        public void Collation_get_and_set_should_work(
            [Values(null, "en_US", "fr_CA")]
            string locale)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
            var value = locale == null ? null : new Collation(locale);

            subject.Collation = value;
            var result = subject.Collation;

            result.Should().Be(value);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:FindOperationTests.cs

示例9: CollectionNamespace_get_should_return_expected_result

        public void CollectionNamespace_get_should_return_expected_result(
            [Values("a", "b")]
            string collectionName)
        {
            var databaseNamespace = new DatabaseNamespace("test");
            var collectionNamespace = new CollectionNamespace(databaseNamespace, collectionName);
            var subject = new FindOperation<BsonDocument>(collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            var result = subject.CollectionNamespace;

            result.Should().Be(collectionNamespace);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:12,代码来源:FindOperationTests.cs

示例10: ResultSerializer_get_should_return_expected_result

        public void ResultSerializer_get_should_return_expected_result()
        {
            var resultSerializer = new BsonDocumentSerializer();
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, resultSerializer, _messageEncoderSettings);

            var result = subject.ResultSerializer;

            result.Should().Be(resultSerializer);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:9,代码来源:FindOperationTests.cs

示例11: Execute_should_find_all_the_documents_matching_the_query_when_split_across_batches

        public void Execute_should_find_all_the_documents_matching_the_query_when_split_across_batches(
            [Values(false, true)]
            bool async)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                BatchSize = 2
            };

            var cursor = ExecuteOperation(subject, async);
            var result = ReadCursorToEnd(cursor, async);

            result.Should().HaveCount(5);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:14,代码来源:FindOperationTests.cs

示例12: 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

示例13: ReadConcern_get_and_set_should_work

        public void ReadConcern_get_and_set_should_work()
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);

            subject.ReadConcern = ReadConcern.Local;
            var result = subject.ReadConcern;

            result.Should().Be(ReadConcern.Local);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:9,代码来源:FindOperationTests.cs

示例14: MaxTime_get_and_set_should_work

        public void MaxTime_get_and_set_should_work(
            [Values(null, 1)]
            int? seconds)
        {
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
            var value = seconds == null ? (TimeSpan?)null : TimeSpan.FromSeconds(seconds.Value);

            subject.MaxTime = value;
            var result = subject.MaxTime;

            result.Should().Be(value);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:12,代码来源:FindOperationTests.cs

示例15: MessageEncoderSettings_get_should_return_expected_result

        public void MessageEncoderSettings_get_should_return_expected_result(
            [Values(GuidRepresentation.CSharpLegacy, GuidRepresentation.Standard)]
            GuidRepresentation guidRepresentation)
        {
            var messageEncoderSettings = new MessageEncoderSettings { { "GuidRepresentation", guidRepresentation } };
            var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, messageEncoderSettings);

            var result = subject.MessageEncoderSettings;

            result.Should().BeEquivalentTo(messageEncoderSettings);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:11,代码来源:FindOperationTests.cs


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