/// <summary>
        /// Use the NHibernate backed saga persister implementation.
        /// SagaData classes are automatically mapped using Fluent NHibernate conventions
        /// and there persistence schema is automatically generated if requested.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="nhibernateProperties"></param>
        /// <param name="autoUpdateSchema"></param>
        /// <returns></returns>
        public static Configure NHibernateSagaPersister(this Configure config,
                                                        IDictionary <string, string> nhibernateProperties,
                                                        bool autoUpdateSchema)
        {
            if (!Sagas.Impl.Configure.SagasWereFound)
            {
                return(config); //no sagas - don't need to do anything
            }
            if (nhibernateProperties == null)
            {
                throw new InvalidOperationException("No properties configured for NHibernate. Check that you have a configuration section called 'NHibernateSagaPersisterConfig'.");
            }

            var builder = new SessionFactoryBuilder(Configure.TypesToScan);

            var sessionFactory = builder.Build(nhibernateProperties, autoUpdateSchema);

            if (sessionFactory == null)
            {
                throw new InvalidOperationException("Could not create session factory for saga persistence.");
            }

            config.Configurer.RegisterSingleton <ISessionFactory>(sessionFactory);
            config.Configurer.ConfigureComponent <SagaPersister>(DependencyLifecycle.InstancePerCall);
            config.NHibernateUnitOfWork();

            return(config);
        }
