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


C# MongoClientSettings类代码示例

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


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

示例1: Run

        public void Run(int numConcurrentWorkers, Action<ClusterBuilder> configurator)
        {
            var settings = new MongoClientSettings();
            settings.ClusterConfigurator = configurator;

            var client = new MongoClient(settings);
#pragma warning disable 618
            var server = client.GetServer();
#pragma warning restore 618

            var db = server.GetDatabase("foo");
            var collection = db.GetCollection<BsonDocument>("bar");

            Console.WriteLine("Press Enter to begin");
            Console.ReadLine();

            Console.WriteLine("Clearing Data");
            ClearData(collection);
            Console.WriteLine("Inserting Seed Data");
            InsertData(collection);

            Console.WriteLine("Running CRUD (errors will show up as + (query error) or * (insert/update error))");
            for (int i = 0; i < numConcurrentWorkers; i++)
            {
                ThreadPool.QueueUserWorkItem(_ => DoWork(collection));
            }

            Console.WriteLine("Press Enter to shutdown");
            Console.ReadLine();

            _cancellationTokenSource.Cancel();

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:35,代码来源:LegacyApi.cs

示例2: RunAsync

        public async Task RunAsync(int numConcurrentWorkers, Action<ClusterBuilder> configurator)
        {
            var settings = new MongoClientSettings();
            settings.ClusterConfigurator = configurator;

            var client = new MongoClient(settings);

            var db = client.GetDatabase("foo");
            var collection = db.GetCollection<BsonDocument>("bar");

            Console.WriteLine("Press Enter to begin");
            Console.ReadLine();

            Console.WriteLine("Clearing Data");
            await ClearData(collection);
            Console.WriteLine("Inserting Seed Data");
            await InsertData(collection);

            Console.WriteLine("Running CRUD (errors will show up as + (query error) or * (insert/update error))");
            var tasks = new List<Task>();
            for (int i = 0; i < numConcurrentWorkers; i++)
            {
                tasks.Add(DoWork(collection));
            }

            Console.WriteLine("Press Enter to shutdown");
            Console.ReadLine();

            _cancellationTokenSource.Cancel();
            Task.WaitAll(tasks.ToArray());
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:31,代码来源:Api.cs

示例3: TestApplicationName_too_long

        public void TestApplicationName_too_long()
        {
            var subject = new MongoClientSettings();
            var value = new string('x', 129);

            var exception = Record.Exception(() => subject.ApplicationName = value);

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

示例4: TestConnectTimeout

        public void TestConnectTimeout()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);

            var connectTimeout = new TimeSpan(1, 2, 3);
            settings.ConnectTimeout = connectTimeout;
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);

            settings.Freeze();
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);
            Assert.Throws<InvalidOperationException>(() => { settings.ConnectTimeout = connectTimeout; });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例5: TestApplicationName

        public void TestApplicationName()
        {
            var settings = new MongoClientSettings();
            Assert.Equal(null, settings.ApplicationName);

            var applicationName = "app";
            settings.ApplicationName = applicationName;
            Assert.Equal(applicationName, settings.ApplicationName);

            settings.Freeze();
            Assert.Equal(applicationName, settings.ApplicationName);
            Assert.Throws<InvalidOperationException>(() => { settings.ApplicationName = applicationName; });
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例6: TestConnectionMode

        public void TestConnectionMode()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(ConnectionMode.Automatic, settings.ConnectionMode);

            var connectionMode = ConnectionMode.Direct;
            settings.ConnectionMode = connectionMode;
            Assert.AreEqual(connectionMode, settings.ConnectionMode);

            settings.Freeze();
            Assert.AreEqual(connectionMode, settings.ConnectionMode);
            Assert.Throws<InvalidOperationException>(() => { settings.ConnectionMode = connectionMode; });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例7: TestFixtureSetUp

        public void TestFixtureSetUp()
        {
            __capturedEvents = new EventCapturer()
                .Capture<CommandStartedEvent>()
                .Capture<CommandSucceededEvent>()
                .Capture<CommandFailedEvent>();

            var settings = new MongoClientSettings
            {
                ClusterConfigurator = cb =>
                {
                    cb.Subscribe(__capturedEvents);

                    // never heartbeat...
                    cb.ConfigureServer(ss => ss.With(heartbeatInterval: Timeout.InfiniteTimeSpan));
                }
            };

            __client = new MongoClient(settings);
        }
开发者ID:milyh,项目名称:mongo-csharp-driver,代码行数:20,代码来源:TestRunner.cs

示例8: ClusterKey

 // constructors
 public ClusterKey(MongoClientSettings clientSettings)
 {
     _connectionMode = clientSettings.ConnectionMode;
     _connectTimeout = clientSettings.ConnectTimeout;
     _credentials = clientSettings.Credentials.ToList();
     _heartbeatInterval = __defaultHeartbeatInterval; // TODO: add HeartbeatInterval to MongoClientSettings?
     _heartbeatTimeout = __defaultHeartbeatTimeout; // TODO: add HeartbeatTimeout to MongoClientSettings?
     _ipv6 = clientSettings.IPv6;
     _maxConnectionIdleTime = clientSettings.MaxConnectionIdleTime;
     _maxConnectionLifeTime = clientSettings.MaxConnectionLifeTime;
     _maxConnectionPoolSize = clientSettings.MaxConnectionPoolSize;
     _minConnectionPoolSize = clientSettings.MinConnectionPoolSize;
     _receiveBufferSize = __defaultReceiveBufferSize; // TODO: add ReceiveBufferSize to MongoClientSettings?
     _replicaSetName = clientSettings.ReplicaSetName;
     _sendBufferSize = __defaultSendBufferSize; // TODO: add SendBufferSize to MongoClientSettings?
     _servers = clientSettings.Servers.ToList();
     _socketTimeout = clientSettings.SocketTimeout;
     _sslSettings = clientSettings.SslSettings;
     _useSsl = clientSettings.UseSsl;
     _verifySslCertificate = clientSettings.VerifySslCertificate;
     _waitQueueSize = clientSettings.WaitQueueSize;
     _waitQueueTimeout = clientSettings.WaitQueueTimeout;
     _hashCode = CalculateHashCode();
 }
开发者ID:bollinim,项目名称:mongo-csharp-driver,代码行数:25,代码来源:ClusterKey.cs

示例9: TestServerSelectionTimeout

        public void TestServerSelectionTimeout()
        {
            var settings = new MongoClientSettings();
            Assert.Equal(MongoDefaults.ServerSelectionTimeout, settings.ServerSelectionTimeout);

            var serverSelectionTimeout = new TimeSpan(1, 2, 3);
            settings.ServerSelectionTimeout = serverSelectionTimeout;
            Assert.Equal(serverSelectionTimeout, settings.ServerSelectionTimeout);

            settings.Freeze();
            Assert.Equal(serverSelectionTimeout, settings.ServerSelectionTimeout);
            Assert.Throws<InvalidOperationException>(() => { settings.ServerSelectionTimeout = serverSelectionTimeout; });
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例10: TestUseSsl

        public void TestUseSsl()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(false, settings.UseSsl);

            var useSsl = true;
            settings.UseSsl = useSsl;
            Assert.AreEqual(useSsl, settings.UseSsl);

            settings.Freeze();
            Assert.AreEqual(useSsl, settings.UseSsl);
            Assert.Throws<InvalidOperationException>(() => { settings.UseSsl = useSsl; });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例11: TestSslSettings

        public void TestSslSettings()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(null, settings.SslSettings);

            var sslSettings = new SslSettings { CheckCertificateRevocation = false };
            settings.SslSettings = sslSettings;
            Assert.AreEqual(sslSettings, settings.SslSettings);

            settings.Freeze();
            Assert.AreEqual(sslSettings, settings.SslSettings);
            Assert.Throws<InvalidOperationException>(() => { settings.SslSettings = sslSettings; });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs

示例12: TestEquals

        public void TestEquals()
        {
            var settings = new MongoClientSettings();
            var clone = settings.Clone();
            Assert.IsTrue(clone.Equals(settings));

            clone = settings.Clone();
            clone.ConnectionMode = ConnectionMode.Direct;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ConnectTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Credentials = new[] { MongoCredential.CreateMongoCRCredential("db2", "user2", "password2") };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Credentials = new[] { MongoCredential.CreateMongoCRCredential("db", "user2", "password2") };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.IPv6 = !settings.IPv6;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionIdleTime = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionLifeTime = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionPoolSize = settings.MaxConnectionPoolSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MinConnectionPoolSize = settings.MinConnectionPoolSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ReadPreference = ReadPreference.Secondary;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ReplicaSetName = "abc";
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.LocalThreshold = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Server = new MongoServerAddress("someotherhost");
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ServerSelectionTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.SocketTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.SslSettings = new SslSettings { CheckCertificateRevocation = false };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.UseSsl = !settings.UseSsl;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.VerifySslCertificate = !settings.VerifySslCertificate;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WaitQueueSize = settings.WaitQueueSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WaitQueueTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WriteConcern = WriteConcern.W2;
            Assert.IsFalse(clone.Equals(settings));
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:94,代码来源:MongoClientSettingsTests.cs

示例13: TestDefaults

 public void TestDefaults()
 {
     var settings = new MongoClientSettings();
     Assert.AreEqual(ConnectionMode.Automatic, settings.ConnectionMode);
     Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);
     Assert.AreEqual(0, settings.Credentials.Count());
     Assert.AreEqual(MongoDefaults.GuidRepresentation, settings.GuidRepresentation);
     Assert.AreEqual(false, settings.IPv6);
     Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
     Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, settings.MinConnectionPoolSize);
     Assert.AreEqual(ReadPreference.Primary, settings.ReadPreference);
     Assert.AreEqual(null, settings.ReplicaSetName);
     Assert.AreEqual(_localHost, settings.Server);
     Assert.AreEqual(_localHost, settings.Servers.First());
     Assert.AreEqual(1, settings.Servers.Count());
     Assert.AreEqual(MongoDefaults.ServerSelectionTimeout, settings.ServerSelectionTimeout);
     Assert.AreEqual(MongoDefaults.SocketTimeout, settings.SocketTimeout);
     Assert.AreEqual(null, settings.SslSettings);
     Assert.AreEqual(false, settings.UseSsl);
     Assert.AreEqual(true, settings.VerifySslCertificate);
     Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, settings.WaitQueueSize);
     Assert.AreEqual(MongoDefaults.WaitQueueTimeout, settings.WaitQueueTimeout);
     Assert.AreEqual(WriteConcern.Acknowledged, settings.WriteConcern);
 }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:26,代码来源:MongoClientSettingsTests.cs

