Esempio n. 1
0
        /// <summary>
        /// 使用配置注册自定义的插件服务。
        /// </summary>
        /// <param name="section">提供者的配置对象。</param>
        private static void RegisterCustomProviders(ProviderConfigurationSection section)
        {
            foreach (var key in section.Settings.Keys)
            {
                var setting = section.Settings[key];
                if (providerWappers.Any(s => s.Contains(setting.Name)) || setting.Type == null)
                {
                    continue;
                }

                var provider = setting.Type.New <IProvider>();
                if (provider == null)
                {
                    continue;
                }

                IProvider inherProvider = null;
                if (!string.IsNullOrEmpty(setting.InheritedProvider) &&
                    (inherProvider = GetDefinedProviderInstance(setting.InheritedProvider)) != null)
                {
                    inherProvider.GetServices().ForEach(s => provider.RegisterService(s.GetType()));
                }

                //为提供者注册插件服务
                setting.ServiceTypes.ForEach(s => provider.RegisterService(s));

                RegisterProvider(setting.Name, provider);
            }
        }
        /// <summary>
        /// Initializes the provider and ensures that all configuration can be read
        /// </summary>
        /// <param name="builderContext"></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 packaging provider '{1}'",
                                        HiveConfigSection.ConfigXmlKey, ProviderKey));
            }

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

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

            //get the Hive provider config section
            _localConfig = DeepConfigManager.Default.GetFirstPluginSection <ProviderConfigurationSection>(config2Rw.ConfigSectionKey);

            if (!ValidateProviderConfigSection <MembershipDemandBuilder>(_localConfig, config2Rw))
            {
                CanBuild = false;
                return;
            }

            CanBuild = true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProviderBootstrapper"/> class if sufficient configuration information has been supplied by the user.
        /// </summary>
        /// <param name="existingConfig">The existing config.</param>
        /// <param name="examineManager"></param>
        /// <param name="frameworkContext"></param>
        /// <remarks></remarks>
        public ProviderBootstrapper(ProviderConfigurationSection existingConfig, ExamineManager examineManager, IFrameworkContext frameworkContext)
        {
            _existingConfig   = existingConfig;
            _examineManager   = examineManager;
            _frameworkContext = frameworkContext;

            //bind to all of the Examine events
            foreach (var i in _examineManager.IndexProviderCollection.OfType <BaseIndexProvider>())
            {
                i.IndexingError += (sender, e) => LogHelper.Error <Exception>("[Examine] " + e.Message, e.InnerException);
                i.IndexDeleted  += (sender, e) => LogHelper.TraceIfEnabled <ExamineManager>("[Examine] Item {0} has been removed from the index", () => e.DeletedTerm.Value);
                i.NodeIndexed   += (sender, e) => LogHelper.TraceIfEnabled <ExamineManager>("[Examine] Item {0} has been indexed", () => e.Item.Id);
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        /// <summary>
        /// 使用配置注册自定义的插件服务。
        /// </summary>
        /// <param name="section">提供者的配置对象。</param>
        private static void RegisterCustomProviders(ProviderConfigurationSection section)
        {
            foreach (var key in section.Settings.Keys)
            {
                var setting = section.Settings[key];
                if (dicProviders.ContainsKey(setting.Name))
                {
                    continue;
                }

                var provider = setting.Type.New <IProvider>();
                if (provider == null)
                {
                    continue;
                }

                //为提供者注册插件服务
                setting.ServiceTypes.ForEach(s => provider.RegisterService(s));

                RegisterProvider(setting.Name, provider);
            }
        }
Esempio n. 6
0
        private static void RegisterCustomProviders(ProviderConfigurationSection section)
        {
            foreach (var key in section.Settings.Keys)
            {
                var setting = section.Settings[key];
                if (dicProviders.ContainsKey(setting.Name))
                {
                    continue;
                }

                var provider = setting.Type.New <IProvider>();
                if (provider == null)
                {
                    continue;
                }

                foreach (var type in setting.ServiceTypes)
                {
                    provider.RegisterService(type);
                }

                dicProviders.TryAdd(setting.Name, provider);
            }
        }
Esempio n. 7
0
        /// <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|Umbraco.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, "umbraco/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);
        }
Esempio n. 8
0
 /// <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;
 }
