Provides universal configuration for supported database platforms. Use properties dictionary for platform specific options.
        private static DatabaseConfiguration ParseConfiguration(dynamic config, IApplication application)
        {
            var database = new DatabaseConfiguration();
            database.Platform = EnumHelper.Parse(config.Platform, DatabasePlatform.SqlServer);
            database.Host = config.Host ?? String.Empty;
            database.Database = config.Database ?? String.Empty;
            database.Username = config.Username ?? String.Empty;
            database.Password = config.Password ?? String.Empty;

            if (config.Properties != null)
            {
                foreach (var property in config.Properties)
                {
                    if (property.Value is String)
                    {
                        database.Properties[property.Key] = property.Value;
                    }
                }
            }

            if (DatabasePlatform.SQLite.Equals(database.Platform) && !DatabaseConfiguration.InMemoryDatabase.Equals(database.Database))
            {
                database.Database = Path.Combine(application.RootPath, database.Database);
            }

            return database;
        }
 /// <summary>
 /// Fills specified database configuration.
 /// </summary>
 /// <param name="application">The application.</param>
 /// <param name="kernel">The kernel.</param>
 public void Configure(IApplication application, IKernel kernel)
 {
     dynamic databases = YamlDocument.FromFile(configPath);
     String currentEnvironment = ConfigurationManager.AppSettings[Constants.Environment];
     foreach (var database in databases)
     {
         application.DatabaseConfiguration[database.Key] = ParseConfiguration(database.Value, application);
         if (currentEnvironment!=null && currentEnvironment.Equals(database.Key))
         {
             databaseConfiguration = application.DatabaseConfiguration[database.Key];
         }
     }
 }
        private Configuration BuildConfig(DatabaseConfiguration databaseConfiguration)
        {
            var fluenty = Fluently.Configure()
                            .Database(GetDatabase(databaseConfiguration))
                            .Mappings(m =>
                                        {
                                            foreach (var mapper in kernel.ResolveAll<INHibernateMapper>())
                                            {
                                                mapper.Map(m, databaseConfiguration);
                                            }
                                            m.FluentMappings.Add(typeof(CultureFilter)).Conventions.Setup(x => x.Add(AutoImport.Never()));
                                        });

            return fluenty.ExposeConfiguration(ProcessConfiguration).BuildConfiguration().AddProperties(GetNHibernateProperties(databaseConfiguration));
        }
 private Dictionary<String, String> GetNHibernateProperties(DatabaseConfiguration databaseConfiguration)
 {
     var nhibernateProperties = new Dictionary<String, String>();
     foreach (var property in databaseConfiguration.Properties)
     {
         if (nhibernatePropertyPattern.IsMatch(property.Key))
         {
             var key = nhibernatePropertyPattern.Replace(property.Key, String.Empty);
             nhibernateProperties[key] = property.Value;
         }
     }
     return nhibernateProperties;
 }
 private IPersistenceConfigurer GetDatabase(DatabaseConfiguration databaseConfiguration)
 {
     switch (databaseConfiguration.Platform)
     {
         case DatabasePlatform.SqlServer:
             return MsSqlConfiguration.MsSql2008.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.SqlServer2000:
             return MsSqlConfiguration.MsSql2000.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.SqlServer2005:
             return MsSqlConfiguration.MsSql2005.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.SQLite:
             return SQLiteConfiguration.Standard.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.MySQL:
             return MySQLConfiguration.Standard.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.PostgreSQL:
             return PostgreSQLConfiguration.Standard.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.Oracle9:
             return OracleClientConfiguration.Oracle9.ConnectionString(databaseConfiguration.GetConnectionString());
         case DatabasePlatform.Oracle10:
             return OracleClientConfiguration.Oracle9.ConnectionString(databaseConfiguration.GetConnectionString());
         default:
             throw new ConfigurationErrorsException(String.Format("{0} platform is not supported by nhibernate facility.", databaseConfiguration.Platform));
     }
 }
        private Configuration BuildConfig(DatabaseConfiguration databaseConfiguration, IConfiguration config)
        {
            string fileName = config.Attributes["fileName"];

            Configuration cfg;
            if (IsNewConfigurationRequired(fileName))
            {
                using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    var fluenty = Fluently.Configure()
                        .Database(GetDatabase(databaseConfiguration))
                        .Mappings(m =>
                        {
                            foreach (var mapper in kernel.ResolveAll<INHibernateMapper>())
                            {
                                mapper.Map(m, databaseConfiguration);
                            }
                            m.FluentMappings.Add(typeof(CultureFilter));
                        });

                    cfg = fluenty.ExposeConfiguration(ProcessConfiguration).BuildConfiguration().AddProperties(GetNHibernateProperties(databaseConfiguration));
                    WriteConfigurationToStream(fileStream, cfg);
                }
            }
            else
            {
                using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    cfg = GetConfigurationFromStream(fileStream);
                }
            }
            return cfg;
        }
 /// <summary>
 /// Adds mappings to session configuration.
 /// </summary>
 /// <param name="mapping">The mapping configuration.</param>
 /// <param name="databaseConfiguration">The database configuration.</param>
 public virtual void Map(MappingConfiguration mapping, DatabaseConfiguration databaseConfiguration)
 {
     mapping.FluentMappings.AddFromAssembly(Assembly).Conventions.Add(Conventions.ToArray());
 }