Exemple #1
0
        static IDictionary <string, string> InitFromConfiguration(ReadOnlySettings settings)
        {
            connectionStringSettingsCollection = NHibernateSettingRetriever.ConnectionStrings() ??
                                                 new ConnectionStringSettingsCollection();

            var configuration = CreateNHibernateConfiguration();

            var defaultConnectionString = settings.GetOrDefault <string>("NHibernate.Common.ConnectionString") ?? GetConnectionStringOrNull("NServiceBus/Persistence");
            var configurationProperties = configuration.Properties;

            var appSettingsSection = NHibernateSettingRetriever.AppSettings() ?? new NameValueCollection();

            foreach (string appSetting in appSettingsSection)
            {
                var match = PropertyRetrievalRegex.Match(appSetting);
                if (match.Success)
                {
                    configurationProperties[match.Groups[1].Value] = appSettingsSection[appSetting];
                }
            }
            if (!string.IsNullOrEmpty(defaultConnectionString))
            {
                configurationProperties[Environment.ConnectionString] = defaultConnectionString;
            }

            if (!configurationProperties.ContainsKey(Environment.Dialect))
            {
                configurationProperties[Environment.Dialect] = DefaultDialect;
            }
            return(configurationProperties);
        }
Exemple #2
0
        /// <summary>
        /// Initializes the <see cref="NHibernate.Cfg.Configuration"/> NHibernate properties.
        /// </summary>
        /// <remarks>
        /// Configure NHibernate using the <c>&lt;hibernate-configuration&gt;</c> section
        /// from the application config file, if found, or the file <c>hibernate.cfg.xml</c> if the
        /// <c>&lt;hibernate-configuration&gt;</c> section not include the session-factory configuration.
        /// However those settings can be overwritten by our own configuration settings if specified.
        /// </remarks>
        public static void Init()
        {
            connectionStringSettingsCollection = NHibernateSettingRetriever.ConnectionStrings() ??
                                                 new ConnectionStringSettingsCollection();

            var configuration = CreateNHibernateConfiguration();

            var defaultConnectionString = GetConnectionStringOrNull("NServiceBus/Persistence");
            var configurationProperties = configuration.Properties;

            var appSettingsSection = NHibernateSettingRetriever.AppSettings() ?? new NameValueCollection();

            foreach (string appSetting in appSettingsSection)
            {
                var match = PropertyRetrievalRegex.Match(appSetting);
                if (match.Success)
                {
                    configurationProperties[match.Groups[1].Value] = appSettingsSection[appSetting];
                }
            }
            if (!String.IsNullOrEmpty(defaultConnectionString))
            {
                configurationProperties[Environment.ConnectionString] = defaultConnectionString;
            }

            if (!configurationProperties.ContainsKey(Environment.Dialect))
            {
                configurationProperties[Environment.Dialect] = DefaultDialect;
            }

            TimeoutPersisterProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                                  "NServiceBus/Persistence/NHibernate/Timeout");
            SubscriptionStorageProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                                     "NServiceBus/Persistence/NHibernate/Subscription");
            SagaPersisterProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                               "NServiceBus/Persistence/NHibernate/Saga");
            GatewayPersisterProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                                  "NServiceBus/Persistence/NHibernate/Gateway");
            GatewayDeduplicationProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                                      "NServiceBus/Persistence/NHibernate/Deduplication");
            DistributorPersisterProperties = OverrideConnectionStringSettingIfNotNull(configurationProperties,
                                                                                      "NServiceBus/Persistence/NHibernate/Distributor");
        }