Esempio n. 9
0
        /// <summary>
        /// 获取 Provider 的配置。
        /// </summary>
        /// <param name="setting">数据库实例配置对象。</param>
        /// <param name="section">提供者配置节对象。</param>
        /// <returns>一个提供者配置对象。</returns>
        private static ProviderConfigurationSetting GetProviderSetting(IInstanceConfigurationSetting setting, ProviderConfigurationSection section)
        {
            if (section == null || string.IsNullOrEmpty(setting.ProviderName))
            {
                return(null);
            }

            return(section.Settings[setting.ProviderName]);
        }
 public NHibernateConfigBuilder(string @alias, ProviderConfigurationSection localConfig)
     : this(localConfig.GetConnectionString(), alias, localConfig.Driver, localConfig.SessionContext, localConfig.OutputNhMappings, localConfig.UseNhProf)
 {
 }
Esempio n. 11
0
        /// <summary>
        /// Initializes the provider and ensures that all configuration can be read
        /// </summary>
        /// <param name="builderContext"></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 packaging 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));
            }

            //get the Hive provider config section
            _localConfig = DeepConfigManager.Default.GetFirstPluginSection <ProviderConfigurationSection>(config2Rw.ConfigSectionKey);

            if (!ValidateProviderConfigSection <ExamineDemandBuilder>(_localConfig, config2Rw))
            {
                CanBuild = false;
                return;
            }

            var configMgr = DeepConfigManager.Default;

            //get the internal indexer provider
            _internalIndexer = configMgr.GetFirstPluginSetting <ExamineSettings, ProviderSettings>("examine/examine.settings",
                                                                                                   x => x.IndexProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalIndexer));
            if (_internalIndexer == null)
            {
                LogHelper.Warn <ExamineDemandBuilder>("Could not load RebelInternalIndexer, the configuration section could not be read.");
                CanBuild = false;
                return;
            }

            //get the internal searcher provider
            _internalSearcher = configMgr.GetFirstPluginSetting <ExamineSettings, ProviderSettings>("examine/examine.settings",
                                                                                                    x => x.SearchProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalSearcher));
            if (_internalSearcher == null)
            {
                LogHelper.Warn <ExamineDemandBuilder>("Could not load RebelInternalSearcher, the configuration section could not be read.");
                CanBuild = false;
                return;
            }

            //get the internal index set to use for the searcher/indexer
            _internalIndexSet = configMgr.GetFirstPluginSetting <IndexSets, IndexSet>("examine/examine.indexes",
                                                                                      x => x.SingleOrDefault(set => set.SetName == _localConfig.InternalIndexSet));
            if (_internalIndexSet == null)
            {
                LogHelper.Warn <ExamineDemandBuilder>("Could not load RebelInternalIndexSet, the configuration section could not be read.");
                CanBuild = false;
                return;
            }

            CanBuild = true;
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProviderBootstrapper"/> class if sufficient configuration information has been supplied by the user.
 /// </summary>
 /// <param name="existingConfig">The existing config.</param>
 /// <remarks></remarks>
 public ProviderBootstrapper(ProviderConfigurationSection existingConfig)
 {
     _existingConfig = existingConfig;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProviderBootstrapper"/> class if sufficient configuration information has been supplied by the user.
 /// </summary>
 /// <param name="existingConfig">The existing config.</param>
 /// <param name="frameworkContext"></param>
 /// <remarks></remarks>
 public ProviderBootstrapper(ProviderConfigurationSection existingConfig, IFrameworkContext frameworkContext)
 {
     _existingConfig   = existingConfig;
     _frameworkContext = frameworkContext;
 }