Exemplo n.º 1
0
        public async Task SetUp()
        {
            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(SagaTypes);

            var sagaDataTypes = new List <Type>();

            using (var enumerator = metaModel.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    sagaDataTypes.Add(enumerator.Current.SagaEntityType);
                }
            }

            sagaDataTypes.Add(typeof(ContainSagaData));

            SagaModelMapper.AddMappings(cfg, metaModel, sagaDataTypes);
            SessionFactory = cfg.BuildSessionFactory();

            schema = new SchemaExport(cfg);
            await schema.CreateAsync(false, true);

            SagaPersister = new SagaPersister();
        }
Exemplo n.º 2
0
        SagaMetadataCollection GetModel(params Type[] types)
        {
            var sagaMetaModel = new SagaMetadataCollection();

            sagaMetaModel.Initialize(types.ToList(), new Conventions());
            return(sagaMetaModel);
        }
        public void SetUp()
        {
            var builder    = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var settings      = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();
            var types     = new [] { typeof(TestSaga), typeof(TestSagaData), typeof(TestComponent), typeof(PolymorphicPropertyBase),
                                     typeof(AlsoDerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(AlsoDerivedFromTestSagaWithTableNameAttribute),
                                     typeof(DerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(DerivedFromTestSagaWithTableNameAttribute),
                                     typeof(TestSagaWithTableNameAttributeActualSaga), typeof(TestSagaWithTableNameAttribute),
                                     typeof(SagaWithVersionedPropertyAttributeActualSaga), typeof(SagaWithVersionedPropertyAttribute),
                                     typeof(SagaWithoutVersionedPropertyAttributeActualSaga), typeof(SagaWithoutVersionedPropertyAttribute),
                                     typeof(object) };

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, configuration);
            sessionFactory = configuration.BuildSessionFactory() as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSagaData>();
        }
        /// <summary>
        /// Generates the table creation script for the saga data table
        /// </summary>
        /// <param name="tableNamingConvention">Optional custom table naming convention.</param>
        /// <typeparam name="TSaga">Saga type.</typeparam>
        public static string GenerateSagaScript <TSaga>(Func <Type, string> tableNamingConvention = null)
            where TSaga : Saga
        {
            var sagaBase     = typeof(TSaga).BaseType;
            var sagaDataType = sagaBase.GetGenericArguments()[0];

            var metadata = new SagaMetadataCollection();

            metadata.Initialize(new[]
            {
                typeof(TSaga)
            });
            var typesToScan = new List <Type>
            {
                sagaDataType
            };
            var sagaDataBase = sagaDataType.BaseType;

            while (sagaDataBase != null)
            {
                typesToScan.Add(sagaDataBase);
                sagaDataBase = sagaDataBase.BaseType;
            }

            var config = new Configuration();

            config.DataBaseIntegration(db => { db.Dialect <T>(); });
            SagaModelMapper.AddMappings(config, metadata, typesToScan, tableNamingConvention);
            return(GenerateScript(config));
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            ConnectionString = $@"Data Source={Path.GetTempFileName()};New=True;";

            var configuration = new global::NHibernate.Cfg.Configuration()
                                .AddProperties(new Dictionary <string, string>
            {
                { "dialect", dialect },
                { global::NHibernate.Cfg.Environment.ConnectionString, ConnectionString }
            });

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(new[] { typeof(T) });
            var metadata = metaModel.Find(typeof(T));

            var modelMapper = new SagaModelMapper(metaModel, new[] { metadata.SagaEntityType });

            configuration.AddMapping(modelMapper.Compile());

            SessionFactory = configuration.BuildSessionFactory();

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

            SagaPersister = new SagaPersister();
        }
        public void SetUp()
        {
            ConnectionString = $"Data Source={Path.GetTempFileName()};New=True;";

            var configuration = new Configuration()
                                .AddProperties(new Dictionary <string, string>
            {
                { "dialect", dialect },
                { Environment.ConnectionString, ConnectionString }
            });

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(SagaTypes);

            var sagaDataTypes = new List <Type>();

            using (var enumerator = metaModel.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    sagaDataTypes.Add(enumerator.Current.SagaEntityType);
                }
            }

            sagaDataTypes.Add(typeof(ContainSagaData));

            SagaModelMapper.AddMappings(configuration, metaModel, sagaDataTypes);
            SessionFactory = configuration.BuildSessionFactory();

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

            SagaPersister = new SagaPersister();
        }
