/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="readPreference">The read preference.</param> /// <param name="safeMode">The safe mode to use.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, ReadPreference readPreference, SafeMode safeMode) { if (databaseName == null) { throw new ArgumentNullException("databaseName"); } if (databaseName == "admin" && credentials != null && !credentials.Admin) { throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true."); } if (readPreference == null) { throw new ArgumentNullException("readPreference"); } if (safeMode == null) { throw new ArgumentNullException("safeMode"); } _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _readPreference = readPreference; _safeMode = safeMode; }
public MongoServerSettings( ConnectionMode connectionMode, TimeSpan connectTimeout, MongoCredentials defaultCredentials, TimeSpan maxConnectionIdleTime, TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, string replicaSetName, SafeMode safeMode, IEnumerable<MongoServerAddress> servers, bool slaveOk, TimeSpan socketTimeout, int waitQueueSize, TimeSpan waitQueueTimeout ) { this.connectionMode = connectionMode; this.connectTimeout = connectTimeout; this.defaultCredentials = defaultCredentials; this.maxConnectionIdleTime = maxConnectionIdleTime; this.maxConnectionLifeTime = maxConnectionLifeTime; this.maxConnectionPoolSize = maxConnectionPoolSize; this.minConnectionPoolSize = minConnectionPoolSize; this.replicaSetName = replicaSetName; this.safeMode = safeMode; this.servers = servers; this.slaveOk = slaveOk; this.socketTimeout = socketTimeout; this.waitQueueSize = waitQueueSize; this.waitQueueTimeout = waitQueueTimeout; }
/// <summary> /// Initializes a new instance of the MongoInsertOptions class. /// </summary> /// <param name="collection">The collection from which to get default settings for the options.</param> public MongoInsertOptions( MongoCollection collection ) { this.checkElementNames = true; this.flags = InsertFlags.None; this.safeMode = collection.Settings.SafeMode; }
/// <summary> /// Gets a MongoDatabase instance representing a database on this server. Only one instance /// is created for each combination of database settings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to use with this database.</param> /// <param name="safeMode">The safe mode to use with this database.</param> /// <returns>A new or existing instance of MongoDatabase.</returns> public virtual MongoDatabase this[ string databaseName, MongoCredentials credentials, SafeMode safeMode ] { get { return(GetDatabase(databaseName, credentials, safeMode)); } }
// private methods private void ResetValues() { _connectionMode = ConnectionMode.Automatic; _connectTimeout = MongoDefaults.ConnectTimeout; _databaseName = null; _defaultCredentials = null; _guidRepresentation = MongoDefaults.GuidRepresentation; _ipv6 = false; _maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; _readPreference = null; _replicaSetName = null; _safeMode = null; _secondaryAcceptableLatency = MongoDefaults.SecondaryAcceptableLatency; _servers = null; _slaveOk = null; _socketTimeout = MongoDefaults.SocketTimeout; _useSsl = false; _verifySslCertificate = true; _waitQueueMultiple = MongoDefaults.WaitQueueMultiple; _waitQueueSize = MongoDefaults.WaitQueueSize; _waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
/// <summary> /// Initializes a new instance of the MongoCollectionSettings class. /// </summary> /// <param name="collectionName">The name of the collection.</param> /// <param name="assignIdOnInsert">Whether to automatically assign a value to an empty document Id on insert.</param> /// <param name="defaultDocumentType">The default document type for the collection.</param> /// <param name="guidRepresentation">The GUID representation to use with this collection.</param> /// <param name="readPreference">The read preference.</param> /// <param name="safeMode">The SafeMode to use with this collection.</param> protected MongoCollectionSettings( string collectionName, bool assignIdOnInsert, Type defaultDocumentType, GuidRepresentation guidRepresentation, ReadPreference readPreference, SafeMode safeMode) { if (collectionName == null) { throw new ArgumentNullException("collectionName"); } if (defaultDocumentType == null) { throw new ArgumentNullException("defaultDocumentType"); } if (readPreference == null) { throw new ArgumentNullException("readPreference"); } if (safeMode == null) { throw new ArgumentNullException("safeMode"); } _collectionName = collectionName; _assignIdOnInsert = assignIdOnInsert; _defaultDocumentType = defaultDocumentType; _guidRepresentation = guidRepresentation; _readPreference = readPreference; _safeMode = safeMode; }
// constructors /// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { _connectionMode = ConnectionMode.Direct; _connectTimeout = MongoDefaults.ConnectTimeout; _credentialsStore = new MongoCredentialsStore(); _defaultCredentials = null; _guidRepresentation = MongoDefaults.GuidRepresentation; _ipv6 = false; _maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; _readPreference = ReadPreference.Primary; _replicaSetName = null; _safeMode = MongoDefaults.SafeMode; _servers = new List <MongoServerAddress> { new MongoServerAddress("localhost") }; _serversReadOnly = new ReadOnlyCollection <MongoServerAddress>(_servers); _socketTimeout = MongoDefaults.SocketTimeout; _useSsl = false; _verifySslCertificate = true; _waitQueueSize = MongoDefaults.ComputedWaitQueueSize; _waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
/// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> /// <param name="connectionMode">The connection mode (Direct or ReplicaSet).</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="defaultCredentials">The default credentials.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="ipv6">Whether to use IPv6.</param> /// <param name="maxConnectionIdleTime">The max connection idle time.</param> /// <param name="maxConnectionLifeTime">The max connection life time.</param> /// <param name="maxConnectionPoolSize">The max connection pool size.</param> /// <param name="minConnectionPoolSize">The min connection pool size.</param> /// <param name="replicaSetName">The name of the replica set.</param> /// <param name="safeMode">The safe mode.</param> /// <param name="servers">The server addresses (normally one unless it is the seed list for connecting to a replica set).</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> /// <param name="socketTimeout">The socket timeout.</param> /// <param name="waitQueueSize">The wait queue size.</param> /// <param name="waitQueueTimeout">The wait queue timeout.</param> public MongoServerSettings( ConnectionMode connectionMode, TimeSpan connectTimeout, MongoCredentials defaultCredentials, GuidRepresentation guidRepresentation, bool ipv6, TimeSpan maxConnectionIdleTime, TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, string replicaSetName, SafeMode safeMode, IEnumerable <MongoServerAddress> servers, bool slaveOk, TimeSpan socketTimeout, int waitQueueSize, TimeSpan waitQueueTimeout) { _connectionMode = connectionMode; _connectTimeout = connectTimeout; _defaultCredentials = defaultCredentials; _guidRepresentation = guidRepresentation; _ipv6 = ipv6; _maxConnectionIdleTime = maxConnectionIdleTime; _maxConnectionLifeTime = maxConnectionLifeTime; _maxConnectionPoolSize = maxConnectionPoolSize; _minConnectionPoolSize = minConnectionPoolSize; _replicaSetName = replicaSetName; _safeMode = safeMode; _servers = servers; _slaveOk = slaveOk; _socketTimeout = socketTimeout; _waitQueueSize = waitQueueSize; _waitQueueTimeout = waitQueueTimeout; }
/// <summary> /// Gets a MongoDatabase instance representing the admin database on this server. Only one instance /// is created for each combination of database settings. /// </summary> /// <param name="credentials">The credentials to use with the admin database.</param> /// <param name="safeMode">The safe mode to use with the admin database.</param> /// <returns>A new or existing instance of MongoDatabase.</returns> public virtual MongoDatabase GetAdminDatabase( MongoCredentials credentials, SafeMode safeMode ) { return(GetDatabase("admin", credentials, safeMode)); }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="readPreference">The read preference.</param> /// <param name="safeMode">The safe mode to use.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, ReadPreference readPreference, SafeMode safeMode) { if (databaseName == null) { throw new ArgumentNullException("databaseName"); } if (databaseName == "admin" && credentials != null && !credentials.Admin) { throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true."); } if (readPreference == null) { throw new ArgumentNullException("readPreference"); } if (safeMode == null) { throw new ArgumentNullException("safeMode"); } _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _readPreference = readPreference; _safeMode = safeMode; }
/// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> /// <param name="connectionMode">The connection mode (Direct or ReplicaSet).</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="defaultCredentials">The default credentials.</param> /// <param name="ipv6">Whether to use IPv6.</param> /// <param name="maxConnectionIdleTime">The max connection idle time.</param> /// <param name="maxConnectionLifeTime">The max connection life time.</param> /// <param name="maxConnectionPoolSize">The max connection pool size.</param> /// <param name="minConnectionPoolSize">The min connection pool size.</param> /// <param name="replicaSetName">The name of the replica set.</param> /// <param name="safeMode">The safe mode.</param> /// <param name="servers">The server addresses (normally one unless it is the seed list for connecting to a replica set).</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> /// <param name="socketTimeout">The socket timeout.</param> /// <param name="waitQueueSize">The wait queue size.</param> /// <param name="waitQueueTimeout">The wait queue timeout.</param> public MongoServerSettings( ConnectionMode connectionMode, TimeSpan connectTimeout, MongoCredentials defaultCredentials, bool ipv6, TimeSpan maxConnectionIdleTime, TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, string replicaSetName, SafeMode safeMode, IEnumerable <MongoServerAddress> servers, bool slaveOk, TimeSpan socketTimeout, int waitQueueSize, TimeSpan waitQueueTimeout ) { this.connectionMode = connectionMode; this.connectTimeout = connectTimeout; this.defaultCredentials = defaultCredentials; this.ipv6 = ipv6; this.maxConnectionIdleTime = maxConnectionIdleTime; this.maxConnectionLifeTime = maxConnectionLifeTime; this.maxConnectionPoolSize = maxConnectionPoolSize; this.minConnectionPoolSize = minConnectionPoolSize; this.replicaSetName = replicaSetName; this.safeMode = safeMode; this.servers = servers; this.slaveOk = slaveOk; this.socketTimeout = socketTimeout; this.waitQueueSize = waitQueueSize; this.waitQueueTimeout = waitQueueTimeout; }
private void ResetValues() { // set fields and not properties so base class items aren't set _connectionMode = ConnectionMode.Automatic; _connectTimeout = MongoDefaults.ConnectTimeout; _databaseName = null; _guidRepresentation = MongoDefaults.GuidRepresentation; _ipv6 = false; _maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; _password = null; _readPreference = null; _replicaSetName = null; _safeMode = null; _servers = null; _slaveOk = null; _socketTimeout = MongoDefaults.SocketTimeout; _username = null; _useSsl = false; _verifySslCertificate = true; _waitQueueMultiple = MongoDefaults.WaitQueueMultiple; _waitQueueSize = MongoDefaults.WaitQueueSize; _waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
public MongoDatabaseSettings() { this.databaseName = null; this.credentials = null; this.safeMode = SafeMode.False; this.slaveOk = false; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _safeMode = safeMode; _slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, ReadPreference readPreference) { this.databaseName = databaseName; this.credentials = credentials; this.guidRepresentation = guidRepresentation; this.safeMode = safeMode; this.readPreference = readPreference; }
public MongoCollectionSettings() { this.collectionName = null; this.assignIdOnInsert = true; this.defaultDocumentType = typeof(BsonDocument); this.safeMode = SafeMode.False; this.slaveOk = false; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { this.databaseName = databaseName; this.credentials = credentials; this.guidRepresentation = guidRepresentation; this.safeMode = safeMode; this.slaveOk = slaveOk; }
/// <summary> /// Initializes a new instance of the MongoUpdateOptions class. /// </summary> /// <param name="collection">The collection from which to get default settings for the options.</param> public MongoUpdateOptions( MongoCollection collection ) { this.checkElementNames = true; this.flags = UpdateFlags.None; this.safeMode = collection.Settings.SafeMode; }
// constructors /// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="server">The server to inherit settings from.</param> /// <param name="databaseName">The name of the database.</param> public MongoDatabaseSettings(MongoServer server, string databaseName) { var serverSettings = server.Settings; _databaseName = databaseName; _credentials = serverSettings.DefaultCredentials; _guidRepresentation = serverSettings.GuidRepresentation; _safeMode = serverSettings.SafeMode; _slaveOk = serverSettings.SlaveOk; }
/// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> /// <param name="connectionMode">The connection mode (Direct or ReplicaSet).</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="credentialsStore">The credentials store.</param> /// <param name="defaultCredentials">The default credentials.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="ipv6">Whether to use IPv6.</param> /// <param name="maxConnectionIdleTime">The max connection idle time.</param> /// <param name="maxConnectionLifeTime">The max connection life time.</param> /// <param name="maxConnectionPoolSize">The max connection pool size.</param> /// <param name="minConnectionPoolSize">The min connection pool size.</param> /// <param name="readPreference">The default read preference.</param> /// <param name="replicaSetName">The name of the replica set.</param> /// <param name="safeMode">The safe mode.</param> /// <param name="secondaryAcceptableLatency">The secondary acceptable latency.</param> /// <param name="servers">The server addresses (normally one unless it is the seed list for connecting to a replica set).</param> /// <param name="socketTimeout">The socket timeout.</param> /// <param name="useSsl">Whether to use SSL.</param> /// <param name="verifySslCertificate">Whether to verify an SSL certificate.</param> /// <param name="waitQueueSize">The wait queue size.</param> /// <param name="waitQueueTimeout">The wait queue timeout.</param> /// <exception cref="System.ArgumentNullException"></exception> public MongoServerSettings( ConnectionMode connectionMode, TimeSpan connectTimeout, MongoCredentialsStore credentialsStore, MongoCredentials defaultCredentials, GuidRepresentation guidRepresentation, bool ipv6, TimeSpan maxConnectionIdleTime, TimeSpan maxConnectionLifeTime, int maxConnectionPoolSize, int minConnectionPoolSize, ReadPreference readPreference, string replicaSetName, SafeMode safeMode, TimeSpan secondaryAcceptableLatency, IEnumerable<MongoServerAddress> servers, TimeSpan socketTimeout, bool useSsl, bool verifySslCertificate, int waitQueueSize, TimeSpan waitQueueTimeout) { if (servers == null) { throw new ArgumentNullException("servers"); } if (readPreference == null) { throw new ArgumentNullException("readPreference"); } if (safeMode == null) { throw new ArgumentNullException("safeMode"); } _connectionMode = connectionMode; _connectTimeout = connectTimeout; _credentialsStore = credentialsStore ?? new MongoCredentialsStore(); _defaultCredentials = defaultCredentials; _guidRepresentation = guidRepresentation; _ipv6 = ipv6; _maxConnectionIdleTime = maxConnectionIdleTime; _maxConnectionLifeTime = maxConnectionLifeTime; _maxConnectionPoolSize = maxConnectionPoolSize; _minConnectionPoolSize = minConnectionPoolSize; _readPreference = readPreference; _replicaSetName = replicaSetName; _safeMode = safeMode; _secondaryAcceptableLatency = secondaryAcceptableLatency; _servers = new List<MongoServerAddress>(servers); _serversReadOnly = new ReadOnlyCollection<MongoServerAddress>(_servers); _socketTimeout = socketTimeout; _useSsl = useSsl; _verifySslCertificate = verifySslCertificate; _waitQueueSize = waitQueueSize; _waitQueueTimeout = waitQueueTimeout; }
// constructors /// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="server">The server to inherit settings from.</param> /// <param name="databaseName">The name of the database.</param> public MongoDatabaseSettings(MongoServer server, string databaseName) { var serverSettings = server.Settings; this.databaseName = databaseName; this.credentials = serverSettings.DefaultCredentials; this.guidRepresentation = serverSettings.GuidRepresentation; this.safeMode = serverSettings.SafeMode; this.readPreference = serverSettings.ReadPreference; }
/// <summary> /// Initializes a new instance of the MongoCollectionSettings class. /// </summary> /// <param name="collectionName">The name of the collection.</param> /// <param name="assignIdOnInsert">Whether to automatically assign a value to an empty document Id on insert.</param> /// <param name="defaultDocumentType">The default document type for the collection.</param> /// <param name="guidRepresentation">The GUID representation to use with this collection.</param> /// <param name="safeMode">The SafeMode to use with this collection.</param> /// <param name="slaveOk">Whether to route reads to secondaries for this collection.</param> protected MongoCollectionSettings(string collectionName, bool assignIdOnInsert, Type defaultDocumentType, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { this.collectionName = collectionName; this.assignIdOnInsert = assignIdOnInsert; this.defaultDocumentType = defaultDocumentType; this.guidRepresentation = guidRepresentation; this.safeMode = safeMode; this.slaveOk = slaveOk; }
// constructors /// <summary> /// Initializes a new instance of the MongoCollectionSettings class. /// </summary> /// <param name="database">The database that contains the collection (some collection settings will be inherited from the database settings).</param> /// <param name="collectionName">The name of the collection.</param> /// <param name="defaultDocumentType">The default document type for the collection.</param> protected MongoCollectionSettings(MongoDatabase database, string collectionName, Type defaultDocumentType) { var databaseSettings = database.Settings; _collectionName = collectionName; _assignIdOnInsert = MongoDefaults.AssignIdOnInsert; _defaultDocumentType = defaultDocumentType; _guidRepresentation = databaseSettings.GuidRepresentation; _safeMode = databaseSettings.SafeMode; _slaveOk = databaseSettings.SlaveOk; }
/// <summary> /// Gets a MongoCollection instance representing a collection on this database /// with a default document type of BsonDocument. /// </summary> /// <param name="collectionName">The name of the collection.</param> /// <param name="safeMode">The safe mode to use when accessing this collection.</param> /// <returns>An instance of MongoCollection.</returns> public virtual MongoCollection <BsonDocument> GetCollection( string collectionName, SafeMode safeMode ) { var collectionSettings = CreateCollectionSettings <BsonDocument>(collectionName); collectionSettings.SafeMode = safeMode; return(GetCollection(collectionSettings)); }
public void TestCreateWithEnabledAndFSync() { var safeMode = new SafeMode(true, true); Assert.AreEqual(true, safeMode.Enabled); Assert.AreEqual(true, safeMode.FSync); Assert.AreEqual(false, safeMode.Journal); Assert.AreEqual(0, safeMode.W); Assert.AreEqual(null, safeMode.WMode); Assert.AreEqual(TimeSpan.Zero, safeMode.WTimeout); }
/// <summary> /// Compares two SafeMode values. /// </summary> /// <param name="rhs">The other SafeMode value.</param> /// <returns>True if the values are equal.</returns> public bool Equals( SafeMode rhs ) { if (rhs == null) { return(false); } return(this.enabled == rhs.enabled && this.fsync == rhs.fsync && this.w == rhs.w && this.wtimeout == rhs.wtimeout); }
// constructors /// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="server">The server to inherit settings from.</param> /// <param name="databaseName">The name of the database.</param> public MongoDatabaseSettings(MongoServer server, string databaseName) { var serverSettings = server.Settings; _databaseName = databaseName; _credentials = serverSettings.GetCredentials(databaseName); _guidRepresentation = serverSettings.GuidRepresentation; _safeMode = serverSettings.SafeMode; _slaveOk = serverSettings.SlaveOk; }
// constructors /// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="server">The server to inherit settings from.</param> /// <param name="databaseName">The name of the database.</param> public MongoDatabaseSettings(MongoServer server, string databaseName) { var serverSettings = server.Settings; this.databaseName = databaseName; this.credentials = serverSettings.DefaultCredentials; this.guidRepresentation = serverSettings.GuidRepresentation; this.safeMode = serverSettings.SafeMode; this.slaveOk = serverSettings.SlaveOk; }
/// <summary> /// Gets a MongoCollection instance representing a collection on this database /// with a default document type of BsonDocument. /// </summary> /// <param name="defaultDocumentType">The default document type.</param> /// <param name="collectionName">The name of the collection.</param> /// <param name="safeMode">The safe mode to use when accessing this collection.</param> /// <returns>An instance of MongoCollection.</returns> public virtual MongoCollection GetCollection( Type defaultDocumentType, string collectionName, SafeMode safeMode) { var collectionSettings = CreateCollectionSettings(defaultDocumentType, collectionName); collectionSettings.SafeMode = safeMode; return(GetCollection(collectionSettings)); }
/// <summary> /// Gets a MongoDatabase instance representing a database on this server. Only one instance /// is created for each combination of database settings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="safeMode">The safe mode to use with this database.</param> /// <returns>A new or existing instance of MongoDatabase.</returns> public virtual MongoDatabase GetDatabase( string databaseName, SafeMode safeMode ) { var databaseSettings = CreateDatabaseSettings(databaseName); databaseSettings.SafeMode = safeMode; return(GetDatabase(databaseSettings)); }
public void TestCreateWithEnabledAndFSyncAndWAndWTimeout() { var safeMode = new SafeMode(true, true, 2, TimeSpan.FromSeconds(30)); Assert.AreEqual(true, safeMode.Enabled); Assert.AreEqual(true, safeMode.FSync); Assert.AreEqual(false, safeMode.J); Assert.AreEqual(2, safeMode.W); Assert.AreEqual(null, safeMode.WMode); Assert.AreEqual(TimeSpan.FromSeconds(30), safeMode.WTimeout); }
public void TestCreateWithW() { var safeMode = new SafeMode(2); Assert.AreEqual(true, safeMode.Enabled); Assert.AreEqual(false, safeMode.FSync); Assert.AreEqual(false, safeMode.J); Assert.AreEqual(2, safeMode.W); Assert.AreEqual(null, safeMode.WMode); Assert.AreEqual(TimeSpan.Zero, safeMode.WTimeout); }
/// <summary> /// Freezes the settings. /// </summary> /// <returns>The frozen settings.</returns> public MongoCollectionSettings Freeze() { if (!isFrozen) { safeMode = safeMode.FrozenCopy(); frozenHashCode = GetHashCodeHelper(); frozenStringRepresentation = ToStringHelper(); isFrozen = true; } return(this); }
/// <summary> /// Freezes the settings. /// </summary> /// <returns>The frozen settings.</returns> public MongoCollectionSettings Freeze() { if (!_isFrozen) { _safeMode = _safeMode.FrozenCopy(); _frozenHashCode = GetHashCode(); _frozenStringRepresentation = ToString(); _isFrozen = true; } return(this); }
/// <summary> /// Freezes the settings. /// </summary> /// <returns>The frozen settings.</returns> public MongoDatabaseSettings Freeze() { if (!_isFrozen) { _safeMode = _safeMode.FrozenCopy(); _frozenHashCode = GetHashCodeHelper(); _frozenStringRepresentation = ToStringHelper(); _isFrozen = true; } return(this); }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, SafeMode safeMode, bool slaveOk ) { this.databaseName = databaseName; this.credentials = credentials; this.safeMode = safeMode; this.slaveOk = slaveOk; }
// constructors /// <summary> /// Initializes a new instance of the MongoCollectionSettings class. /// </summary> /// <param name="database">The database that contains the collection (some collection settings will be inherited from the database settings).</param> /// <param name="collectionName">The name of the collection.</param> /// <param name="defaultDocumentType">The default document type for the collection.</param> protected MongoCollectionSettings(MongoDatabase database, string collectionName, Type defaultDocumentType) { var databaseSettings = database.Settings; this.collectionName = collectionName; this.assignIdOnInsert = MongoDefaults.AssignIdOnInsert; this.defaultDocumentType = defaultDocumentType; this.guidRepresentation = databaseSettings.GuidRepresentation; this.safeMode = databaseSettings.SafeMode; this.slaveOk = databaseSettings.SlaveOk; }
/// <summary> /// Gets a MongoCollection instance representing a collection on this database /// with a default document type of TDefaultDocument. /// </summary> /// <typeparam name="TDefaultDocument">The default document type for this collection.</typeparam> /// <param name="collectionName">The name of the collection.</param> /// <param name="safeMode">The safe mode to use when accessing this collection.</param> /// <returns>An instance of MongoCollection.</returns> public virtual MongoCollection <TDefaultDocument> GetCollection <TDefaultDocument>( string collectionName, SafeMode safeMode) { var collectionSettings = new MongoCollectionSettings <TDefaultDocument>(this, collectionName) { SafeMode = safeMode }; return(GetCollection(collectionSettings)); }
/// <summary> /// Freezes the settings. /// </summary> /// <returns>The frozen settings.</returns> public MongoServerSettings Freeze() { if (!_isFrozen) { _credentialsStore.Freeze(); _safeMode = _safeMode.FrozenCopy(); _frozenHashCode = GetHashCode(); _frozenStringRepresentation = ToString(); _isFrozen = true; } return(this); }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, SafeMode safeMode, bool slaveOk ) { this.databaseName = databaseName; this.credentials = credentials; this.safeMode = safeMode; this.slaveOk = slaveOk; }
/// <summary> /// Gets a MongoDatabase instance representing a database on this server. Only one instance /// is created for each combination of database settings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="safeMode">The safe mode to use with this database.</param> /// <returns>A new or existing instance of MongoDatabase.</returns> public virtual MongoDatabase GetDatabase(string databaseName, SafeMode safeMode) { if (databaseName == null) { throw new ArgumentNullException("databaseName"); } var databaseSettings = new MongoDatabaseSettings(this, databaseName) { SafeMode = safeMode }; return(GetDatabase(databaseSettings)); }
protected MongoCollectionSettings( string collectionName, bool assignIdOnInsert, Type defaultDocumentType, SafeMode safeMode, bool slaveOk ) { this.collectionName = collectionName; this.assignIdOnInsert = assignIdOnInsert; this.defaultDocumentType = defaultDocumentType; this.safeMode = safeMode; this.slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _safeMode = safeMode; _slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk ) { this.databaseName = databaseName; this.credentials = credentials; this.guidRepresentation = guidRepresentation; this.safeMode = safeMode; this.slaveOk = slaveOk; }
public MongoUrl( string url ) { var builder = new MongoUrlBuilder(url); this.url = builder.ToString(); // keep canonical form this.credentials = builder.Credentials; this.servers = builder.Servers; this.databaseName = builder.DatabaseName; this.connectionMode = builder.ConnectionMode; this.replicaSetName = builder.ReplicaSetName; this.safeMode = builder.SafeMode ?? SafeMode.False; // never null this.slaveOk = builder.SlaveOk; }
/// <summary> /// Initializes a new instance of the MongoCollectionSettings class. /// </summary> /// <param name="collectionName">The name of the collection.</param> /// <param name="assignIdOnInsert">Whether to automatically assign a value to an empty document Id on insert.</param> /// <param name="defaultDocumentType">The default document type for the collection.</param> /// <param name="guidRepresentation">The GUID representation to use with this collection.</param> /// <param name="safeMode">The SafeMode to use with this collection.</param> /// <param name="slaveOk">Whether to route reads to secondaries for this collection.</param> protected MongoCollectionSettings( string collectionName, bool assignIdOnInsert, Type defaultDocumentType, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { _collectionName = collectionName; _assignIdOnInsert = assignIdOnInsert; _defaultDocumentType = defaultDocumentType; _guidRepresentation = guidRepresentation; _safeMode = safeMode; _slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { if (databaseName == "admin" && credentials != null && !credentials.Admin) { throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true."); } _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _safeMode = safeMode; _slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="databaseName">The name of the database.</param> /// <param name="credentials">The credentials to access the database.</param> /// <param name="guidRepresentation">The representation for Guids.</param> /// <param name="safeMode">The safe mode to use.</param> /// <param name="slaveOk">Whether queries should be sent to secondary servers.</param> public MongoDatabaseSettings( string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk) { if (databaseName == "admin" && credentials != null && !credentials.Admin) { throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true."); } _databaseName = databaseName; _credentials = credentials; _guidRepresentation = guidRepresentation; _safeMode = safeMode; _slaveOk = slaveOk; }
/// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { connectionMode = ConnectionMode.Direct; connectTimeout = MongoDefaults.ConnectTimeout; defaultCredentials = null; ipv6 = false; maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; replicaSetName = null; safeMode = MongoDefaults.SafeMode; servers = null; slaveOk = false; socketTimeout = MongoDefaults.SocketTimeout; waitQueueSize = MongoDefaults.ComputedWaitQueueSize; waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
/// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { connectionMode = ConnectionMode.Direct; connectTimeout = MongoDefaults.ConnectTimeout; defaultCredentials = null; ipv6 = false; maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; replicaSetName = null; safeMode = MongoDefaults.SafeMode; servers = null; slaveOk = false; socketTimeout = MongoDefaults.SocketTimeout; waitQueueSize = MongoDefaults.ComputedWaitQueueSize; waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
// constructors /// <summary> /// Creates a new instance of MongoDatabaseSettings. /// </summary> /// <param name="server">The server to inherit settings from.</param> /// <param name="databaseName">The name of the database.</param> public MongoDatabaseSettings(MongoServer server, string databaseName) { if (server == null) { throw new ArgumentNullException("server"); } if (databaseName == null) { throw new ArgumentNullException("databaseName"); } var serverSettings = server.Settings; _databaseName = databaseName; _credentials = serverSettings.GetCredentials(databaseName); _guidRepresentation = serverSettings.GuidRepresentation; _readPreference = serverSettings.ReadPreference; _safeMode = serverSettings.SafeMode; }
public void SetData(string IdSession, string data, DateTime lastAccess) { MongoServer conn = GetConnection(); MongoCollection sessionCollection = GetSessionCollection(conn); BsonDocument insertDoc = null; SafeMode _safeMode = new SafeMode(false); string sessItems = data; var ApplicationName = "IOL"; Double timeout = this.GetTimeoutSet(); object lockId = new object(); try { if (!this.Exist(conn, IdSession, sessionCollection)) { insertDoc = new BsonDocument(); insertDoc.Add("_id", IdSession); insertDoc.Add("ApplicationName", ApplicationName); insertDoc.Add("Created", DateTime.Now.ToUniversalTime()); insertDoc.Add("Expires", DateTime.Now.AddMinutes((Double)timeout).ToUniversalTime()); insertDoc.Add("SessionItems", sessItems); var query = Query.And(Query.EQ("_id", IdSession), Query.EQ("ApplicationName", ApplicationName), Query.LT("Expires", DateTime.Now.ToUniversalTime())); sessionCollection.Remove(query, _safeMode); sessionCollection.Insert(insertDoc, _safeMode); } else { var query = Query.And(Query.EQ("_id", IdSession), Query.EQ("ApplicationName", ApplicationName)); var update = Update.Set("Expires", DateTime.Now.AddMinutes((Double)timeout).ToUniversalTime()); update.Set("SessionItems", sessItems); sessionCollection.Update(query, update, _safeMode); } } catch (Exception e) { } finally { conn.Disconnect(); } }
// constructors /// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { _connectionMode = ConnectionMode.Direct; _connectTimeout = MongoDefaults.ConnectTimeout; _defaultCredentials = null; _guidRepresentation = MongoDefaults.GuidRepresentation; _ipv6 = false; _maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; _replicaSetName = null; _safeMode = MongoDefaults.SafeMode; _servers = null; _slaveOk = false; _socketTimeout = MongoDefaults.SocketTimeout; _waitQueueSize = MongoDefaults.ComputedWaitQueueSize; _waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
// constructors /// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { connectionMode = ConnectionMode.Direct; connectTimeout = MongoDefaults.ConnectTimeout; defaultCredentials = null; guidRepresentation = MongoDefaults.GuidRepresentation; ipv6 = false; maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; replicaSetName = null; safeMode = MongoDefaults.SafeMode; servers = null; //slaveOk = false; readPreference = ReadPreference.Primary; socketTimeout = MongoDefaults.SocketTimeout; waitQueueSize = MongoDefaults.ComputedWaitQueueSize; waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
// constructors /// <summary> /// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead. /// </summary> public MongoServerSettings() { _connectionMode = ConnectionMode.Direct; _connectTimeout = MongoDefaults.ConnectTimeout; _credentialsStore = new MongoCredentialsStore(); _defaultCredentials = null; _guidRepresentation = MongoDefaults.GuidRepresentation; _ipv6 = false; _maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; _maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; _maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; _minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; _readPreference = ReadPreference.Primary; _replicaSetName = null; _safeMode = MongoDefaults.SafeMode; _servers = new List<MongoServerAddress> { new MongoServerAddress("localhost") }; _serversReadOnly = new ReadOnlyCollection<MongoServerAddress>(_servers); _socketTimeout = MongoDefaults.SocketTimeout; _waitQueueSize = MongoDefaults.ComputedWaitQueueSize; _waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
public MongoDBEventStore( MongoServer mongoServer, SafeMode safeMode, string databaseName = "EventsStore", string collectionName="Commits" ) { Contract.Requires<ArgumentNullException>(mongoServer != null); Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(databaseName)); Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(collectionName)); _mongoServer = mongoServer; _databaseName = databaseName; _collectionName = collectionName; _safeMode = safeMode; // Both operations can take a while Task.WaitAll( Task.Factory.StartNew(()=>SetupStore(mongoServer, databaseName, collectionName)), Task.Factory.StartNew(SetupClassMap) ); }
/// <summary> /// Freezes the settings. /// </summary> /// <returns>The frozen settings.</returns> public MongoDatabaseSettings Freeze() { if (!_isFrozen) { _safeMode = _safeMode.FrozenCopy(); _frozenHashCode = GetHashCodeHelper(); _frozenStringRepresentation = ToStringHelper(); _isFrozen = true; } return this; }
private void ResetValues() { connectionMode = ConnectionMode.Direct; connectTimeout = MongoDefaults.ConnectTimeout; databaseName = null; defaultCredentials = null; ipv6 = false; maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime; maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime; maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize; minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize; replicaSetName = null; safeMode = null; servers = null; slaveOk = false; socketTimeout = MongoDefaults.SocketTimeout; waitQueueMultiple = MongoDefaults.WaitQueueMultiple; waitQueueSize = MongoDefaults.WaitQueueSize; waitQueueTimeout = MongoDefaults.WaitQueueTimeout; }
/// <summary> /// Parses a URL and sets all settings to match the URL. /// </summary> /// <param name="url">The URL.</param> public void Parse( string url ) { ResetValues(); const string pattern = @"^mongodb://" + @"((?<username>[^:]+):(?<password>[^@]+)@)?" + @"(?<servers>[^:,/]+(:\d+)?(,[^:,/]+(:\d+)?)*)" + @"(/(?<database>[^?]+)?(\?(?<query>.*))?)?$"; Match match = Regex.Match(url, pattern); if (match.Success) { string username = Uri.UnescapeDataString(match.Groups["username"].Value); string password = Uri.UnescapeDataString(match.Groups["password"].Value); string servers = match.Groups["servers"].Value; string databaseName = match.Groups["database"].Value; string query = match.Groups["query"].Value; if (username != "" && password != "") { this.defaultCredentials = new MongoCredentials(username, password); } else { this.defaultCredentials = null; } if (servers != "") { List<MongoServerAddress> addresses = new List<MongoServerAddress>(); foreach (string server in servers.Split(',')) { var address = MongoServerAddress.Parse(server); addresses.Add(address); } if (addresses.Count == 1) { this.connectionMode = ConnectionMode.Direct; } else if (addresses.Count > 1) { this.connectionMode = ConnectionMode.ReplicaSet; } this.servers = addresses; } else { throw new FormatException("Invalid connection string: server missing"); } this.databaseName = (databaseName != "") ? databaseName : null; if (!string.IsNullOrEmpty(query)) { var safeModeChanged = false; var safe = false; var w = 0; var wtimeout = TimeSpan.Zero; var fsync = false; foreach (var pair in query.Split('&', ';')) { var parts = pair.Split('='); if (parts.Length != 2) { throw new FormatException(string.Format("Invalid connection string: {0}", parts)); } var name = parts[0]; var value = parts[1]; switch (name.ToLower()) { case "connect": connectionMode = ParseConnectionMode(name, value); break; case "connecttimeout": case "connecttimeoutms": connectTimeout = ParseTimeSpan(name, value); break; case "fsync": safeModeChanged = true; safe = true; fsync = ParseBoolean(name, value); break; case "ipv6": ipv6 = ParseBoolean(name, value); break; case "maxidletime": case "maxidletimems": maxConnectionIdleTime = ParseTimeSpan(name, value); break; case "maxlifetime": case "maxlifetimems": maxConnectionLifeTime = ParseTimeSpan(name, value); break; case "maxpoolsize": maxConnectionPoolSize = ParseInt32(name, value); break; case "minpoolsize": minConnectionPoolSize = ParseInt32(name, value); break; case "replicaset": this.replicaSetName = value; this.connectionMode = ConnectionMode.ReplicaSet; break; case "safe": safeModeChanged = true; safe = ParseBoolean(name, value); break; case "slaveok": slaveOk = ParseBoolean(name, value); break; case "sockettimeout": case "sockettimeoutms": socketTimeout = ParseTimeSpan(name, value); break; case "w": safeModeChanged = true; safe = true; w = ParseInt32(name, value); break; case "waitqueuemultiple": waitQueueMultiple = ParseDouble(name, value); waitQueueSize = 0; break; case "waitqueuesize": waitQueueMultiple = 0; waitQueueSize = ParseInt32(name, value); break; case "waitqueuetimeout": case "waitqueuetimeoutms": waitQueueTimeout = ParseTimeSpan(name, value); break; case "wtimeout": case "wtimeoutms": safeModeChanged = true; safe = true; wtimeout = ParseTimeSpan(name, value); break; } } if (safeModeChanged) { this.safeMode = SafeMode.Create(safe, fsync, w, wtimeout); } } } else { throw new FormatException(string.Format("Invalid connection string: {0}", url)); } }
public void TestEquals() { var a1 = new SafeMode(false); var a2 = new SafeMode(true) { Enabled = false }; var a3 = a2; var b = new SafeMode(false) { Enabled = true }; var c = new SafeMode(false) { FSync = true }; var d = new SafeMode(false) { J = true }; var e = new SafeMode(false) { W = 2 }; var f = new SafeMode(false) { WMode = "mode" }; var g = new SafeMode(false) { WTimeout = TimeSpan.FromMinutes(1) }; var null1 = (SafeMode)null; var null2 = (SafeMode)null; Assert.AreNotSame(a1, a2); Assert.AreSame(a2, a3); Assert.IsTrue(a1.Equals((object)a2)); Assert.IsFalse(a1.Equals((object)null)); Assert.IsFalse(a1.Equals((object)"x")); Assert.IsTrue(a1 == a2); Assert.IsTrue(a2 == a3); Assert.IsFalse(a1 == b); Assert.IsFalse(a1 == c); Assert.IsFalse(a1 == d); Assert.IsFalse(a1 == e); Assert.IsFalse(a1 == f); Assert.IsFalse(a1 == g); Assert.IsFalse(a1 == null1); Assert.IsFalse(null1 == a1); Assert.IsTrue(null1 == null2); Assert.IsFalse(a1 != a2); Assert.IsFalse(a2 != a3); Assert.IsTrue(a1 != b); Assert.IsTrue(a1 != c); Assert.IsTrue(a1 != d); Assert.IsTrue(a1 != e); Assert.IsTrue(a1 != f); Assert.IsTrue(a1 != g); Assert.IsTrue(a1 != null1); Assert.IsTrue(null1 != a1); Assert.IsFalse(null1 != null2); var hash = a1.GetHashCode(); Assert.AreEqual(hash, a2.GetHashCode()); // check that all tests still pass after objects are Frozen a1.Freeze(); a2.Freeze(); a3.Freeze(); b.Freeze(); c.Freeze(); d.Freeze(); e.Freeze(); f.Freeze(); g.Freeze(); Assert.AreNotSame(a1, a2); Assert.AreSame(a2, a3); Assert.IsTrue(a1.Equals((object)a2)); Assert.IsFalse(a1.Equals((object)null)); Assert.IsFalse(a1.Equals((object)"x")); Assert.IsTrue(a1 == a2); Assert.IsTrue(a2 == a3); Assert.IsFalse(a1 == b); Assert.IsFalse(a1 == c); Assert.IsFalse(a1 == d); Assert.IsFalse(a1 == e); Assert.IsFalse(a1 == f); Assert.IsFalse(a1 == g); Assert.IsFalse(a1 == null1); Assert.IsFalse(null1 == a1); Assert.IsTrue(null1 == null2); Assert.IsFalse(a1 != a2); Assert.IsFalse(a2 != a3); Assert.IsTrue(a1 != b); Assert.IsTrue(a1 != c); Assert.IsTrue(a1 != d); Assert.IsTrue(a1 != e); Assert.IsTrue(a1 != f); Assert.IsTrue(a1 != g); Assert.IsTrue(a1 != null1); Assert.IsTrue(null1 != a1); Assert.IsFalse(null1 != null2); Assert.AreEqual(hash, a1.GetHashCode()); Assert.AreEqual(hash, a2.GetHashCode()); }