/// <summary> /// Adds the connection. /// </summary> /// <param name="key">The key.</param> /// <param name="mongoSettings">The mongo settings.</param> public void AddConnection(string key, MongoSettingsExtended mongoSettings) { bool lockTaken = false; _spinLock.Enter(ref lockTaken); if (lockTaken) { if (!_mongoHelpers.ContainsKey(key)) _mongoHelpers.Add(key, new MongoHelper(mongoSettings) { Logger = LogManager.GetLogger(GetType())}); _spinLock.Exit(); } }
/// <summary> /// Creates the specified connection name. /// </summary> /// <param name="mongoSettings">The mongo settings.</param> /// <param name="collection">The collection.</param> /// <returns></returns> public static ISubscriptorsPersister Create(MongoSettingsExtended mongoSettings, string collection) { try { MongoHelperProvider.Instance.AddConnection("SubscriptorsEntities", mongoSettings); var repository = new Repository<SubscriptorEntity, ObjectId>("SubscriptorsEntities", collection); return new MongoSubscriptorsPersister(repository); } catch (Exception ex) { LoggerManager.Instance.Error("Error Create Mongo Subscriptor Persister", ex); throw; } }
/// <summary> /// Adds the connection. /// </summary> /// <param name="key">The key.</param> /// <param name="mongoSettings">The mongo settings.</param> public void AddConnection(string key, MongoSettingsExtended mongoSettings) { bool lockTaken = false; _spinLock.Enter(ref lockTaken); if (lockTaken) { if (!_mongoHelpers.ContainsKey(key)) { _mongoHelpers.Add(key, new MongoHelper(mongoSettings) { Logger = LogManager.GetLogger(GetType()) }); } _spinLock.Exit(); } }
private void CreateExtendedHelpers(MongoFullConfig mongoDbConfig) { foreach (ConnectionExtendedConfig connection in mongoDbConfig.Connections) { var settings = new MongoSettingsExtended { ConnectionMode = connection.ConnectionMode, ConnectTimeout = connection.ConnectTimeout, MaxConnectionIdleTime = connection.MaxConnectionIdleTime, MaxConnectionLifeTime = connection.MaxConnectionLifeTime, MaxConnectionPoolSize = connection.MaxConnectionPoolSize, MinConnectionPoolSize = connection.MinConnectionPoolSize, ReplicaSetName = connection.ReplicaSetName, SlaveOk = connection.SlaveOk, SocketTimeout = connection.SocketTimeout, WaitQueueSize = connection.WaitQueueSize, WaitQueueTimeout = connection.WaitQueueTimeout, Database = connection.Database, ReadPreferenceMode = connection.ReadPreferenceMode }; foreach (ServerConnection server in connection.Servers) { settings.AddServer(server.Server, server.Port); } if (!string.IsNullOrEmpty(connection.DefaultCredentials.User)) { settings.AddCredentials(connection.DefaultCredentials.User, connection.DefaultCredentials.Password, connection.DefaultCredentials.Admin); } _mongoHelpers.Add(connection.Name, new MongoHelper(settings) { Logger = LogManager.GetLogger(GetType()) }); } }
private void CreateExtendedHelpers(MongoFullConfig mongoDbConfig) { foreach (ConnectionExtendedConfig connection in mongoDbConfig.Connections) { var settings = new MongoSettingsExtended { ConnectionMode = connection.ConnectionMode, ConnectTimeout = connection.ConnectTimeout, MaxConnectionIdleTime = connection.MaxConnectionIdleTime, MaxConnectionLifeTime = connection.MaxConnectionLifeTime, MaxConnectionPoolSize = connection.MaxConnectionPoolSize, MinConnectionPoolSize = connection.MinConnectionPoolSize, ReplicaSetName = connection.ReplicaSetName, SlaveOk = connection.SlaveOk, SocketTimeout = connection.SocketTimeout, WaitQueueSize = connection.WaitQueueSize, WaitQueueTimeout = connection.WaitQueueTimeout, Database = connection.Database, ReadPreferenceMode = connection.ReadPreferenceMode }; foreach (ServerConnection server in connection.Servers) { settings.AddServer(server.Server, server.Port); } if(!string.IsNullOrEmpty(connection.DefaultCredentials.User) ) { settings.AddCredentials(connection.DefaultCredentials.User, connection.DefaultCredentials.Password, connection.DefaultCredentials.Admin); } _mongoHelpers.Add(connection.Name, new MongoHelper(settings) { Logger = LogManager.GetLogger(GetType()) }); } }
/// <summary> /// Loads the persisters. /// </summary> /// <returns></returns> private RouterControlConfigurator LoadPersisters() { _subscriptorsPersiter = new NullSubscriptorPersister(); MongoPersiterConfig mongoPersister = _hermEsbConfig.RouterControlProcessor.Persister.MongoPersister; if (mongoPersister.Connection.Servers.Count > 0) { //Cargamos la configuracion de mongo var settings = new MongoSettingsExtended { ConnectionMode = mongoPersister.Connection.ConnectionMode, ConnectTimeout = mongoPersister.Connection.ConnectTimeout, MaxConnectionIdleTime = mongoPersister.Connection.MaxConnectionIdleTime, MaxConnectionLifeTime = mongoPersister.Connection.MaxConnectionLifeTime, MaxConnectionPoolSize = mongoPersister.Connection.MaxConnectionPoolSize, MinConnectionPoolSize = mongoPersister.Connection.MinConnectionPoolSize, ReplicaSetName = mongoPersister.Connection.ReplicaSetName, SlaveOk = mongoPersister.Connection.SlaveOk, SocketTimeout = mongoPersister.Connection.SocketTimeout, WaitQueueSize = mongoPersister.Connection.WaitQueueSize, WaitQueueTimeout = mongoPersister.Connection.WaitQueueTimeout, Database = mongoPersister.Connection.Database }; foreach (ServerConnection server in mongoPersister.Connection.Servers) { settings.AddServer(server.Server, server.Port); } _subscriptorsPersiter = MongoSubscriptorsPersisterFactory.Create(settings, mongoPersister.Collection); } return this; }