當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。