Ejemplo n.º 2
0
        public void BeforeEachTest()
        {
            ISessionFactoryBuilder sessionFactoryBuilder = new SessionFactoryBuilder(new SqlLiteConfigurationBuilder());
            ISessionFactory        sessionFactory        = sessionFactoryBuilder.Build();

            Session = sessionFactory.OpenSession();
        }
        /// <summary>
        /// Use the NHibernate backed saga persister implementation on top of Azure table storage.
        /// SagaData classes are automatically mapped using Fluent NHibernate conventions
        /// and there persistence schema is automatically generated if requested.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="connectionString"></param>
        /// <param name="autoUpdateSchema"></param>
        /// <returns></returns>
        public static Configure AzureSagaPersister(this Configure config,
                                                   string connectionString,
                                                   bool autoUpdateSchema)
        {
            if (!Sagas.Impl.Configure.SagasWereFound)
            {
                return(config); //no sagas - don't need to do anything
            }
            var nhibernateProperties = MsSqlConfiguration.MsSql2005
                                       .ConnectionString(connectionString)
                                       .Provider(typeof(TableStorageConnectionProvider).AssemblyQualifiedName)
                                       .Dialect(typeof(TableStorageDialect).AssemblyQualifiedName)
                                       .Driver(typeof(TableStorageDriver).AssemblyQualifiedName)
                                       .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName)
                                       .ToProperties();

            var builder = new SessionFactoryBuilder(Configure.TypesToScan);

            var sessionFactory = builder.Build(nhibernateProperties, autoUpdateSchema);

            if (sessionFactory == null)
            {
                throw new InvalidOperationException("Could not create session factory for saga persistence.");
            }

            config.Configurer.RegisterSingleton <ISessionFactory>(sessionFactory);
            config.Configurer.ConfigureComponent <SagaPersister>(DependencyLifecycle.InstancePerCall);

            return(config);
        }
        public void Should_throw_if_class_is_derived()
        {
            var builder = new SessionFactoryBuilder(new[] { typeof(MyDerivedClassWithRowVersion) });

            var properties = SQLiteConfiguration.InMemory();

            Assert.Throws<MappingException>(() => builder.Build(new Configuration().AddProperties(properties)));
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            var builder = new SessionFactoryBuilder(new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
        public void SetUp()
        {
            var builder = new SessionFactoryBuilder(new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 7
0
 private void RegisterNHibernateConfigs()
 {
     foreach (var serviceModule in _serviceModules)
     {
         var mappingsDistincted = GetItemsDistincted(serviceModule.Mappings);
         _sessionFactoryBuilder.Build(_builder, mappingsDistincted, serviceModule.Name, serviceModule.IsolationLevel);
     }
 }
        public static SessionFactoryImpl Build()
        {
            var types = Types();

            var builder = new SessionFactoryBuilder(types);
            var properties = SQLiteConfiguration.InMemory();

            return builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 9
0
        private ISession CreateSession(SessionFactoryBuilder sessionFactory)
        {
            _factory = sessionFactory.Build();
            var builder    = _factory.WithOptions();
            var connection = new SqlConnection(sessionFactory.ConnectionString);

            connection.Open();
            return(builder.Connection(connection).OpenSession());
        }
Ejemplo n.º 10
0
        public void References_of_the_persistent_entity_should_also_be_mapped()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;

            var builder = new SessionFactoryBuilder(assemblyContainingSagas.GetTypes());

            var sessionFactory = builder.Build(testProperties, false) as SessionFactoryImpl;

            Assert.NotNull(sessionFactory.GetEntityPersister(typeof(RelatedClass).FullName));
        }
        public static ISession New(IDatabaseMappingScheme<MappingConfiguration> mappingScheme)
        {

            var sessionFactoryBuilder = new SessionFactoryBuilder(mappingScheme, SQLiteConfiguration.Standard.InMemory());
            Configuration config = null;
            _sessionFactory = sessionFactoryBuilder.Build(cfg => { config = cfg; });
            ISession session = _sessionFactory.OpenSession();
            new SchemaExport(config).Execute(false, true, false, session.Connection, null);
            return session;
        }
        public void References_of_the_persistent_entity_should_also_be_mapped()
        {
            var assemblyContainingSagas = typeof (TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();
            types.Add(typeof(ContainSagaData));

            var builder = new SessionFactoryBuilder(types);

            var sessionFactory = builder.Build(new Configuration().AddProperties(testProperties)) as SessionFactoryImpl;

            Assert.NotNull(sessionFactory.GetEntityPersister(typeof (RelatedClass).FullName));
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();

            types.Add(typeof(ContainSagaData));

            var builder    = new SessionFactoryBuilder(types);
            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 14
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>();
            }
        }
        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>();
            }
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;

            var builder = new SessionFactoryBuilder(assemblyContainingSagas.GetTypes());

            sessionFactory = builder.Build(SQLiteConfiguration.Standard
                                           .InMemory()
                                           .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName)
                                           .ToProperties(), false) as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSaga>();
        }
        public void References_of_the_persistent_entity_should_also_be_mapped()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();

            types.Add(typeof(ContainSagaData));

            var builder = new SessionFactoryBuilder(types);

            var sessionFactory = builder.Build(new Configuration().AddProperties(testProperties)) as SessionFactoryImpl;

            Assert.NotNull(sessionFactory.GetEntityPersister(typeof(RelatedClass).FullName));
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        static Configure UseNHibernateSagaPersisterInternal(this Configure config, Configuration configuration, bool autoUpdateSchema)
        {
            ConfigureNHibernate.ThrowIfRequiredPropertiesAreMissing(ConfigureNHibernate.SagaPersisterProperties);

            SagaPersisters.NHibernate.Config.Installer.Installer.RunInstaller = autoUpdateSchema;

            var builder = new SessionFactoryBuilder(Configure.TypesToScan);

            var sessionFactory = builder.Build(configuration);

            if (sessionFactory == null)
            {
                throw new InvalidOperationException("Could not create session factory for saga persistence.");
            }

            config.Configurer.ConfigureComponent <UnitOfWorkManager>(DependencyLifecycle.SingleInstance)
            .ConfigureProperty(p => p.SessionFactory, sessionFactory);

            config.Configurer.ConfigureComponent <SagaPersister>(DependencyLifecycle.InstancePerCall);

            return(config);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;

            var builder = new SessionFactoryBuilder(assemblyContainingSagas.GetTypes());

            //var properties = SQLiteConfiguration.Standard
            //  .InMemory()
            //  .ToProperties();

            //File.WriteAllText("sqlite.txt", "");

            //foreach (var property in properties)
            //{
            //  File.AppendAllText("sqlite.txt", String.Format("{{ \"{0}\", \"{1}\" }}\n", property.Key, property.Value));

            //}

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(properties, false) as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSaga>();
        }
        static Configure UseNHibernateSagaPersisterInternal(this Configure config, Configuration configuration, bool autoUpdateSchema)
        {
            ConfigureNHibernate.ThrowIfRequiredPropertiesAreMissing(ConfigureNHibernate.SagaPersisterProperties);

            SagaPersisters.NHibernate.Config.Installer.Installer.RunInstaller = autoUpdateSchema;

            var builder = new SessionFactoryBuilder(Configure.TypesToScan);

            var sessionFactory = builder.Build(configuration);

            if (sessionFactory == null)
            {
                throw new InvalidOperationException("Could not create session factory for saga persistence.");
            }

            config.Configurer.ConfigureComponent<UnitOfWorkManager>(DependencyLifecycle.SingleInstance)
                .ConfigureProperty(p => p.SessionFactory, sessionFactory);

            config.Configurer.ConfigureComponent<SagaPersister>(DependencyLifecycle.InstancePerCall);

            return config;
        }
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();
            types.Add(typeof (ContainSagaData));

            var builder = new SessionFactoryBuilder(types);
            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }