public void NHibernateBootstrapper_Configure_Application() { //Arrange //create a new web.config file in /plugins for the providers to write to var http = new FakeHttpContextFactory("~/test"); var configFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "nhibernate.config")); var configMgr = new DeepConfigManager(http.HttpContext); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); var installModel = new DatabaseInstallModel() { DatabaseType = DatabaseServerType.MSSQL, DatabaseName = "test", Server = "testserver", Username = "******", Password = "******" }; var boot = new ProviderBootstrapper(null, null, new FakeFrameworkContext()); //Act boot.ConfigureApplication("rw-test", "test", configXml, new BendyObject(installModel)); //Assert Assert.AreEqual(@"<configuration> <configSections> <sectionGroup name=""rebel""> <sectionGroup name=""persistenceProviderSettings""> <section name=""test"" type=""Rebel.Framework.Persistence.NHibernate.Config.ProviderConfigurationSection, Rebel.Framework.Persistence.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" /> </sectionGroup> </sectionGroup> </configSections> <connectionStrings> <add name=""test.ConnString"" connectionString=""Data Source=testserver; Initial Catalog=test;User Id=testuser;Password=testpass"" providerName=""System.Data.SqlClient"" /> </connectionStrings> <appSettings /> <rebel> <persistenceProviderSettings> <test connectionStringKey=""test.ConnString"" sessionContext=""web"" driver=""MsSql2008"" /> </persistenceProviderSettings> </rebel> </configuration>", configXml.ToString()); }
public ActionResult DatabaseForm(DatabaseInstallModel model) { if (!ModelState.IsValid) { return View(model); } //create a new web.config file in /plugins for the providers to write to var configFile = new FileInfo( Path.Combine(HttpContext.Server.MapPath("~/App_Data/Rebel/HiveConfig"), "web.config")); Directory.CreateDirectory(configFile.Directory.FullName); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); //for each hive provider, get them to serialize their config to our xml file foreach (var hive in _requestContext.Application.Hive.GetAllReadWriteProviders()) { var installStatus = hive.Bootstrapper.GetInstallStatus(); //even if it's not completed, then overwrite if (installStatus.StatusType == InstallStatusType.RequiresConfiguration || installStatus.StatusType == InstallStatusType.Pending || installStatus.StatusType == InstallStatusType.TriedAndFailed) { //TODO: This will currently only work for the nhibernate provider since we're just passing in the DatabaseInstallmodel as the install params hive.Bootstrapper.ConfigureApplication(hive.ProviderMetadata.Alias, configXml, new BendyObject(model)); } } // Test connection strings if (model.DatabaseType != DatabaseServerType.SQLCE) { // We don't test SQL CE connection string as we will just create the DB if it doesn't exist try { foreach ( var connStringElement in configXml.Element("configuration").Element("connectionStrings").Descendants("add")) { var connString = connStringElement.Attribute("connectionString").Value; var providerName = connStringElement.Attribute("providerName").Value; var factory = DbProviderFactories.GetFactory(providerName); using (var conn = factory.CreateConnection()) { conn.ConnectionString = connString; conn.Open(); if (model.DatabaseType == DatabaseServerType.Custom || model.DatabaseType == DatabaseServerType.MSSQL) { var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT SERVERPROPERTY('productversion')"; var reader = cmd.ExecuteReader(); while(reader.Read()) { var versionString = reader[0].ToString(); var version = Convert.ToInt32(versionString.Replace(".", "").PadRight(10, '0')); if(version < 1000160000) // SQL 2008 RTM { throw new ApplicationException(string.Format("Unsupported version of SQL Server. SQL 2008 RTM (10.00.1600) or greater is required, but found {0}.", versionString)); } } } } } } catch (global::System.Exception ex) { ModelState.AddModelError("", "An error occured while testing connection string: " + ex.Message); return View(model); } } //now save the new config file configXml.Save(configFile.FullName); return RedirectToAction("DatabaseInstall"); }
public void NHibernateBootstrapper_Configure_Application() { //Arrange //create a new web.config file in /plugins for the providers to write to var http = new FakeHttpContextFactory("~/test"); var configFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, "nhibernate.config")); var configMgr = new DeepConfigManager(http.HttpContext); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); var installModel = new DatabaseInstallModel() { DatabaseType = DatabaseServerType.MSSQL, DatabaseName = "test", Server = "testserver", Username = "******", Password = "******" }; var boot = new ProviderBootstrapper(null, null, new FakeFrameworkContext()); //Act boot.ConfigureApplication("rw-test", "test", configXml, new BendyObject(installModel)); //Assert Assert.AreEqual(@"<configuration> <configSections> <sectionGroup name=""umbraco""> <sectionGroup name=""persistenceProviderSettings""> <section name=""test"" type=""Umbraco.Framework.Persistence.NHibernate.Config.ProviderConfigurationSection, Umbraco.Framework.Persistence.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"" /> </sectionGroup> </sectionGroup> </configSections> <connectionStrings> <add name=""test.ConnString"" connectionString=""Data Source=testserver; Initial Catalog=test;User Id=testuser;Password=testpass"" providerName=""System.Data.SqlClient"" /> </connectionStrings> <appSettings /> <umbraco> <persistenceProviderSettings> <test connectionStringKey=""test.ConnString"" sessionContext=""web"" driver=""MsSql2008"" /> </persistenceProviderSettings> </umbraco> </configuration>", configXml.ToString()); }
public ActionResult DatabaseForm(DatabaseInstallModel model) { if (!ModelState.IsValid) { return(View(model)); } //create a new web.config file in /plugins for the providers to write to var configFile = new FileInfo( Path.Combine(HttpContext.Server.MapPath("~/App_Data/Rebel/HiveConfig"), "web.config")); Directory.CreateDirectory(configFile.Directory.FullName); var configXml = DeepConfigManager.CreateNewConfigFile(configFile, true); //for each hive provider, get them to serialize their config to our xml file foreach (var hive in _requestContext.Application.Hive.GetAllReadWriteProviders()) { var installStatus = hive.Bootstrapper.GetInstallStatus(); //even if it's not completed, then overwrite if (installStatus.StatusType == InstallStatusType.RequiresConfiguration || installStatus.StatusType == InstallStatusType.Pending || installStatus.StatusType == InstallStatusType.TriedAndFailed) { //TODO: This will currently only work for the nhibernate provider since we're just passing in the DatabaseInstallmodel as the install params hive.Bootstrapper.ConfigureApplication(hive.ProviderMetadata.Alias, configXml, new BendyObject(model)); } } // Test connection strings if (model.DatabaseType != DatabaseServerType.SQLCE) { // We don't test SQL CE connection string as we will just create the DB if it doesn't exist try { foreach ( var connStringElement in configXml.Element("configuration").Element("connectionStrings").Descendants("add")) { var connString = connStringElement.Attribute("connectionString").Value; var providerName = connStringElement.Attribute("providerName").Value; var factory = DbProviderFactories.GetFactory(providerName); using (var conn = factory.CreateConnection()) { conn.ConnectionString = connString; conn.Open(); if (model.DatabaseType == DatabaseServerType.Custom || model.DatabaseType == DatabaseServerType.MSSQL) { var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT SERVERPROPERTY('productversion')"; var reader = cmd.ExecuteReader(); while (reader.Read()) { var versionString = reader[0].ToString(); var version = Convert.ToInt32(versionString.Replace(".", "").PadRight(10, '0')); if (version < 1000160000) // SQL 2008 RTM { throw new ApplicationException(string.Format("Unsupported version of SQL Server. SQL 2008 RTM (10.00.1600) or greater is required, but found {0}.", versionString)); } } } } } } catch (global::System.Exception ex) { ModelState.AddModelError("", "An error occured while testing connection string: " + ex.Message); return(View(model)); } } //now save the new config file configXml.Save(configFile.FullName); return(RedirectToAction("DatabaseInstall")); }