Пример #1
0
        public static List <BookingModel> SaveBooking(BookingModel bookingData = null)
        {
            var dbBooking = new Booking();

            dbBooking.Id           = bookingData.Id;
            dbBooking.Name         = bookingData.Name;
            dbBooking.CreationDate = DateTime.Now;
            dbBooking.UpdatedDate  = DateTime.Now;
            //dbBooking.BookingParts = new List<BookingPart>();

            bookingData.BookingParts.ForEach(bpt =>
            {
                dbBooking.Add(new BookingPart
                {
                    Id           = bpt.Id,
                    CreationDate = DateTime.Now,
                    CreationTime = DateTime.Now,
                    Status       = 2,
                    Description  = bpt.Description,
                    Title        = bpt.Title,
                    UpdatedDate  = DateTime.Now,
                });
            });

            using (var session = SessionFactoryBuilder.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(dbBooking);
                    transaction.Commit();
                }
            }

            return(GetBookings());
        }
Пример #2
0
 public static int CreateCoupon(string email) //yeni yelik oluşturulurken bu metod çağrılır.
 {
     try
     {
         int discount = 0;
         using (var session = SessionFactoryBuilder.OpenSession())
         {
             var customerList = session.QueryOver <Customer>().Where(x => x.Email == email).List();
             if (customerList.Count == 0)
             {
                 Coupon couponObj = new Coupon();
                 couponObj.CustomerId = customerList[0].Id;
                 couponObj.Discount   = 5; //%5 hesabı yapılabilir.
                 session.Save(couponObj);
                 session.Clear();
             }
             return(discount);//json formatında başarılı sonuç dönülecek.
         }
     }
     catch (Exception ex)
     {
         //rollback yapılacak.
         //log atılacak.
         return(0); //json formatında hata dönülecek.
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            string connectionString = ConnectionStrings.Get();

            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(connectionString));

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            dd.Drop();
            Console.WriteLine("Database dropped.");
            Thread.Sleep(1000);

            dd.Create();
            Console.WriteLine("Database created.");

            ISession session = sessionFactory.OpenSession();

            using (ITransaction tx = session.BeginTransaction())
            {
                dd.Seed(new List <IDataSeeder>
                {
                    new AccountSeeder(session),
                });
                tx.Commit();
            }
            session.Close();
            sessionFactory.Close();
            Console.WriteLine("Seed data added.");
            Thread.Sleep(2000);
        }
Пример #4
0
 public IList <T> GetList()
 {
     using (ISession Session = SessionFactoryBuilder.getConnection())
     {
         return(Session.Query <T>().ToList());
     }
 }
Пример #5
0
        public Task RouteAsync(RouteContext context)
        {
            var SessionFactory = SessionFactoryBuilder.BuildSessionFactory(true, true);

            using (var Session = SessionFactory.OpenSession())
            {
                using (var transaction = Session.BeginTransaction())
                {
                    string      url     = context.HttpContext.Request.Path.Value.TrimStart('/').TrimEnd('/');
                    var         FullUrl = Session.CreateCriteria <Url>().Add(Restrictions.Like("ShortUrl", url, MatchMode.Anywhere));
                    IList <Url> Urls    = FullUrl.List <Url>();

                    foreach (var record in Urls)
                    {
                        if (url != "" && record.ShortUrl.Contains(url))
                        {
                            record.PassCount++;
                            Session.SaveOrUpdate(record);
                            context.Handler = async ctx =>
                            {
                                ctx.Response.Redirect(record.FullUrl, true);
                            };
                        }
                    }
                    transaction.Commit();
                }
            }
            return(Task.CompletedTask);
        }
Пример #6
0
        public IList <Booking> GetAll()
        {
            List <string>     names = new List <string>();
            IList <Booking>   bookings;
            IList <Passenger> passengers;

            // create our NHibernate session factory
            string connectionString = " server=BW-DESKTOP\\SQLEXPRESS2014; database=FlightsDB;Trusted_Connection=True;";
            var    sessionFactory   = SessionFactoryBuilder.BuildSessionFactory(connectionString, true, true);

            using (var session = sessionFactory.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    bool isopen      = session.IsOpen;
                    bool isconnected = session.IsConnected;

                    passengers = session.Query <Passenger>().ToList();

                    bookings = session.Query <Booking>().ToList(); //  Querying to get all the books

                    foreach (var b in bookings)
                    {
                        names.Add(b.FlightNo);
                    }
                }
            }

            return(bookings);
        }
