示例#1
0
        /// <summary>
        /// Executes the installer.
        /// </summary>
        /// <param name="identity">The user for whom permissions will be given.</param>
        public void Install(string identity)
        {
            if (RunInstaller)
            {
                var configSection = Configure.GetConfigSection <TimeoutPersisterConfig>();

                if (configSection != null)
                {
                    if (configSection.NHibernateProperties.Count == 0)
                    {
                        throw new InvalidOperationException(
                                  "No NHibernate properties found. Please specify NHibernateProperties in your TimeoutPersisterConfig section");
                    }

                    foreach (var property in configSection.NHibernateProperties.ToProperties())
                    {
                        ConfigureNHibernate.TimeoutPersisterProperties[property.Key] = property.Value;
                    }
                }

                ConfigureNHibernate.ThrowIfRequiredPropertiesAreMissing(ConfigureNHibernate.TimeoutPersisterProperties);

                var configuration = ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.TimeoutPersisterProperties);
                ConfigureNHibernate.AddMappings <TimeoutEntityMap>(configuration);
                new SchemaUpdate(configuration).Execute(false, true);
            }
        }
示例#2
0
        /// <summary>
        /// Configures NHibernate Timeout Persister.
        /// </summary>
        /// <remarks>
        /// Reads configuration settings from <a href="http://msdn.microsoft.com/en-us/library/ms228154.aspx">&lt;appSettings&gt; config section</a> and <a href="http://msdn.microsoft.com/en-us/library/bf7sd233">&lt;connectionStrings&gt; config section</a>.
        /// </remarks>
        /// <example>
        /// An example that shows the minimum configuration:
        /// <code lang="XML" escaped="true">
        ///  <appSettings>
        ///    <!-- other optional settings examples -->
        ///    <add key="NServiceBus/Persistence/NHibernate/connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        ///    <add key="NServiceBus/Persistence/NHibernate/connection.driver_class" value="NHibernate.Driver.Sql2008ClientDriver"/>
        ///    <!-- For more setting see http://www.nhforge.org/doc/nh/en/#configuration-hibernatejdbc and http://www.nhforge.org/doc/nh/en/#configuration-optional -->
        ///  </appSettings>
        ///
        ///  <connectionStrings>
        ///    <!-- Default connection string for all persisters -->
        ///    <add name="NServiceBus/Persistence/NHibernate" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
        ///
        ///    <!-- Optional overrides per persister -->
        ///    <add name="NServiceBus/Persistence/NHibernate/Timeout" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=timeout;Integrated Security=True" />
        ///  </connectionStrings>
        /// </code>
        /// </example>
        /// <param name="config">The configuration object.</param>
        /// <returns>The configuration object.</returns>
        public static Configure UseNHibernateTimeoutPersister(this Configure config)
        {
            var configSection = Configure.GetConfigSection <TimeoutPersisterConfig>();

            if (configSection != null)
            {
                if (configSection.NHibernateProperties.Count == 0)
                {
                    throw new InvalidOperationException(
                              "No NHibernate properties found. Please specify NHibernateProperties in your TimeoutPersisterConfig section");
                }

                foreach (var property in configSection.NHibernateProperties.ToProperties())
                {
                    ConfigureNHibernate.TimeoutPersisterProperties[property.Key] = property.Value;
                }
            }

            ConfigureNHibernate.ConfigureSqlLiteIfRunningInDebugModeAndNoConfigPropertiesSet(ConfigureNHibernate.TimeoutPersisterProperties);

            var properties = ConfigureNHibernate.TimeoutPersisterProperties;

            return(config.UseNHibernateTimeoutPersisterInternal(ConfigureNHibernate.CreateConfigurationWith(properties),
                                                                configSection == null || configSection.UpdateSchema));
        }
