/// <summary> /// Configures Rebus to use SQL Server to store sagas, using the tables specified to store data and indexed properties respectively. /// </summary> public static void StoreInSqlServer(this StandardConfigurer <ISagaStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string dataTableName, string indexTableName, bool automaticallyCreateTables = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (dataTableName == null) { throw new ArgumentNullException(nameof(dataTableName)); } if (indexTableName == null) { throw new ArgumentNullException(nameof(indexTableName)); } configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory, rebusLoggerFactory); var sagaStorage = new SqlServerSagaStorage(connectionProvider, dataTableName, indexTableName, rebusLoggerFactory); if (automaticallyCreateTables) { sagaStorage.EnsureTablesAreCreated(); } return(sagaStorage); }); }
/// <summary> /// Configures the data bus to store data in a central MySQL /// </summary> public static void StoreInMySql(this StandardConfigurer <IDataBusStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string tableName, bool automaticallyCreateTables = true, int commandTimeout = 240) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } configurer.OtherService <MySqlDataBusStorage>().Register(c => { var rebusTime = c.Get <IRebusTime>(); var loggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory); return(new MySqlDataBusStorage(connectionProvider, tableName, automaticallyCreateTables, loggerFactory, rebusTime, commandTimeout)); }); configurer.Register(c => c.Get <MySqlDataBusStorage>()); configurer.OtherService <IDataBusStorageManagement>().Register(c => c.Get <MySqlDataBusStorage>()); }
/// <summary> /// Configures Rebus to use SQL Server to store subscriptions. Use <paramref name="isCentralized"/> = true to indicate whether it's OK to short-circuit /// subscribing and unsubscribing by manipulating the subscription directly from the subscriber or just let it default to false to preserve the /// default behavior. /// </summary> public static void StoreInSqlServer(this StandardConfigurer <ISubscriptionStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string tableName, bool isCentralized = false, bool automaticallyCreateTables = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory); var subscriptionStorage = new SqlServerSubscriptionStorage(connectionProvider, tableName, isCentralized, rebusLoggerFactory); if (automaticallyCreateTables) { subscriptionStorage.EnsureTableIsCreated(); } return(subscriptionStorage); }); }
/// <summary> /// Defines the method to be called when the command is invoked. /// </summary> /// <param name="parameter">The connection parameter.</param> public void Execute(object parameter) { DbConnectionParameter connectionParameter = (DbConnectionParameter)parameter; IWrappedDbConnectionFactory connectionFactory = DbConnectionFactoryProvider.GetFactory(connectionParameter.Provider); WrappedDbConnection dbConnection = null; bool succeeded = false; try { dbConnection = connectionFactory.CreateConnection(connectionParameter); succeeded = true; } catch (WrappedDbException) { } finally { if (dbConnection != null) { dbConnection.Dispose(); } } if (succeeded) { MessageBox.Show("Connection succeeded", "Connection Test", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Connection failed", "Connection Test", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Configures Rebus to store saga snapshots in MySQL /// </summary> public static void StoreInMySql(this StandardConfigurer <ISagaSnapshotStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string tableName, bool automaticallyCreateTables = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory); var snapshotStorage = new MySqlSagaSnapshotStorage(connectionProvider, tableName, rebusLoggerFactory); if (automaticallyCreateTables) { snapshotStorage.EnsureTableIsCreated(); } return(snapshotStorage); }); }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionProcessor"/> class. /// </summary> /// <param name="cmdArgs">The CMD args.</param> public ExecutionProcessor(CSqlOptions csqlOptions) { this.options = csqlOptions; DbConnectionParameter connectionParameter = csqlOptions.ConnectionParameter; this.connection = DbConnectionFactoryProvider.CreateConnection(connectionParameter); this.connection.InfoMessage += new EventHandler <DbMessageEventArgs>(InfoMessageEventHandler); }
public void Call_Unavailable_Db_Connection_Factory() { var dbConnectionName = new DbConnectionName("name"); var callDbConnName = new DbConnectionName("SomeName"); var provider = new DbConnectionFactoryProvider(); var mockFactory = new Mock <IDbConnectionFactory>(); provider.Add(dbConnectionName, mockFactory.Object); Should.Throw <DbConnectionFactoryProviderException>(() => provider.Create(callDbConnName)); }
public void Register_Db_Connection_Factory_And_Find() { var dbConnectionName = new DbConnectionName("name"); var provider = new DbConnectionFactoryProvider(); var mockFactory = new Mock <IDbConnectionFactory>(); mockFactory.Verify(tt => tt.Create(null), Times.AtMost(1)); provider.Add(dbConnectionName, mockFactory.Object); provider.Create(dbConnectionName).Create(null); mockFactory.VerifyAll(); }
/// <summary> /// Stores the current database connection parameter in the global variables /// of the visual studio environment. /// </summary> /// <param name="dbConnectionParameter">The database connection parameter.</param> internal void SaveDbConnectionParameterInGlobals(DbConnectionParameter dbConnectionParameter) { IWrappedDbConnectionFactory factory = DbConnectionFactoryProvider.GetFactory(dbConnectionParameter.Provider); string providerName = factory.ProviderName; string connectionString = factory.GetConnectionString(dbConnectionParameter); Globals globals = application.Globals; string variableName = CSqlConnectionFactory.CSqlConnectionProviderVariableName; globals[variableName] = providerName; globals.set_VariablePersists(variableName, true); variableName = CSqlConnectionFactory.CSqlConnectionStringVariableName; globals[variableName] = connectionString; globals.set_VariablePersists(variableName, true); }
/// <summary> /// Configures the data bus to store data in a central SQL Server /// </summary> public static void StoreInSqlServer(this StandardConfigurer <IDataBusStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string tableName, bool automaticallyCreateTables = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } configurer.Register(c => { var loggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory, loggerFactory); return(new SqlServerDataBusStorage(connectionProvider, tableName, automaticallyCreateTables, loggerFactory)); }); }
/// <summary> /// Configures Rebus to use MySQL to store sagas, using the tables specified to store data and indexed properties respectively. /// </summary> public static void StoreInMySql(this StandardConfigurer <ISagaStorage> configurer, Func <Task <IDbConnection> > connectionFactory, string dataTableName, string indexTableName, bool automaticallyCreateTables = true) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (connectionFactory == null) { throw new ArgumentNullException(nameof(connectionFactory)); } if (dataTableName == null) { throw new ArgumentNullException(nameof(dataTableName)); } if (indexTableName == null) { throw new ArgumentNullException(nameof(indexTableName)); } configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var connectionProvider = new DbConnectionFactoryProvider(connectionFactory); var sagaTypeNamingStrategy = GetSagaTypeNamingStrategy(c, rebusLoggerFactory); var serializer = c.Has <ISagaSerializer>(false) ? c.Get <ISagaSerializer>() : new DefaultSagaSerializer(); var sagaStorage = new MySqlSagaStorage(connectionProvider, dataTableName, indexTableName, rebusLoggerFactory, sagaTypeNamingStrategy, serializer); if (automaticallyCreateTables) { sagaStorage.EnsureTablesAreCreated(); } return(sagaStorage); }); }