Пример #7
0
        public JsonResult Lookup(string q_word, string primary_key, int per_page, int page_num)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                var FilteredCategory = svc.Query <Category>()
                                       .Where(x => q_word == "" || x.CategoryName.Contains(q_word));


                var PagedFilter = FilteredCategory.OrderBy(x => x.CategoryName)
                                  .LimitAndOffset(per_page, page_num)
                                  .ToList();

                return(Json(
                           new
                {
                    cnt = FilteredCategory.Count()

                    , primary_key = PagedFilter.Select(x => x.CategoryId)

                    , candidate = PagedFilter.Select(x => x.CategoryName)

                    , cnt_page = PagedFilter.Count()

                    , attached = PagedFilter.Select(x =>
                                                    new[]
                    {
                        new string[] { "Code", x.CategoryCode },
                        new string[] { "Ranking", x.Ranking.ToString() }
                    }
                                                    )
                }
                           ));
            } //using
        }     //Lookup
        /// <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);
        }
Пример #9
0
        public static List <Product> GetProductList()
        {
            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    var productList = session.Query <Product>().ToList();
                    if (productList != null && productList.Count > 0)
                    {
                        foreach (Product productItem in productList.ToList())
                        {
                            if (productItem.Stock == 0)
                            {
                                productList.Remove(productItem);
                            }
                        }
                    }

                    return(productList); //json formatında dönülecek
                }
            }
            catch (Exception ex)
            {
                //log atılacak.
                return(null); //json formatında dönülecek
            }
        }
        //
        // GET: /Home/

        public ViewResult Index()
        {
            using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                return(View(s.Query <Product>().OrderBy(x => x.ProductName).Fetch(x => x.Category).ToList()));
            }
        }
        /// <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);
        }
Пример #12
0
 public T GetById(int id)
 {
     using (ISession Session = SessionFactoryBuilder.getConnection())
     {
         return(Session.Get <T>(id));
     }
 }
Пример #13
0
 protected RepositoryBase(ProviderTypeEnum providerType, string nameOrConnectionString,
                          FluentNHibernatePersistenceBuilderOptions options)
 {
     _info =
         SessionFactoryBuilder.GetFromAssemblyOf <AspNetUser>(providerType,
                                                              nameOrConnectionString, options);
 }
Пример #14
0
        public void BeforeEachTest()
        {
            ISessionFactoryBuilder sessionFactoryBuilder = new SessionFactoryBuilder(new SqlLiteConfigurationBuilder());
            ISessionFactory        sessionFactory        = sessionFactoryBuilder.Build();

            Session = sessionFactory.OpenSession();
        }
Пример #15
0
        static void Main(string[] args)
        {
            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.FromConnectionStringWithKey("CrudGesitonContenido.Local"));

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            dd.Drop();
            Console.WriteLine("Database dropped.");
            Thread.Sleep(1000);

            dd.Create();
            Console.WriteLine("Database created.");

            ISession session = sessionFactory.OpenSession();

            using (ITransaction tx = session.BeginTransaction())
            {
                dd.Seed(new List <IDataSeeder>
                {
                    new DepartamentoSeeder(session)
                });
                tx.Commit();
            }

            session.Close();
            sessionFactory.Close();
            Console.WriteLine("Seed data added.");
            Thread.Sleep(2000);
        }
Пример #16
0
 public static bool Login(string email, string password)
 {
     try
     {
         using (var session = SessionFactoryBuilder.OpenSession())
         {
             var accountObj = session.QueryOver <Customer>().Where(x => x.Email == email).List();
             if (accountObj != null && accountObj.Count > 0)
             {
                 if (accountObj[0].Password == password) //hash tutulacak
                 {
                     return(true);                       //json formatında dönülecek
                 }
             }
             return(false);
             //json formatında dönülecek
         }
     }
     catch (Exception ex)
     {
         //log atılacak.
         //json formatında dönülecek
         return(false);
     }
 }
 public ActionResult InputEdit(int id)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         var p = s.Get <Product>(id);
         return(View("Input", p));
     }
 }