示例#3
0
            public IDictionary <string, string> Execute()
            {
                ConfigureNHibernate.Init();
                var configuration =
                    ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.DistributorPersisterProperties);

                return(configuration.Properties);
            }
            public IDictionary <string, string> Execute()
            {
                var config        = new ConfigureNHibernate(new SettingsHolder());
                var configuration =
                    ConfigureNHibernate.CreateConfigurationWith(config.DistributorPersisterProperties);

                return(configuration.Properties);
            }
示例#5
0
        public static Configure UseNHibernateTimeoutPersisterWithSQLiteAndAutomaticSchemaGeneration(this Configure config)
        {
            ConfigureNHibernate.TimeoutPersisterProperties["dialect"] = "NHibernate.Dialect.SQLiteDialect";
            ConfigureNHibernate.TimeoutPersisterProperties["connection.connection_string"] = "Data Source=.\\NServiceBus.Timeouts.sqlite;Version=3;New=True;";

            var configuration = ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.TimeoutPersisterProperties);

            return(config.UseNHibernateTimeoutPersisterInternal(configuration, true));
        }
        /// <summary>
        /// Configures NHibernate Gateway Persister.
        /// </summary>
        /// <remarks>
        /// Reads configuration settings from <a href="http://msdn.microsoft.com/en-us/library/ms228154.aspx">&lt;appSettings&gt; config section</a> and <a href="http://msdn.microsoft.com/en-us/library/bf7sd233">&lt;connectionStrings&gt; config section</a>.
        /// </remarks>
        /// <example>
        /// An example that shows the minimum configuration:
        /// <code lang="XML" escaped="true">
        ///  <appSettings>
        ///    <!-- optional settings examples -->
        ///    <add key="NServiceBus/Persistence/NHibernate/connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        ///    <add key="NServiceBus/Persistence/NHibernate/connection.driver_class" value="NHibernate.Driver.Sql2008ClientDriver"/>
        ///    <!-- For more setting see http://www.nhforge.org/doc/nh/en/#configuration-hibernatejdbc and http://www.nhforge.org/doc/nh/en/#configuration-optional -->
        ///  </appSettings>
        ///
        ///  <connectionStrings>
        ///    <!-- Default connection string for all persisters -->
        ///    <add name="NServiceBus/Persistence/NHibernate" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True" />
        ///
        ///    <!-- Optional overrides per persister -->
        ///    <add name="NServiceBus/Persistence/NHibernate/Gateway" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=gateway;Integrated Security=True" />
        ///  </connectionStrings>
        /// </code>
        /// </example>
        /// <param name="config">The configuration object.</param>
        /// <returns>The configuration object.</returns>
        public static Configure UseNHibernateGatewayPersister(this Configure config)
        {
            ConfigureNHibernate.ConfigureSqlLiteIfRunningInDebugModeAndNoConfigPropertiesSet(ConfigureNHibernate.GatewayPersisterProperties);

            var properties    = ConfigureNHibernate.GatewayPersisterProperties;
            var configuration = ConfigureNHibernate.CreateConfigurationWith(properties);

            return(config.UseNHibernateGatewayPersisterInternal(configuration));
        }
示例#7
0
        public static Configure NHibernateSagaPersister(this Configure config, IDictionary <string, string> nhibernateProperties,
                                                        bool autoUpdateSchema)
        {
            foreach (var property in nhibernateProperties)
            {
                ConfigureNHibernate.SagaPersisterProperties[property.Key] = property.Value;
            }

            return(config.UseNHibernateSagaPersisterInternal(ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.SagaPersisterProperties), autoUpdateSchema));
        }
示例#8
0
        /// <summary>
        /// Executes the installer.
        /// </summary>
        /// <param name="identity">The user for whom permissions will be given.</param>
        public void Install(string identity)
        {
            if (RunInstaller)
            {
                ConfigureNHibernate.ThrowIfRequiredPropertiesAreMissing(ConfigureNHibernate.GatewayPersisterProperties);

                var configuration = ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.GatewayPersisterProperties);
                ConfigureNHibernate.AddMappings <GatewayMessageMap>(configuration);
                new SchemaUpdate(configuration).Execute(false, true);
            }
        }