Exemplo n.º 7
0
        public void SetUp()
        {
            var builder = new NHibernateSagaStorage();

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var types = new[] { typeof(SagaWithAbstractBaseClassActualSaga), typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) };

            var allMetadata = new SagaMetadataCollection();

            allMetadata.Initialize(types);

            var settings = new SettingsHolder();

            settings.Set("TypesToScan", types);
            settings.Set <SagaMetadataCollection>(allMetadata);

            builder.ApplyMappings(settings, cfg);
            sessionFactory = cfg.BuildSessionFactory() as SessionFactoryImpl;
        }
        public void SetUp()
        {
            var builder = new NHibernateSagaStorage();

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var settings = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();
            var types     = new [] { typeof(TestSaga), typeof(TestSagaData), typeof(TestComponent), typeof(PolymorphicPropertyBase),
                                     typeof(AlsoDerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(AlsoDerivedFromTestSagaWithTableNameAttribute),
                                     typeof(DerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(DerivedFromTestSagaWithTableNameAttribute),
                                     typeof(TestSagaWithTableNameAttributeActualSaga), typeof(TestSagaWithTableNameAttribute),
                                     typeof(SagaWithVersionedPropertyAttributeActualSaga), typeof(SagaWithVersionedPropertyAttribute),
                                     typeof(SagaWithoutVersionedPropertyAttributeActualSaga), typeof(SagaWithoutVersionedPropertyAttribute),
                                     typeof(object) };

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, cfg);
            sessionFactory = cfg.BuildSessionFactory() as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSagaData>();
        }
        public static SessionFactoryImpl Build(Type[] types)
        {
            var builder    = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var settings      = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, configuration);
            return(configuration.BuildSessionFactory() as SessionFactoryImpl);
        }
    SagaPersister SetUp(string endpointName, string theSchema)
    {
        var runtimeSqlDialect = sqlDialect.Convert(theSchema);

        var sagaMetadataCollection = new SagaMetadataCollection();

        sagaMetadataCollection.Initialize(GetSagasAndFinders());

        var infoCache = new SagaInfoCache(
            versionSpecificSettings: null,
            jsonSerializer: Serializer.JsonSerializer,
            readerCreator: reader => new JsonTextReader(reader),
            writerCreator: writer => new JsonTextWriter(writer),
            tablePrefix: $"{endpointName}_",
            sqlDialect: runtimeSqlDialect,
            metadataCollection: sagaMetadataCollection,
            nameFilter: sagaName => sagaName);

        return(new SagaPersister(infoCache, runtimeSqlDialect));
    }
Exemplo n.º 11
0
        public void SetUp()
        {
            var builder    = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var types         = new[] { typeof(SagaWithAbstractBaseClassActualSaga), typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) };

            var allMetadata = new SagaMetadataCollection();

            allMetadata.Initialize(types);

            var settings = new SettingsHolder();

            settings.Set("TypesToScan", types);
            settings.Set <SagaMetadataCollection>(allMetadata);

            builder.ApplyMappings(settings, configuration);
            sessionFactory = configuration.BuildSessionFactory() as SessionFactoryImpl;
        }
Exemplo n.º 12
0
        public static SessionFactoryImpl Build(Type[] types)
        {
            var builder = new NHibernateSagaStorage();

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var settings = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, cfg);
            return(cfg.BuildSessionFactory() as SessionFactoryImpl);
        }
Exemplo n.º 13
0
    static RuntimeSagaInfo BuildSagaInfo <TSaga, TSagaData>(SqlDialect dialect)
        where TSaga : SqlSaga <TSagaData>
        where TSagaData : IContainSagaData, new()
    {
        var sagaMetadataCollection = new SagaMetadataCollection();

        sagaMetadataCollection.Initialize(new[]
        {
            typeof(TSaga)
        });

        var infoCache = new SagaInfoCache(
            null,
            Serializer.JsonSerializer,
            readerCreator: reader => new JsonTextReader(reader),
            writerCreator: writer => new JsonTextWriter(writer),
            tablePrefix: "some",
            sqlDialect: dialect,
            metadataCollection: sagaMetadataCollection,
            nameFilter: sagaName => sagaName);

        return(infoCache.GetInfo(typeof(TSagaData)));
    }
    SagaPersister SetUp(string endpointName)
    {
        var runtimeSqlVariant = sqlVariant.Convert();

#pragma warning disable 618
        var commandBuilder = new SagaCommandBuilder(runtimeSqlVariant);
#pragma warning restore 618

        var sagaMetadataCollection = new SagaMetadataCollection();
        sagaMetadataCollection.Initialize(GetSagasAndFinders());

        var infoCache = new SagaInfoCache(
            versionSpecificSettings: null,
            jsonSerializer: Serializer.JsonSerializer,
            commandBuilder: commandBuilder,
            readerCreator: reader => new JsonTextReader(reader),
            writerCreator: writer => new JsonTextWriter(writer),
            tablePrefix: $"{endpointName}_",
            schema: schema,
            sqlVariant: runtimeSqlVariant,
            metadataCollection: sagaMetadataCollection,
            nameFilter: sagaName => sagaName);
        return(new SagaPersister(infoCache, runtimeSqlVariant));
    }