コード例 #1
0
        public IMigrator CreateMigrator(Assembly assembly, string scope, int version)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            if (ConfigurationManager.ConnectionStrings[ConnStrName] == null)
            {
                throw new Exception(ConnStrName + " connection string configuration not found.");
            }

            var connstr = ConfigurationManager.ConnectionStrings[ConnStrName].ConnectionString;

            var config = new StaticMigratorConfiguration {ConnectionString = connstr, CommandTimeout = 300};

            IConnectionProvider connProvider = new SQLiteConnectionProvider(config);
            ITransactionProvider transProvider = new TransactionProvider(connProvider);
            IDatabaseProvider dbProvider = new SQLiteDatabaseProvider(connProvider, transProvider, config);
            ISchemaProvider schemaProvider = new SQLiteSchemaProvider(dbProvider);

            ISchemaStateManager schemaStateManager = new SQLiteSchemaStateManager(dbProvider, schemaProvider);
            IVersionStateFactory versionStateFactory = new SQLiteVersionStateFactory(config, schemaStateManager);

            IMigrationFinder finder = new AssemblyMigrationFinder(assembly);

            IMigrationSelector selector = new MigrationSelector(finder, versionStateFactory);

            IMigrationFactoryChooser chooser = new WindsorBasedFactoryChooser(kernel);
            ICommonTransformations common = new CommonTransformations(dbProvider, schemaProvider);

            IMigrationInitializer initializer = new MigrationInitializer(config, dbProvider, schemaProvider, common, connProvider);
            IMigrationRunner runner = new MigrationRunner(chooser, initializer, schemaStateManager, config, transProvider);
            IWorkingDirectoryManager workDirMng = new NoOpWorkingDirectoryManager();

            IMigrator migrator = new Migrator(selector, runner, dbProvider, schemaStateManager, workDirMng);

            //MigrationScope migrationScope = null;
            migrator.Start += delegate {  };
            migrator.End += delegate {  };

            return migrator;
        }
コード例 #2
0
        public IMigrator CreateMigrator(Assembly assembly, string scope, ISession session)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }

            var config = new StaticMigratorConfiguration();
            config.Scope = scope;

            INHibernateSessionProvider hibernateSessionProvider = new StaticNHibernateSessionProvider(session);

            IConnectionProvider connProvider = new NHibernateConnectionProvider(hibernateSessionProvider);
            ITransactionProvider transProvider = new NHibernateTransactionProvider(hibernateSessionProvider);
            IDatabaseProvider dbProvider = new SQLiteDatabaseProvider(connProvider, transProvider, config);
            ISchemaProvider schemaProvider = new SQLiteSchemaProvider(dbProvider);

            ISchemaStateManager schemaStateManager = new SQLiteSchemaStateManager(dbProvider, schemaProvider);
            IVersionStateFactory versionStateFactory = new SQLiteVersionStateFactory(config, schemaStateManager);

            IMigrationFinder finder = new AssemblyMigrationFinder(assembly);

            IMigrationSelector selector = new MigrationSelector(finder, versionStateFactory);

            IMigrationFactoryChooser chooser = new WindsorBasedFactoryChooser(kernel);
            ICommonTransformations common = new CommonTransformations(dbProvider, schemaProvider);

            IMigrationInitializer initializer = new MigrationInitializer(config, dbProvider, schemaProvider, common,
                                                                            connProvider);
            IMigrationRunner runner = new MigrationRunner(chooser, initializer, schemaStateManager, config,
                                                            transProvider);
            IWorkingDirectoryManager workDirMng = new NoOpWorkingDirectoryManager();

            IMigrator migrator = new Migrator(selector, runner, dbProvider, schemaStateManager, workDirMng);

            //MigrationScope migrationScope = null;

            migrator.Start += delegate {  };
            migrator.End += delegate { };

            return migrator;
        }