/// <summary> /// Gets a MongoClientSettings object intialized with values from a URL. /// </summary> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { var clientSettings = new MongoClientSettings(); clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; clientSettings.CredentialsStore = new MongoCredentialsStore(); clientSettings.DefaultCredentials = url.DefaultCredentials; clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; clientSettings.Servers = new List <MongoServerAddress>(url.Servers); clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.UseSsl = url.UseSsl; clientSettings.VerifySslCertificate = url.VerifySslCertificate; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient return(clientSettings); }
/// <summary> /// Gets a MongoServerSettings object intialized with values from a MongoUrl. /// </summary> /// <param name="url">The MongoUrl.</param> /// <returns>A MongoServerSettings.</returns> public static MongoServerSettings FromUrl(MongoUrl url) { var serverSettings = new MongoServerSettings(); serverSettings.ConnectionMode = url.ConnectionMode; serverSettings.ConnectTimeout = url.ConnectTimeout; serverSettings.CredentialsStore = new MongoCredentialsStore(); serverSettings.DefaultCredentials = url.DefaultCredentials; serverSettings.GuidRepresentation = url.GuidRepresentation; serverSettings.IPv6 = url.IPv6; serverSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; serverSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; serverSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; serverSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; serverSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; serverSettings.ReplicaSetName = url.ReplicaSetName; serverSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; serverSettings.Servers = new List <MongoServerAddress>(url.Servers); serverSettings.SocketTimeout = url.SocketTimeout; serverSettings.UseSsl = url.UseSsl; serverSettings.VerifySslCertificate = url.VerifySslCertificate; serverSettings.WaitQueueSize = url.ComputedWaitQueueSize; serverSettings.WaitQueueTimeout = url.WaitQueueTimeout; #pragma warning disable 618 serverSettings.WriteConcern = url.GetWriteConcern(MongoDefaults.SafeMode.Enabled); #pragma warning restore return(serverSettings); }
/// <summary> /// Gets a MongoClientSettings object intialized with values from a MongoURL. /// </summary> /// <param name="url">The MongoURL.</param> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { if (!url.IsResolved) { var connectionMode = url.ConnectionMode; var resolveHosts = connectionMode == ConnectionMode.Direct || connectionMode == ConnectionMode.Standalone; url = url.Resolve(resolveHosts); } var credential = url.GetCredential(); var clientSettings = new MongoClientSettings(); clientSettings.AllowInsecureTls = url.AllowInsecureTls; clientSettings.ApplicationName = url.ApplicationName; clientSettings.Compressors = url.Compressors; clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { foreach (var property in url.AuthenticationMechanismProperties) { if (property.Key.Equals("CANONICALIZE_HOST_NAME", StringComparison.OrdinalIgnoreCase)) { credential = credential.WithMechanismProperty(property.Key, bool.Parse(property.Value)); } else { credential = credential.WithMechanismProperty(property.Key, property.Value); } } clientSettings.Credential = credential; } clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.HeartbeatInterval = url.HeartbeatInterval; clientSettings.HeartbeatTimeout = url.HeartbeatTimeout; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadConcern = new ReadConcern(url.ReadConcernLevel); clientSettings.ReadEncoding = null; // ReadEncoding must be provided in code clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.RetryReads = url.RetryReads.GetValueOrDefault(true); clientSettings.RetryWrites = url.RetryWrites.GetValueOrDefault(true); clientSettings.LocalThreshold = url.LocalThreshold; clientSettings.Scheme = url.Scheme; clientSettings.Servers = new List <MongoServerAddress>(url.Servers); clientSettings.ServerSelectionTimeout = url.ServerSelectionTimeout; clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.SslSettings = null; // SSL settings must be provided in code clientSettings.UseTls = url.UseTls; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient clientSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(clientSettings); }
/// <summary> /// Gets a MongoServerSettings object intialized with values from a MongoUrl. /// </summary> /// <param name="url">The MongoUrl.</param> /// <returns>A MongoServerSettings.</returns> public static MongoServerSettings FromUrl(MongoUrl url) { var credential = url.GetCredential(); var serverSettings = new MongoServerSettings(); serverSettings.AllowInsecureTls = url.AllowInsecureTls; serverSettings.ApplicationName = url.ApplicationName; serverSettings.Compressors = url.Compressors; serverSettings.ConnectionMode = url.ConnectionMode; serverSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { foreach (var property in url.AuthenticationMechanismProperties) { if (property.Key.Equals("CANONICALIZE_HOST_NAME", StringComparison.OrdinalIgnoreCase)) { credential = credential.WithMechanismProperty(property.Key, bool.Parse(property.Value)); } else { credential = credential.WithMechanismProperty(property.Key, property.Value); } } serverSettings.Credential = credential; } serverSettings.GuidRepresentation = url.GuidRepresentation; serverSettings.HeartbeatInterval = url.HeartbeatInterval; serverSettings.HeartbeatTimeout = url.HeartbeatTimeout; serverSettings.IPv6 = url.IPv6; serverSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; serverSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; serverSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; serverSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; serverSettings.ReadConcern = new ReadConcern(url.ReadConcernLevel); serverSettings.ReadEncoding = null; // ReadEncoding must be provided in code serverSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; serverSettings.ReplicaSetName = url.ReplicaSetName; serverSettings.RetryReads = url.RetryReads ?? true; serverSettings.RetryWrites = url.RetryWrites ?? true; serverSettings.LocalThreshold = url.LocalThreshold; serverSettings.Scheme = url.Scheme; serverSettings.SdamLogFilename = null; // SdamLogFilename must be provided in code serverSettings.Servers = new List <MongoServerAddress>(url.Servers); serverSettings.ServerSelectionTimeout = url.ServerSelectionTimeout; serverSettings.SocketTimeout = url.SocketTimeout; serverSettings.SslSettings = null; // SSL settings must be provided in code serverSettings.UseTls = url.UseTls; #pragma warning disable 618 serverSettings.WaitQueueSize = url.ComputedWaitQueueSize; #pragma warning restore 618 serverSettings.WaitQueueTimeout = url.WaitQueueTimeout; serverSettings.WriteConcern = url.GetWriteConcern(false); serverSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(serverSettings); }
// public static methods /// <summary> /// Gets a MongoClientSettings object intialized with values from a MongoURL. /// </summary> /// <param name="url">The MongoURL.</param> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { var credential = MongoCredential.FromComponents( url.AuthenticationMechanism, url.AuthenticationSource ?? url.DatabaseName, url.Username, url.Password); var clientSettings = new MongoClientSettings(); clientSettings.ApplicationName = url.ApplicationName; clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { foreach (var property in url.AuthenticationMechanismProperties) { if (property.Key.Equals("CANONICALIZE_HOST_NAME", StringComparison.OrdinalIgnoreCase)) { credential = credential.WithMechanismProperty(property.Key, bool.Parse(property.Value)); } else { credential = credential.WithMechanismProperty(property.Key, property.Value); } } clientSettings.Credentials = new[] { credential }; } clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.HeartbeatInterval = url.HeartbeatInterval; clientSettings.HeartbeatTimeout = url.HeartbeatTimeout; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadConcern = new ReadConcern(url.ReadConcernLevel); clientSettings.ReadEncoding = null; // ReadEncoding must be provided in code clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.LocalThreshold = url.LocalThreshold; clientSettings.Servers = new List <MongoServerAddress>(url.Servers); clientSettings.ServerSelectionTimeout = url.ServerSelectionTimeout; clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.SslSettings = null; // SSL settings must be provided in code clientSettings.UseSsl = url.UseSsl; clientSettings.VerifySslCertificate = url.VerifySslCertificate; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient clientSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(clientSettings); }
/// <summary> /// Gets a MongoServerSettings object intialized with values from a MongoUrl. /// </summary> /// <param name="url">The MongoUrl.</param> /// <returns>A MongoServerSettings.</returns> public static MongoServerSettings FromUrl(MongoUrl url) { var credential = MongoCredential.FromComponents( url.AuthenticationMechanism, url.AuthenticationSource ?? url.DatabaseName, url.Username, url.Password); var serverSettings = new MongoServerSettings(); serverSettings.ConnectionMode = url.ConnectionMode; serverSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { foreach (var property in url.AuthenticationMechanismProperties) { if (property.Key.Equals("CANONICALIZE_HOST_NAME", StringComparison.InvariantCultureIgnoreCase)) { credential = credential.WithMechanismProperty(property.Key, bool.Parse(property.Value)); } else { credential = credential.WithMechanismProperty(property.Key, property.Value); } } serverSettings.Credentials = new[] { credential }; } serverSettings.GuidRepresentation = url.GuidRepresentation; serverSettings.IPv6 = url.IPv6; serverSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; serverSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; serverSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; serverSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; serverSettings.ReadEncoding = null; // ReadEncoding must be provided in code serverSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; serverSettings.ReplicaSetName = url.ReplicaSetName; serverSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; serverSettings.Servers = new List <MongoServerAddress>(url.Servers); serverSettings.SocketTimeout = url.SocketTimeout; serverSettings.SslSettings = null; // SSL settings must be provided in code serverSettings.UseSsl = url.UseSsl; serverSettings.VerifySslCertificate = url.VerifySslCertificate; serverSettings.WaitQueueSize = url.ComputedWaitQueueSize; serverSettings.WaitQueueTimeout = url.WaitQueueTimeout; serverSettings.WriteConcern = url.GetWriteConcern(false); serverSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(serverSettings); }
/// <summary> /// Gets a MongoServerSettings object intialized with values from a MongoUrl. /// </summary> /// <param name="url">The MongoUrl.</param> /// <returns>A MongoServerSettings.</returns> public static MongoServerSettings FromUrl(MongoUrl url) { var credential = MongoCredential.FromComponents( url.AuthenticationMechanism, url.AuthenticationSource ?? url.DatabaseName, url.Username, url.Password); var serverSettings = new MongoServerSettings(); serverSettings.ConnectionMode = url.ConnectionMode; serverSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { if (!string.IsNullOrEmpty(url.GssapiServiceName)) { credential = credential.WithMechanismProperty("SERVICE_NAME", url.GssapiServiceName); } serverSettings.Credentials = new[] { credential }; } serverSettings.GuidRepresentation = url.GuidRepresentation; serverSettings.IPv6 = url.IPv6; serverSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; serverSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; serverSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; serverSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; serverSettings.ReadEncoding = null; // ReadEncoding must be provided in code serverSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; serverSettings.ReplicaSetName = url.ReplicaSetName; serverSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; serverSettings.Servers = new List <MongoServerAddress>(url.Servers); serverSettings.SocketTimeout = url.SocketTimeout; serverSettings.SslSettings = null; // SSL settings must be provided in code serverSettings.UseSsl = url.UseSsl; serverSettings.VerifySslCertificate = url.VerifySslCertificate; serverSettings.WaitQueueSize = url.ComputedWaitQueueSize; serverSettings.WaitQueueTimeout = url.WaitQueueTimeout; #pragma warning disable 618 serverSettings.WriteConcern = url.GetWriteConcern(MongoDefaults.SafeMode.Enabled); #pragma warning restore serverSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(serverSettings); }
/// <summary> /// Gets a MongoClientSettings object intialized with values from a MongoURL. /// </summary> /// <param name="url">The MongoURL.</param> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { var credential = MongoCredential.FromComponents( url.AuthenticationMechanism, url.AuthenticationSource ?? url.DatabaseName, url.Username, url.Password); var clientSettings = new MongoClientSettings(); clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { clientSettings.Credentials = new[] { credential }; } clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadEncoding = null; // ReadEncoding must be provided in code clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; clientSettings.Servers = new List <MongoServerAddress>(url.Servers); clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.SslSettings = null; // SSL settings must be provided in code clientSettings.UseSsl = url.UseSsl; clientSettings.VerifySslCertificate = url.VerifySslCertificate; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient clientSettings.WriteEncoding = null; // WriteEncoding must be provided in code return(clientSettings); }
/// <summary> /// Gets a MongoClientSettings object intialized with values from a URL. /// </summary> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { var clientSettings = new MongoClientSettings(); clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; clientSettings.CredentialsStore = new MongoCredentialsStore(); clientSettings.DefaultCredentials = url.DefaultCredentials; clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; clientSettings.Servers = new List<MongoServerAddress>(url.Servers); clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.UseSsl = url.UseSsl; clientSettings.VerifySslCertificate = url.VerifySslCertificate; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(false); // fireAndForget default for MongoClientSettings is false return clientSettings; }
public void TestGetWriteConcern_WTimeout(int? ms, string connectionString) { var wtimeout = (ms == null) ? (TimeSpan?)null : TimeSpan.FromMilliseconds(ms.Value); var url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(true); Assert.AreEqual(wtimeout, writeConcern.WTimeout); }
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 url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(enabledDefault); Assert.AreEqual(enabled, writeConcern.Enabled); Assert.AreEqual(w, writeConcern.W); }
/// <summary> /// Gets a MongoClientSettings object intialized with values from a MongoURL. /// </summary> /// <param name="url">The MongoURL.</param> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { if (!url.IsResolved) { bool resolveHosts; #pragma warning disable CS0618 // Type or member is obsolete if (url.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection) #pragma warning restore CS0618 // Type or member is obsolete { resolveHosts = url.DirectConnection.GetValueOrDefault(); } else { #pragma warning disable CS0618 // Type or member is obsolete var connectionMode = url.ConnectionMode; #pragma warning restore CS0618 // Type or member is obsolete resolveHosts = connectionMode == ConnectionMode.Direct || connectionMode == ConnectionMode.Standalone; } url = url.Resolve(resolveHosts); } var credential = url.GetCredential(); var clientSettings = new MongoClientSettings(); clientSettings.AllowInsecureTls = url.AllowInsecureTls; clientSettings.ApplicationName = url.ApplicationName; clientSettings.AutoEncryptionOptions = null; // must be configured via code clientSettings.Compressors = url.Compressors; #pragma warning disable CS0618 // Type or member is obsolete if (url.ConnectionModeSwitch == ConnectionModeSwitch.UseConnectionMode) { clientSettings.ConnectionMode = url.ConnectionMode; #pragma warning restore CS0618 // Type or member is obsolete } clientSettings.ConnectTimeout = url.ConnectTimeout; if (credential != null) { foreach (var property in url.AuthenticationMechanismProperties) { if (property.Key.Equals("CANONICALIZE_HOST_NAME", StringComparison.OrdinalIgnoreCase)) { credential = credential.WithMechanismProperty(property.Key, bool.Parse(property.Value)); } else { credential = credential.WithMechanismProperty(property.Key, property.Value); } } clientSettings.Credential = credential; } #pragma warning disable CS0618 // Type or member is obsolete if (url.ConnectionModeSwitch == ConnectionModeSwitch.UseDirectConnection) #pragma warning restore CS0618 // Type or member is obsolete { clientSettings.DirectConnection = url.DirectConnection; } #pragma warning disable 618 if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2) { clientSettings.GuidRepresentation = url.GuidRepresentation; } #pragma warning restore 618 clientSettings.HeartbeatInterval = url.HeartbeatInterval; clientSettings.HeartbeatTimeout = url.HeartbeatTimeout; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadConcern = new ReadConcern(url.ReadConcernLevel); clientSettings.ReadEncoding = null; // ReadEncoding must be provided in code clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.RetryReads = url.RetryReads.GetValueOrDefault(true); clientSettings.RetryWrites = url.RetryWrites.GetValueOrDefault(true); clientSettings.LocalThreshold = url.LocalThreshold; clientSettings.Scheme = url.Scheme; clientSettings.Servers = new List<MongoServerAddress>(url.Servers); clientSettings.ServerSelectionTimeout = url.ServerSelectionTimeout; clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.SslSettings = null; if (url.TlsDisableCertificateRevocationCheck) { clientSettings.SslSettings = new SslSettings { CheckCertificateRevocation = false }; } clientSettings.UseTls = url.UseTls; #pragma warning disable 618 clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; #pragma warning restore 618 clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient clientSettings.WriteEncoding = null; // WriteEncoding must be provided in code return clientSettings; }
public void TestGetWriteConcern_Enabled(bool enabledDefault, bool enabled, string connectionString) { var url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(enabledDefault || enabled); Assert.AreEqual(enabled, writeConcern.Enabled); }
public void TestGetWriteConcern_W(object obj, string connectionString) { var w = (obj is int) ? (WriteConcern.WValue)(int)obj : (WriteConcern.WValue)(string)obj; var url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(false); Assert.AreEqual(w, writeConcern.W); }
public void TestGetWriteConcern_FireAndForget(bool fireAndForgetDefault, bool fireAndForget, string connectionString) { var url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(fireAndForgetDefault); Assert.AreEqual(fireAndForget, writeConcern.FireAndForget); }
/// <summary> /// Gets a MongoServerSettings object intialized with values from a URL. /// </summary> /// <returns>A MongoServerSettings.</returns> public static MongoServerSettings FromUrl(MongoUrl url) { var serverSettings = new MongoServerSettings(); serverSettings.ConnectionMode = url.ConnectionMode; serverSettings.ConnectTimeout = url.ConnectTimeout; serverSettings.CredentialsStore = new MongoCredentialsStore(); serverSettings.DefaultCredentials = url.DefaultCredentials; serverSettings.GuidRepresentation = url.GuidRepresentation; serverSettings.IPv6 = url.IPv6; serverSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; serverSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; serverSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; serverSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; serverSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; serverSettings.ReplicaSetName = url.ReplicaSetName; serverSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; serverSettings.Servers = new List<MongoServerAddress>(url.Servers); serverSettings.SocketTimeout = url.SocketTimeout; serverSettings.UseSsl = url.UseSsl; serverSettings.VerifySslCertificate = url.VerifySslCertificate; serverSettings.WaitQueueSize = url.ComputedWaitQueueSize; serverSettings.WaitQueueTimeout = url.WaitQueueTimeout; #pragma warning disable 618 serverSettings.WriteConcern = url.GetWriteConcern(MongoDefaults.SafeMode.Enabled); #pragma warning restore return serverSettings; }
public void TestGetWriteConcern_FSync(bool? fsync, string connectionString) { var url = new MongoUrl(connectionString); var writeConcern = url.GetWriteConcern(true); Assert.AreEqual(fsync, writeConcern.FSync); }
/// <summary> /// Gets a MongoClientSettings object intialized with values from a MongoURL. /// </summary> /// <param name="url">The MongoURL.</param> /// <returns>A MongoClientSettings.</returns> public static MongoClientSettings FromUrl(MongoUrl url) { var credentials = MongoCredentials.FromComponents( url.AuthenticationProtocol, url.AuthenticationSource, url.DatabaseName, url.Username, url.Password); var clientSettings = new MongoClientSettings(); clientSettings.ConnectionMode = url.ConnectionMode; clientSettings.ConnectTimeout = url.ConnectTimeout; if (credentials != null) { clientSettings.CredentialsStore.Add(credentials); } clientSettings.GuidRepresentation = url.GuidRepresentation; clientSettings.IPv6 = url.IPv6; clientSettings.MaxConnectionIdleTime = url.MaxConnectionIdleTime; clientSettings.MaxConnectionLifeTime = url.MaxConnectionLifeTime; clientSettings.MaxConnectionPoolSize = url.MaxConnectionPoolSize; clientSettings.MinConnectionPoolSize = url.MinConnectionPoolSize; clientSettings.ReadPreference = (url.ReadPreference == null) ? ReadPreference.Primary : url.ReadPreference; clientSettings.ReplicaSetName = url.ReplicaSetName; clientSettings.SecondaryAcceptableLatency = url.SecondaryAcceptableLatency; clientSettings.Servers = new List<MongoServerAddress>(url.Servers); clientSettings.SocketTimeout = url.SocketTimeout; clientSettings.UseSsl = url.UseSsl; clientSettings.VerifySslCertificate = url.VerifySslCertificate; clientSettings.WaitQueueSize = url.ComputedWaitQueueSize; clientSettings.WaitQueueTimeout = url.WaitQueueTimeout; clientSettings.WriteConcern = url.GetWriteConcern(true); // WriteConcern is enabled by default for MongoClient return clientSettings; }