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


C# MongoConnectionStringBuilder.GetWriteConcern方法代码示例

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


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

示例1: TestGetWriteConcern_WTimeout

 public void TestGetWriteConcern_WTimeout(int? ms, string connectionString)
 {
     var wtimeout = (ms == null) ? (TimeSpan?)null : TimeSpan.FromMilliseconds(ms.Value);
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(true);
     Assert.AreEqual(wtimeout, writeConcern.WTimeout);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoConnectionStringBuilderTests.cs

示例2: TestFromMongoConnectionStringBuilder

        public void TestFromMongoConnectionStringBuilder()
        {
            // set everything to non default values to test that all settings are converted
            var connectionString =
                "server=somehost;username=user1;password=password1;" +
                "connect=direct;connectTimeout=123;uuidRepresentation=pythonLegacy;ipv6=true;" +
                "maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;" +
                "readPreference=secondary;readPreferenceTags=a:1,b:2|c:3,d:4;secondaryAcceptableLatency=128;socketTimeout=129;" +
                "ssl=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
                "fireAndForget=false;fsync=true;journal=true;w=2;wtimeout=131";
            var builder = new MongoConnectionStringBuilder(connectionString);

            var settings = MongoClientSettings.FromConnectionStringBuilder(builder);
            Assert.AreEqual(builder.ConnectionMode, settings.ConnectionMode);
            Assert.AreEqual(builder.ConnectTimeout, settings.ConnectTimeout);
            Assert.AreEqual("{}", settings.CredentialsStore.ToString());
            Assert.AreEqual(new MongoCredentials("user1", "password1"), settings.DefaultCredentials);
            Assert.AreEqual(builder.GuidRepresentation, settings.GuidRepresentation);
            Assert.AreEqual(builder.IPv6, settings.IPv6);
            Assert.AreEqual(builder.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
            Assert.AreEqual(builder.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.AreEqual(builder.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
            Assert.AreEqual(builder.MinConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.AreEqual(builder.ReadPreference, settings.ReadPreference);
            Assert.AreEqual(builder.ReplicaSetName, settings.ReplicaSetName);
            Assert.AreEqual(builder.SecondaryAcceptableLatency, settings.SecondaryAcceptableLatency);
            Assert.IsTrue(builder.Servers.SequenceEqual(settings.Servers));
            Assert.AreEqual(builder.SocketTimeout, settings.SocketTimeout);
            Assert.AreEqual(builder.UseSsl, settings.UseSsl);
            Assert.AreEqual(builder.VerifySslCertificate, settings.VerifySslCertificate);
            Assert.AreEqual(builder.ComputedWaitQueueSize, settings.WaitQueueSize);
            Assert.AreEqual(builder.WaitQueueTimeout, settings.WaitQueueTimeout);
            Assert.AreEqual(builder.GetWriteConcern(false), settings.WriteConcern);
        }
开发者ID:subbuballa,项目名称:mongo-csharp-driver,代码行数:34,代码来源:MongoClientSettingsTests.cs

示例3: TestGetWriteConcern_FSync

 public void TestGetWriteConcern_FSync(bool? fsync, string connectionString)
 {
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(true);
     Assert.AreEqual(fsync, writeConcern.FSync);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:6,代码来源:MongoConnectionStringBuilderTests.cs

示例4: TestGetWriteConcern_W

 public void TestGetWriteConcern_W(bool enabledDefault, bool enabled, object wobj, string connectionString)
 {
     var w = (wobj == null) ? null : (wobj is int) ? (WriteConcern.WValue)new WriteConcern.WCount((int)wobj) : new WriteConcern.WMode((string)wobj);
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(enabledDefault);
     Assert.AreEqual(enabled, writeConcern.Enabled);
     Assert.AreEqual(w, writeConcern.W);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:8,代码来源:MongoConnectionStringBuilderTests.cs

示例5: FromConnectionStringBuilder

        /// <summary>
        /// Gets a MongoServerSettings object intialized with values from a MongoConnectionStringBuilder.
        /// </summary>
        /// <returns>A MongoServerSettings.</returns>
        public static MongoServerSettings FromConnectionStringBuilder(MongoConnectionStringBuilder builder)
        {
            MongoCredentials defaultCredentials = null;
            if (builder.Username != null && builder.Password != null)
            {
                defaultCredentials = new MongoCredentials(builder.Username, builder.Password);
            }

            var serverSettings = new MongoServerSettings();
            serverSettings.ConnectionMode = builder.ConnectionMode;
            serverSettings.ConnectTimeout = builder.ConnectTimeout;
            serverSettings.CredentialsStore = new MongoCredentialsStore();
            serverSettings.DefaultCredentials = defaultCredentials;
            serverSettings.GuidRepresentation = builder.GuidRepresentation;
            serverSettings.IPv6 = builder.IPv6;
            serverSettings.MaxConnectionIdleTime = builder.MaxConnectionIdleTime;
            serverSettings.MaxConnectionLifeTime = builder.MaxConnectionLifeTime;
            serverSettings.MaxConnectionPoolSize = builder.MaxConnectionPoolSize;
            serverSettings.MinConnectionPoolSize = builder.MinConnectionPoolSize;
            serverSettings.ReadPreference = (builder.ReadPreference == null) ? ReadPreference.Primary : builder.ReadPreference.Clone();
            serverSettings.ReplicaSetName = builder.ReplicaSetName;
            serverSettings.SecondaryAcceptableLatency = builder.SecondaryAcceptableLatency;
            serverSettings.Servers = new List<MongoServerAddress>(builder.Servers);
            serverSettings.SocketTimeout = builder.SocketTimeout;
            serverSettings.UseSsl = builder.UseSsl;
            serverSettings.VerifySslCertificate = builder.VerifySslCertificate;
            serverSettings.WaitQueueSize = builder.ComputedWaitQueueSize;
            serverSettings.WaitQueueTimeout = builder.WaitQueueTimeout;
#pragma warning disable 618
            serverSettings.WriteConcern = builder.GetWriteConcern(MongoDefaults.SafeMode.Enabled);
#pragma warning restore
            return serverSettings;
        }
开发者ID:tkellogg,项目名称:mongo-csharp-driver,代码行数:37,代码来源:MongoServerSettings.cs

示例6: TestGetWriteConcern_Enabled

 public void TestGetWriteConcern_Enabled(bool enabledDefault, bool enabled, string connectionString)
 {
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(enabledDefault);
     Assert.AreEqual(enabled, writeConcern.Enabled);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:6,代码来源:MongoConnectionStringBuilderTests.cs

示例7: FromConnectionStringBuilder

        // public static methods
        /// <summary>
        /// Gets a MongoClientSettings object intialized with values from a connection string builder.
        /// </summary>
        /// <returns>A MongoClientSettings.</returns>
        public static MongoClientSettings FromConnectionStringBuilder(MongoConnectionStringBuilder builder)
        {
            MongoCredentials defaultCredentials = null;
            if (builder.Username != null && builder.Password != null)
            {
                defaultCredentials = new MongoCredentials(builder.Username, builder.Password);
            }

            var clientSettings = new MongoClientSettings();
            clientSettings.ConnectionMode = builder.ConnectionMode;
            clientSettings.ConnectTimeout = builder.ConnectTimeout;
            clientSettings.CredentialsStore = new MongoCredentialsStore();
            clientSettings.DefaultCredentials = defaultCredentials;
            clientSettings.GuidRepresentation = builder.GuidRepresentation;
            clientSettings.IPv6 = builder.IPv6;
            clientSettings.MaxConnectionIdleTime = builder.MaxConnectionIdleTime;
            clientSettings.MaxConnectionLifeTime = builder.MaxConnectionLifeTime;
            clientSettings.MaxConnectionPoolSize = builder.MaxConnectionPoolSize;
            clientSettings.MinConnectionPoolSize = builder.MinConnectionPoolSize;
            clientSettings.ReadPreference = (builder.ReadPreference == null) ? ReadPreference.Primary : builder.ReadPreference.Clone();
            clientSettings.ReplicaSetName = builder.ReplicaSetName;
            clientSettings.SecondaryAcceptableLatency = builder.SecondaryAcceptableLatency;
            clientSettings.Servers = new List<MongoServerAddress>(builder.Servers);
            clientSettings.SocketTimeout = builder.SocketTimeout;
            clientSettings.UseSsl = builder.UseSsl;
            clientSettings.VerifySslCertificate = builder.VerifySslCertificate;
            clientSettings.WaitQueueSize = builder.ComputedWaitQueueSize;
            clientSettings.WaitQueueTimeout = builder.WaitQueueTimeout;
            clientSettings.WriteConcern = builder.GetWriteConcern(false); // fireAndForget default for MongoClientSettings is false
            return clientSettings;
        }
开发者ID:staywellandy,项目名称:mongo-csharp-driver,代码行数:36,代码来源:MongoClientSettings.cs

示例8: TestFromMongoConnectionStringBuilder

        public void TestFromMongoConnectionStringBuilder()
        {
            // set everything to non default values to test that all settings are converted
            var connectionString =
                "server=somehost;username=user1;password=password1;" +
                "connect=direct;connectTimeout=123;uuidRepresentation=pythonLegacy;ipv6=true;" +
                "maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;" +
                "readPreference=secondary;readPreferenceTags=a:1,b:2|c:3,d:4;secondaryAcceptableLatency=128;socketTimeout=129;" +
                "ssl=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
                "w=1;fsync=true;journal=true;w=2;wtimeout=131";
            var builder = new MongoConnectionStringBuilder(connectionString);

            var settings = MongoServerSettings.FromConnectionStringBuilder(builder);
            Assert.AreEqual(builder.ConnectionMode, settings.ConnectionMode);
            Assert.AreEqual(builder.ConnectTimeout, settings.ConnectTimeout);
            Assert.AreEqual(1, settings.Credentials.Count());
            Assert.AreEqual(builder.Username, settings.Credentials.Single().Username);
            Assert.AreEqual("admin", settings.Credentials.Single().Source);
            Assert.AreEqual(new PasswordEvidence(builder.Password), settings.Credentials.Single().Evidence);
            Assert.AreEqual(builder.GuidRepresentation, settings.GuidRepresentation);
            Assert.AreEqual(builder.IPv6, settings.IPv6);
            Assert.AreEqual(builder.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
            Assert.AreEqual(builder.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.AreEqual(builder.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
            Assert.AreEqual(builder.MinConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.AreEqual(builder.ReadPreference, settings.ReadPreference);
            Assert.AreEqual(builder.ReplicaSetName, settings.ReplicaSetName);
            Assert.AreEqual(builder.SecondaryAcceptableLatency, settings.SecondaryAcceptableLatency);
            Assert.IsTrue(builder.Servers.SequenceEqual(settings.Servers));
            Assert.AreEqual(builder.SocketTimeout, settings.SocketTimeout);
            Assert.AreEqual(null, settings.SslSettings);
            Assert.AreEqual(builder.UseSsl, settings.UseSsl);
            Assert.AreEqual(builder.VerifySslCertificate, settings.VerifySslCertificate);
            Assert.AreEqual(builder.ComputedWaitQueueSize, settings.WaitQueueSize);
            Assert.AreEqual(builder.WaitQueueTimeout, settings.WaitQueueTimeout);
#pragma warning disable 618
            Assert.AreEqual(builder.GetWriteConcern(MongoDefaults.SafeMode.Enabled), settings.WriteConcern);
#pragma warning restore
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:39,代码来源:MongoServerSettingsTests.cs

示例9: TestGetWriteConcern_W

 public void TestGetWriteConcern_W(object obj, string connectionString)
 {
     var w = (obj is int) ? (WriteConcern.WValue)(int)obj : (WriteConcern.WValue)(string)obj;
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(false);
     Assert.AreEqual(w, writeConcern.W);
 }
开发者ID:subbuballa,项目名称:mongo-csharp-driver,代码行数:7,代码来源:MongoConnectionStringBuilderTests.cs

示例10: TestGetWriteConcern_FireAndForget

 public void TestGetWriteConcern_FireAndForget(bool fireAndForgetDefault, bool fireAndForget, string connectionString)
 {
     var builder = new MongoConnectionStringBuilder(connectionString);
     var writeConcern = builder.GetWriteConcern(fireAndForgetDefault);
     Assert.AreEqual(fireAndForget, writeConcern.FireAndForget);
 }
开发者ID:subbuballa,项目名称:mongo-csharp-driver,代码行数:6,代码来源:MongoConnectionStringBuilderTests.cs

示例11: FromConnectionStringBuilder

        // public static methods
        /// <summary>
        /// Gets a MongoClientSettings object intialized with values from a connection string builder.
        /// </summary>
        /// <param name="builder">The connection string builder.</param>
        /// <returns>A MongoClientSettings.</returns>
        public static MongoClientSettings FromConnectionStringBuilder(MongoConnectionStringBuilder builder)
        {
            var credentials = MongoCredentials.FromComponents(
                builder.AuthenticationProtocol,
                builder.AuthenticationSource,
                builder.DatabaseName,
                builder.Username,
                builder.Password);

            var clientSettings = new MongoClientSettings();
            clientSettings.ConnectionMode = builder.ConnectionMode;
            clientSettings.ConnectTimeout = builder.ConnectTimeout;
            if (credentials != null)
            {
                clientSettings.CredentialsStore.Add(credentials);
            }
            clientSettings.GuidRepresentation = builder.GuidRepresentation;
            clientSettings.IPv6 = builder.IPv6;
            clientSettings.MaxConnectionIdleTime = builder.MaxConnectionIdleTime;
            clientSettings.MaxConnectionLifeTime = builder.MaxConnectionLifeTime;
            clientSettings.MaxConnectionPoolSize = builder.MaxConnectionPoolSize;
            clientSettings.MinConnectionPoolSize = builder.MinConnectionPoolSize;
            clientSettings.ReadPreference = (builder.ReadPreference == null) ? ReadPreference.Primary : builder.ReadPreference.Clone();
            clientSettings.ReplicaSetName = builder.ReplicaSetName;
            clientSettings.SecondaryAcceptableLatency = builder.SecondaryAcceptableLatency;
            clientSettings.Servers = new List<MongoServerAddress>(builder.Servers);
            clientSettings.SocketTimeout = builder.SocketTimeout;
            clientSettings.UseSsl = builder.UseSsl;
            clientSettings.VerifySslCertificate = builder.VerifySslCertificate;
            clientSettings.WaitQueueSize = builder.ComputedWaitQueueSize;
            clientSettings.WaitQueueTimeout = builder.WaitQueueTimeout;
            clientSettings.WriteConcern = builder.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient
            return clientSettings;
        }
开发者ID:petarvucetin,项目名称:mongo-csharp-driver,代码行数:40,代码来源:MongoClientSettings.cs


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