Exemplo n.º 1
0
        /// <summary>
        /// Wireup of the sql server repository
        /// </summary>
        /// <param name="wireup"></param>
        /// <returns></returns>
        private Wireup WireupSqlServerRepository(Wireup wireup)
        {
            // we need to make sure the database exists and also pull the db name out of the connection string
            var connectionString         = new ConfigurationConnectionFactory("EventStore_SqlServer").Settings.ConnectionString;
            var databaseNameRegex        = @"(Initial Catalog=.*$)|(Initial Catalog=.*[;])";
            var connectionStringModified = Regex.Replace(connectionString, databaseNameRegex, "Initial Catalog=master");
            var databaseName             = Regex.Match(connectionString, databaseNameRegex).Captures[0].Value.Replace("Initial Catalog=", string.Empty);

            bool exists = false;

            using (var sqlConnection = new SqlConnection(connectionStringModified))
            {
                var sqlCreateDBQuery = string.Format("SELECT database_id FROM sys.databases WHERE Name = '{0}'", databaseName);
                using (var sqlCmd = new SqlCommand(sqlCreateDBQuery, sqlConnection))
                {
                    sqlConnection.Open();
                    var dbId = sqlCmd.ExecuteScalar();
                    exists = (dbId != null) && (Convert.ToInt32(dbId) > 0);
                    sqlConnection.Close();
                }
            }

            if (!exists)
            {
                using (var sqlConnection = new SqlConnection(connectionStringModified))
                {
                    var sqlCreateDBQuery = string.Format("CREATE DATABASE {0}", databaseName);
                    using (var sqlCmd = new SqlCommand(sqlCreateDBQuery, sqlConnection))
                    {
                        sqlConnection.Open();
                        sqlCmd.ExecuteScalar();
                        sqlConnection.Close();
                    }
                }
            }

            return(wireup
                   .UsingSqlPersistence("EventStore_SqlServer")
                   .WithDialect(new MsSqlDialect())
                   .InitializeStorageEngine()
                   .UsingBsonSerialization());
        }
Exemplo n.º 2
0
        public static SqlPersistenceWireup UsingSqlAzurePersistence(this Wireup wireup, string connectionName)
        {
            var factory = new AzureConfigurationConnectionFactory(connectionName);

            return(wireup.UsingSqlPersistence(factory));
        }
Exemplo n.º 3
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup
         .UsingSqlPersistence("SqlServer")
         .WithDialect(new MsSqlDialect());
 }
Exemplo n.º 4
0
 protected override PersistenceWireup ConfigurePersistence(Wireup wireup)
 {
     return wireup
         .UsingSqlPersistence("PostgreSql")
         .WithDialect(new PostgreSqlDialect());
 }
        public static SqlPersistenceWireup UsingSqlPersistence(this Wireup wireup, string connectionName, string connectionString)
        {
            var factory = new DirectConnectionFactory(connectionName, connectionString);

            return(wireup.UsingSqlPersistence(factory));
        }
Exemplo n.º 6
0
 private static PersistenceWireup ConfigureSql(Wireup wireup)
 {
     return(wireup
            .UsingSqlPersistence("SqlServer")
            .WithDialect(new MsSqlDialect()));
 }