Пример #18
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 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)));
        }
        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;
        }
Пример #21
0
        private void Initialize(object state)
        {
            try
            {
                var sessionFactoryInfo = SessionFactoryBuilder.GetFromAssemblyOf <Message0Map>(
                    _configuration.ProviderType, _configuration.ConnectionString,
                    new FluentNHibernatePersistenceBuilderOptions {
                    DefaultSchema = _configuration.DefaultSchema
                });
                var sessionFactory = sessionFactoryInfo.SessionFactory;
                // NOTE: Called from a ThreadPool thread
                _trace.TraceInformation("Message bus initializing.");

                while (true)
                {
                    try
                    {
                        var installer = new FNHInstaller(sessionFactory, _trace);
                        installer.Install();
                        break;
                    }
                    catch (Exception ex)
                    {
                        _trace.TraceError("Error trying to install database objects, trying again in 2 seconds: {0}",
                                          ex);

                        // Try again in a little bit
                        Thread.Sleep(2000);
                    }
                }

                var collection = new List <IStream>
                {
                    new FNHStream <Messages_0, Messages_0_Id>(0, sessionFactory, _trace),
                    new FNHStream <Messages_1, Messages_1_Id>(1, sessionFactory, _trace),
                    new FNHStream <Messages_2, Messages_2_Id>(2, sessionFactory, _trace),
                    new FNHStream <Messages_3, Messages_3_Id>(3, sessionFactory, _trace),
                    new FNHStream <Messages_4, Messages_4_Id>(4, sessionFactory, _trace),
                    new FNHStream <Messages_5, Messages_5_Id>(5, sessionFactory, _trace),
                    new FNHStream <Messages_6, Messages_6_Id>(6, sessionFactory, _trace),
                    new FNHStream <Messages_7, Messages_7_Id>(7, sessionFactory, _trace),
                    new FNHStream <Messages_8, Messages_8_Id>(8, sessionFactory, _trace),
                    new FNHStream <Messages_9, Messages_9_Id>(9, sessionFactory, _trace)
                };
                _streams.AddRange(collection.Take(_configuration.TableCount));
                foreach (var stream in _streams)
                {
                    stream.Queried  += () => Open(stream.StreamIndex);
                    stream.Faulted  += ex => OnError(stream.StreamIndex, ex);
                    stream.Received += (id, messages) => OnReceived(stream.StreamIndex, id, messages);
                    StartReceiving(stream);
                }
            }
            catch (Exception ex)
            {
                _trace.TraceError("Issue", ex);
            }
        }
Пример #22
0
 public void Can_correctly_map_TaskRecord()
 {
     new PersistenceSpecification <TaskRecord>(SessionFactoryBuilder.BuildTestSessionFactory <TaskRecord>().OpenSession())
     .CheckProperty(c => c.Id, 1)
     .CheckProperty(c => c.Title, "John")
     .CheckProperty(c => c.Description, "Some long text testing description")
     .CheckProperty(c => c.Creator, "Doe")
     .VerifyTheMappings();
 }
Пример #23
0
        public static ISessionFactory CreateSessionFactory()
        {
            string             connectionString      = ConnectionStrings.Get();
            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(connectionString));
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration).Build();

            return(sessionFactory);
        }
 public ViewResult DeletePreview(int id)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         return(View(
                    s.Query <Purchased>().Fetch(x => x.Product).ThenFetch(x => x.Category)
                    .Where(x => x.PurchasedId == id).Single()));
     }
 }
 public ActionResult Delete(int PurchasedId)
 {
     using (var s = SessionFactoryBuilder.GetSessionFactory().OpenSession())
     {
         s.Delete(s.Load <Purchased>(PurchasedId));
         s.Flush();
         return(RedirectToAction("Index"));
     }
 }
        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;
        }
Пример #27
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());
        }
        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;
        }
