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


C# MongoClientSettings.ToClusterKey方法代码示例

本文整理汇总了C#中MongoDB.Driver.MongoClientSettings.ToClusterKey方法的典型用法代码示例。如果您正苦于以下问题:C# MongoClientSettings.ToClusterKey方法的具体用法?C# MongoClientSettings.ToClusterKey怎么用?C# MongoClientSettings.ToClusterKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Driver.MongoClientSettings的用法示例。


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

示例1: GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings

        public void GetOrCreateCluster_should_return_a_cluster_with_the_correct_settings()
        {
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var servers = new[] { new MongoServerAddress("localhost"), new MongoServerAddress("127.0.0.1", 30000), new MongoServerAddress("[::1]", 27018) };

            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols = SslProtocols.Tls
            };

            var clientSettings = new MongoClientSettings
            {
                ApplicationName = "app1",
                ConnectionMode = ConnectionMode.ReplicaSet,
                ConnectTimeout = TimeSpan.FromSeconds(1),
                Credentials = credentials,
                GuidRepresentation = GuidRepresentation.Standard,
                HeartbeatInterval = TimeSpan.FromSeconds(7),
                HeartbeatTimeout = TimeSpan.FromSeconds(8),
                IPv6 = true,
                MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize = 10,
                MinConnectionPoolSize = 5,
                ReplicaSetName = "rs",
                LocalThreshold = TimeSpan.FromMilliseconds(20),
                Servers = servers,
                ServerSelectionTimeout = TimeSpan.FromSeconds(5),
                SocketTimeout = TimeSpan.FromSeconds(4),
                SslSettings = sslSettings,
                UseSsl = true,
                VerifySslCertificate = true,
                WaitQueueSize = 20,
                WaitQueueTimeout = TimeSpan.FromSeconds(6)
            };

            var subject = new ClusterRegistry();

            using (var cluster = subject.GetOrCreateCluster(clientSettings.ToClusterKey()))
            {
                var endPoints = new EndPoint[]
                {
                    new DnsEndPoint("localhost", 27017),
                    new IPEndPoint(IPAddress.Parse("127.0.0.1"), 30000),
                    new IPEndPoint(IPAddress.Parse("[::1]"), 27018)
                };
                cluster.Settings.ConnectionMode.Should().Be(ClusterConnectionMode.ReplicaSet);
                cluster.Settings.EndPoints.Equals(endPoints);
                cluster.Settings.ReplicaSetName.Should().Be("rs");
                cluster.Settings.ServerSelectionTimeout.Should().Be(clientSettings.ServerSelectionTimeout);
                cluster.Settings.PostServerSelector.Should().NotBeNull().And.Subject.Should().BeOfType<LatencyLimitingServerSelector>();
                cluster.Settings.MaxServerSelectionWaitQueueSize.Should().Be(20);

                cluster.Description.Servers.Select(s => s.EndPoint).Should().Contain(endPoints);

                // TODO: don't know how to test the rest of the settings because they are all private to the cluster
            }
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:59,代码来源:ClusterRegistryTests.cs

示例2: CreateSubject

        private ClusterKey CreateSubject(string notEqualFieldName = null)
        {
            var connectionMode = ConnectionMode.Direct;
            var connectTimeout = TimeSpan.FromSeconds(1);
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var guidRepresentation = GuidRepresentation.Standard;
            var ipv6 = false;
            var localThreshold = TimeSpan.FromMilliseconds(20);
            var maxConnectionIdleTime = TimeSpan.FromSeconds(2);
            var maxConnectionLifeTime = TimeSpan.FromSeconds(3);
            var maxConnectionPoolSize = 50;
            var minConnectionPoolSize = 5;
            var replicaSetName = "abc";
            var servers = new[] { new MongoServerAddress("localhost") };
            var serverSelectionTimeout = TimeSpan.FromSeconds(6);
            var socketTimeout = TimeSpan.FromSeconds(4);
            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols = SslProtocols.Ssl3
            };
            var useSsl = false;
            var verifySslCertificate = false;
            var waitQueueSize = 20;
            var waitQueueTimeout = TimeSpan.FromSeconds(5);

            switch (notEqualFieldName)
            {
                case "ConnectionMode": connectionMode = ConnectionMode.ReplicaSet; break;
                case "ConnectTimeout": connectTimeout = TimeSpan.FromSeconds(99); break;
                case "Credentials": credentials = new[] { MongoCredential.CreateMongoCRCredential("different", "different", "different") }; break;
                case "IPv6": ipv6 = !ipv6; break;
                case "LocalThreshold": localThreshold = TimeSpan.FromMilliseconds(99); break;
                case "MaxConnectionIdleTime": maxConnectionIdleTime = TimeSpan.FromSeconds(99); break;
                case "MaxConnectionLifeTime": maxConnectionLifeTime = TimeSpan.FromSeconds(99); break;
                case "MaxConnectionPoolSize": maxConnectionPoolSize = 99; break;
                case "MinConnectionPoolSize": minConnectionPoolSize = 99; break;
                case "ReplicaSetName": replicaSetName = "different"; break;
                case "Servers": servers = new[] { new MongoServerAddress("different") }; break;
                case "ServerSelectionTimeout": serverSelectionTimeout = TimeSpan.FromSeconds(98); break;
                case "SocketTimeout": socketTimeout = TimeSpan.FromSeconds(99); break;
                case "SslSettings": sslSettings.CheckCertificateRevocation = !sslSettings.CheckCertificateRevocation; break;
                case "UseSsl": useSsl = !useSsl; break;
                case "VerifySslCertificate": verifySslCertificate = !verifySslCertificate; break;
                case "WaitQueueSize": waitQueueSize = 99; break;
                case "WaitQueueTimeout": waitQueueTimeout = TimeSpan.FromSeconds(99); break;
            }

            var clientSettings = new MongoClientSettings
            {
                ConnectionMode = connectionMode,
                ConnectTimeout = connectTimeout,
                Credentials = credentials,
                GuidRepresentation = guidRepresentation,
                IPv6 = ipv6,
                MaxConnectionIdleTime = maxConnectionIdleTime,
                MaxConnectionLifeTime = maxConnectionLifeTime,
                MaxConnectionPoolSize = maxConnectionPoolSize,
                MinConnectionPoolSize = minConnectionPoolSize,
                ReplicaSetName = replicaSetName,
                LocalThreshold = localThreshold,
                Servers = servers,
                ServerSelectionTimeout = serverSelectionTimeout,
                SocketTimeout = socketTimeout,
                SslSettings = sslSettings,
                UseSsl = useSsl,
                VerifySslCertificate = verifySslCertificate,
                WaitQueueSize = waitQueueSize,
                WaitQueueTimeout = waitQueueTimeout
            };

            return clientSettings.ToClusterKey();
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:73,代码来源:ClusterKeyTests.cs

示例3: MongoClient

 /// <summary>
 /// Initializes a new instance of the MongoClient class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public MongoClient(MongoClientSettings settings)
 {
     _settings = Ensure.IsNotNull(settings, nameof(settings)).FrozenCopy();
     _cluster = ClusterRegistry.Instance.GetOrCreateCluster(_settings.ToClusterKey());
     _operationExecutor = new OperationExecutor();
 }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:10,代码来源:MongoClient.cs

示例4: GetOrCreateCluster_should_return_a_different_cluster_if_client_settings_are_not_equal

        public void GetOrCreateCluster_should_return_a_different_cluster_if_client_settings_are_not_equal()
        {
            var clientSettings1 = new MongoClientSettings();
            var clientSettings2 = new MongoClientSettings() { IPv6 = true };

            var subject = new ClusterRegistry();

            using (var cluster1 = subject.GetOrCreateCluster(clientSettings1.ToClusterKey()))
            using (var cluster2 = subject.GetOrCreateCluster(clientSettings2.ToClusterKey()))
            {
                cluster2.Should().NotBeSameAs(cluster1);
            }
        }
开发者ID:XiaoPingJiang,项目名称:mongo-csharp-driver,代码行数:13,代码来源:ClusterRegistryTests.cs

示例5: GetOrCreateCluster_should_return_the_same_cluster_if_client_settings_are_equal

        public void GetOrCreateCluster_should_return_the_same_cluster_if_client_settings_are_equal()
        {
            var clientSettings1 = new MongoClientSettings();
            var clientSettings2 = new MongoClientSettings();

            var subject = new ClusterRegistry();

            using (var cluster1 = subject.GetOrCreateCluster(clientSettings1.ToClusterKey()))
            using (var cluster2 = subject.GetOrCreateCluster(clientSettings2.ToClusterKey()))
            {
                cluster2.Should().BeSameAs(cluster1);
            }
        }
开发者ID:XiaoPingJiang,项目名称:mongo-csharp-driver,代码行数:13,代码来源:ClusterRegistryTests.cs

示例6: MongoClient

 /// <summary>
 /// Initializes a new instance of the MongoClient class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public MongoClient(MongoClientSettings settings)
 {
     _settings = settings.FrozenCopy();
     _cluster = ClusterRegistry.Instance.GetOrCreateCluster(_settings.ToClusterKey());
     _operationExecutor = new OperationExecutor();
 }
开发者ID:p3p3pp3,项目名称:mongo-csharp-driver-for-tokumx,代码行数:10,代码来源:MongoClient.cs

示例7: UnregisterAndDisposeCluster_should_unregister_and_dispose_the_cluster

        public void UnregisterAndDisposeCluster_should_unregister_and_dispose_the_cluster()
        {
            var subject = new ClusterRegistry();
            var settings = new MongoClientSettings();
            var clusterKey = settings.ToClusterKey();
            var cluster = subject.GetOrCreateCluster(clusterKey);

            subject.UnregisterAndDisposeCluster(cluster);

            subject._registry().Count.Should().Be(0);
            cluster._state().Should().Be(2);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:ClusterRegistryTests.cs


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