示例#9
0
        public void Update_schema_can_be_specified_by_the_user()
        {
            var builder    = new SessionFactoryBuilder(Configure.TypesToScan);
            var properties = ConfigureNHibernate.SagaPersisterProperties;

            var sessionFactory = builder.Build(ConfigureNHibernate.CreateConfigurationWith(properties));

            using (var session = sessionFactory.OpenSession())
            {
                session.CreateCriteria(typeof(MySaga)).List <MySaga>();
            }
        }
示例#10
0
            public IDictionary <string, string> Execute()
            {
                NHibernateSettingRetriever.ConnectionStrings = () => new ConnectionStringSettingsCollection
                {
                    new ConnectionStringSettings("NServiceBus/Persistence", "specified")
                };

                ConfigureNHibernate.Init();
                var configuration =
                    ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.DistributorPersisterProperties);

                return(configuration.Properties);
            }
示例#11
0
        public void SetUp()
        {
            string connectionString = String.Format(@"Data Source={0};Version=3;New=True;", Path.GetTempFileName());

            Configure.ConfigurationSource = new FakeConfigurationSource();

            NHibernateSettingRetriever.AppSettings = () => new NameValueCollection
            {
                { "NServiceBus/Persistence/NHibernate/dialect", dialect }
            };

            NHibernateSettingRetriever.ConnectionStrings = () => new ConnectionStringSettingsCollection
            {
                new ConnectionStringSettings("NServiceBus/Persistence/NHibernate/Saga", connectionString)
            };

            ConfigureNHibernate.Init();

            Configure.Features.Enable <Features.Sagas>();

            var types = typeof(TestSaga).Assembly.GetTypes().ToList();

            types.Add(typeof(ContainSagaData));

            Configure.With(types)
            .DefineEndpointName("Foo")
            .DefaultBuilder()
            .UseNHibernateSagaPersister();

            var builder    = new SessionFactoryBuilder(Configure.TypesToScan);
            var properties = ConfigureNHibernate.SagaPersisterProperties;

            SessionFactory = builder.Build(ConfigureNHibernate.CreateConfigurationWith(properties));

            UnitOfWork = new UnitOfWorkManager {
                SessionFactory = SessionFactory
            };

            SagaPersister = new SagaPersister {
                UnitOfWorkManager = (UnitOfWorkManager)UnitOfWork
            };

            new Installer().Install(WindowsIdentity.GetCurrent().Name);
        }
示例#12
0
        /// <summary>
        /// Executes the installer.
        /// </summary>
        /// <param name="identity">The user for whom permissions will be given.</param>
        public void Install(string identity)
        {
            if (RunInstaller)
            {
                var configSection = Configure.GetConfigSection <NHibernateSagaPersisterConfig>();

                if (configSection != null)
                {
                    if (configSection.NHibernateProperties.Count == 0)
                    {
                        throw new InvalidOperationException(
                                  "No NHibernate properties found. Please specify NHibernateProperties in your NHibernateSagaPersisterConfig section");
                    }

                    foreach (var property in configSection.NHibernateProperties.ToProperties())
                    {
                        ConfigureNHibernate.SagaPersisterProperties[property.Key] = property.Value;
                    }
                }

                ConfigureNHibernate.ThrowIfRequiredPropertiesAreMissing(ConfigureNHibernate.SagaPersisterProperties);

                var configuration     = ConfigureNHibernate.CreateConfigurationWith(ConfigureNHibernate.SagaPersisterProperties);
                var typesToScan       = Configure.TypesToScan.ToList();
                var scannedAssemblies = typesToScan.Select(t => t.Assembly).Distinct();

                foreach (var assembly in scannedAssemblies)
                {
                    configuration.AddAssembly(assembly);
                }

                var modelMapper = new SagaModelMapper(typesToScan.Except(configuration.ClassMappings.Select(x => x.MappedClass)));

                configuration.AddMapping(modelMapper.Compile());


                new SchemaUpdate(configuration).Execute(false, true);
            }
        }