Пример #29
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 void Should_create_the_NHibernate_configuration()
        {
            var builder        = new SessionFactoryBuilder();
            var sessionFactory = builder.GetFactory();

            sessionFactory.ShouldNotBeNull();
            var metadata = sessionFactory.GetClassMetadata(typeof(User));

            metadata.EntityName.Contains(typeof(User).Name).ShouldBeTrue();
        }
        public JsonResult xLookup(string cascaded_word, string q_word, string primary_key, int per_page, int page_num)
        {
            using (var svc = SessionFactoryBuilder.GetSessionFactory().OpenSession())
            {
                int categoryId = 0;

                bool isNumber = int.TryParse(cascaded_word, out categoryId);



                var FilteredProduct = svc.Query <Product>()
                                      .Where(x =>
                                             (

                                                 categoryId == 0
                                                 ||
                                                 (categoryId != 0 && x.Category.CategoryId == categoryId)

                                             )

                                             &&

                                             (q_word == "" || x.ProductName.Contains(q_word))

                                             );


                var PagedFilter = FilteredProduct.OrderBy(x => x.ProductName)
                                  .LimitAndOffset(per_page, page_num)
                                  .Fetch(x => x.Category)
                                  .ToList();

                return(Json(
                           new
                {
                    cnt = FilteredProduct.Count()

                    , primary_key = PagedFilter.Select(x => x.ProductId)

                    , candidate = PagedFilter.Select(x => x.ProductName)

                    , cnt_page = PagedFilter.Count()

                    , attached = PagedFilter.Select(x =>
                                                    new[]
                    {
                        new string[] { "Product Code", x.ProductCode },
                        new string[] { "Category Code", x.Category.CategoryCode },
                        new string[] { "Category", x.Category.CategoryName }
                    }
                                                    )
                }
                           ));
            } //using
        }     //CascadedFromCategoryLookup
        public static bool CreateOrder(int customerId, int addressId)
        {
            decimal totalPrice = 0;

            try
            {
                using (var session = SessionFactoryBuilder.OpenSession())
                {
                    var cartList = session.QueryOver <Cart>().Where(x => x.CustomerId == customerId && x.Status == 1).List();
                    foreach (var cartItem in cartList)
                    {
                        Order orderObj = new Order();
                        orderObj.CustomerId = customerId;
                        orderObj.ProductId  = cartItem.ProductId;
                        orderObj.UnitPrice  = cartItem.UnitPrice;
                        if (cartItem.Quantity > 1)
                        {
                            orderObj.TotalPrice = cartItem.Quantity * cartItem.UnitPrice;
                        }
                        else
                        {
                            orderObj.TotalPrice = cartItem.UnitPrice;
                        }
                        orderObj.Status         = 1;//sipariş tamamlandı.
                        orderObj.AddressId      = addressId;
                        orderObj.InsertDatetime = System.DateTime.Now;
                        session.Save(orderObj);
                        session.Clear();
                        cartItem.Status = 0;
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            session.Clear();
                            session.SaveOrUpdate(cartItem);
                            transaction.Commit();
                        }
                        totalPrice += orderObj.UnitPrice;
                    }

                    var couponList = session.QueryOver <Coupon>().Where(x => x.CustomerId == customerId && x.Status == 1).List();
                    if (couponList.Count > 0)
                    {
                        totalPrice = totalPrice - (totalPrice * couponList[0].Discount / 100); //CartDetail tablosu yapılarak toplam fiyattan düşülebilir.
                    }
                }
                return(true); //json formatında dönülecek
            }
            catch (Exception ex)
            {
                //rollback yapılacak.
                //log atılacak.
                //json formatında dönülecek
                return(false);
            }
        }
        public void Should_store_session_factory_in_singleton()
        {
            var builder  = new SessionFactoryBuilder();
            var factory1 = builder.GetFactory();

            factory1.ShouldNotBeNull();

            var factory2 = builder.GetFactory();

            ReferenceEquals(factory1, factory2).ShouldBeTrue();
        }
        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 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));
        }
Пример #36
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;
        }
Пример #37
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);
        }
Пример #38
0
        private void CreateDatabase()
        {
            var builder = new SessionFactoryBuilder();

            this.database = new DatabaseAccessLayer(builder);

            this.database.Initalize(Schema.Rebuild);
        }
        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;
        }