Inheritance: AbstractProviderConfigurationSection
        /// <summary>
        /// Initialises the provider dependency builder. This method is run by <see cref="Rebel.Hive.DependencyManagement.ProviderDemandRunner"/> prior to it calling <see cref="Build"/>.
        /// </summary>
        /// <param name="builderContext">The builder context.</param>
        public override void Initialise(IBuilderContext builderContext)
        {
            Mandate.ParameterNotNull(builderContext, "builderContext");

            var configMain = builderContext.ConfigurationResolver.GetConfigSection(HiveConfigSection.ConfigXmlKey) as HiveConfigSection;
            if (configMain == null)
                throw new ConfigurationErrorsException(
                    string.Format("Configuration section '{0}' not found when building persistence provider '{1}'",
                                  HiveConfigSection.ConfigXmlKey, ProviderKey));

            var config2rw = RegistryConfigElement ?? configMain.Providers.ReadWriters[ProviderKey] ?? configMain.Providers.Readers[ProviderKey];

            if (config2rw == null)
            {
                throw new ConfigurationErrorsException(
                    string.Format("No configuration found for persistence provider '{0}'", ProviderKey));
            }

            _localConfig = !string.IsNullOrEmpty(config2rw.ConfigSectionKey)
                              ? DeepConfigManager.Default.GetFirstWebSetting
                                    <ProviderConfigurationSection, ProviderConfigurationSection>(
                                        config2rw.ConfigSectionKey, x => x, "~/App_Data/Rebel/HiveConfig")
                                ??
                                config2rw.GetLocalProviderConfig() as ProviderConfigurationSection
                              : null;

            if (ValidateProviderConfigSection<NHibernateDemandBuilder>(_localConfig, config2rw))
            {
                CanBuild = true;
            }          
        }
        public void NHibernateBootstrapper_Tried_And_Failed()
        {

            var localConfig = new ProviderConfigurationSection()
                {
                    ConnectionStringKey = "This is an invalid conn string",
                    Driver = SupportedNHDrivers.MsSql2008,
                    SessionContext = "web"
                };
            var builder = new NHibernateConfigBuilder(localConfig.ConnectionStringKey, "test", localConfig.Driver, "thread_static", false);
            var config = builder.BuildConfiguration();
            var boot = new ProviderBootstrapper(config, localConfig, new FakeFrameworkContext());

            var status = boot.TryInstall();

            Assert.AreEqual(InstallStatusType.TriedAndFailed, status.StatusType);
        }
        /// <summary>
        /// Creates any necessary configuration files/transforms for the provider to operate
        /// </summary>
        /// <param name="providerKey">The provider key for the provider that is being configured</param>
        /// <param name="configXml">The configuration xml file that needs to be written to</param>
        /// <param name="installParams">TODO: This is only a temporary way of passing arbitrary parameters to a provider to create its configuration,
        /// we need to allow hive providers to return a model for which we display a form/installer for and then pass in that
        /// model to the installParams</param>
        public override void ConfigureApplication(string providerKey, XDocument configXml, BendyObject installParams)
        {
            dynamic dynamicParams = installParams;
            string dbType = dynamicParams.DatabaseType.ToString();

            var connectionString = "";
            var providerName = "";
            var nhDriver = "";
            //we need to create the connection strings if it's not custom

            switch (dbType)
            {
                case "MSSQL":
                    connectionString = string.Format("Data Source={0}; Initial Catalog={1};User Id={2};Password={3}",
                                                     dynamicParams.Server, dynamicParams.DatabaseName, dynamicParams.Username, dynamicParams.Password);
                    providerName = "System.Data.SqlClient";
                    nhDriver = "MsSql2008";
                    break;
                case "MySQL":
                    connectionString = string.Format("Server={0}; Database={1};Uid={2};Pwd={3}",
                                                     dynamicParams.Server, dynamicParams.DatabaseName, dynamicParams.Username, dynamicParams.Password);
                    providerName = "MySql.Data.MySQLClient";
                    nhDriver = "MySql";
                    break;
                case "SQLCE":
                    connectionString = "Data Source=|DataDirectory|Rebel.sdf";
                    providerName = "System.Data.SqlServerCe.4.0";
                    nhDriver = "MsSqlCe4";
                    break;
                case "Custom":
                    //limiting to MS SQL atm 
                    connectionString = dynamicParams.ConnectionString;
                    providerName = "System.Data.SqlClient";
                    nhDriver = "MsSql2008";
                    break;
            }

            var connstringKey = "";

            var hiveElement = new ProviderConfigurationSection()
                       {
                           ConnectionStringKey = "{0}.ConnString",
                           Driver = SupportedNHDrivers.MsSqlCe4,
                           SessionContext = "web"
                       };

            var elementName = providerKey;
    
            hiveElement.DriverAsString = nhDriver;
            connstringKey = string.Format(hiveElement.ConnectionStringKey, providerKey);
            hiveElement.ConnectionStringKey = connstringKey;

            DeepConfigManager.SerializeProviderConfigSection(configXml, hiveElement, "rebel/persistenceProviderSettings/" + elementName, true);

            //add the connection strings
            var connStrings = new ConnectionStringsSection();
            connStrings.ConnectionStrings.Add(new ConnectionStringSettings(connstringKey, connectionString, providerName));
            //now serialize the connection strings to the config
            var connectionStringElement = DeepConfigManager.SerializeProviderConfigSection(configXml, connStrings, "connectionStrings", false);
            var newConnString = new XElement("add");
            DeepConfigManager.AddPropertiesToElement(connStrings.ConnectionStrings[0], newConnString);
            connectionStringElement.Add(newConnString);
            
            // The following is superceded by the above to support multiple "add" references: DeepConfigManager.SerializeProviderConfigSection(configXml, connStrings.ConnectionStrings[0], "connectionStrings/add", false);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProviderBootstrapper"/> class if sufficient configuration information has been supplied by the user.
 /// </summary>        
 /// <param name="configuration">The configuration.</param>
 /// <param name="localConfig">The existing config.</param>
 /// <remarks></remarks>
 public ProviderBootstrapper(global::NHibernate.Cfg.Configuration configuration, ProviderConfigurationSection localConfig)
 {
     _localConfig = localConfig;
     _configuration = configuration;
 }