示例14: TestServersWithOneServer

        public void TestServersWithOneServer()
        {
            var settings = new MongoClientSettings();
            Assert.Equal(_localHost, settings.Server);
            Assert.True(new[] { _localHost }.SequenceEqual(settings.Servers));

            var server = new MongoServerAddress("server");
            var servers = new[] { server };
            settings.Servers = servers;
            Assert.Equal(server, settings.Server);
            Assert.True(servers.SequenceEqual(settings.Servers));

            settings.Freeze();
            Assert.Equal(server, settings.Server);
            Assert.True(servers.SequenceEqual(settings.Servers));
            Assert.Throws<InvalidOperationException>(() => { settings.Server = server; });
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:17,代码来源:MongoClientSettingsTests.cs

示例15: TestWriteConcern

        public void TestWriteConcern()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(WriteConcern.Acknowledged, settings.WriteConcern);

            var writeConcern = new WriteConcern();
            settings.WriteConcern = writeConcern;
            Assert.AreSame(writeConcern, settings.WriteConcern);

            settings.Freeze();
            Assert.AreEqual(writeConcern, settings.WriteConcern);
            Assert.Throws<InvalidOperationException>(() => { settings.WriteConcern = writeConcern; });
        }
开发者ID:kay-kim,项目名称:mongo-csharp-driver,代码行数:13,代码来源:MongoClientSettingsTests.cs


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