コード例 #1
0
ファイル: Program.cs プロジェクト: robrich/NAntTasks
        public static int Main( string[] args )
        {
            string basePath = new Uri( Assembly.GetExecutingAssembly().CodeBase ).LocalPath;
            string migrationFilesSourcePath = null;
            DatabaseInfo databaseInfo = new DatabaseInfo();
            string currentAppVersion = null;
            string migrationScriptFile = null;
            bool wait = false;
            bool verbose = false;
            bool showHelp = false;

            var arguments = new List<ArgParameter> {
                new ArgParameter( "migrationFilesSourcePath", v => migrationFilesSourcePath = v.FirstOrDefault() ),
                new ArgParameter( "connectionStringSource", v => databaseInfo.ConnectionStringSource = v.FirstOrDefault() ),
                new ArgParameter( "server", "S", v => databaseInfo.Server = v.FirstOrDefault() ),
                new ArgParameter( "database", "d", v => databaseInfo.Database = v.FirstOrDefault() ),
                new ArgParameter( "username", "U", v => databaseInfo.Username = v.FirstOrDefault() ),
                new ArgParameter( "password", "P", v => databaseInfo.Password = v.FirstOrDefault() ),
                new ArgParameter( "trustedConnection", "E", v => databaseInfo.TrustedConnection = true ),
                new ArgParameter( "currentAppVersion", v => currentAppVersion = v.FirstOrDefault() ),
                new ArgParameter( "migrationScriptFile", v => migrationScriptFile = v.FirstOrDefault() ),
                new ArgParameter( "wait", "w", v => wait = true ),
                new ArgParameter( "verbose", "v", v => verbose = true ),
                new ArgParameter( "help", "?", v => showHelp = true )
            };

            int matchedArgs = CommandLineParser.ParseCommandLineArguments( args, arguments );
            if ( matchedArgs != args.Length ) {
                showHelp = true;
            }

            if ( showHelp ) {
                string helpContent = CommandLineParser.GetHelpText( arguments );
                Console.WriteLine( "NAnt.DbMigrations.Tasks" );
                Console.Write( helpContent );
                return (int)ExitReason.InvalidArguments;
            }

            ILogger logger = new ConsoleLogger();

            // Lame DI solution here to avoid multiple dll dependencies for this tool
            IHashCalculator hashCalculator = new HashCalculator();
            ISqlHelper sqlHelper = new SqlHelper();
            IConfigRepository configRepository = new ConfigRepository();
            IMigrationDbRepository migrationDbRepository = new MigrationDbRepository( sqlHelper );
            IMigrationFileRepository migrationFileRepository = new MigrationFileRepository();
            ISqlCmdHelper sqlCmdHelper = new SqlCmdHelper( sqlHelper );
            IMigrationOutputFileRepository migrationOutputFileRepository = new MigrationOutputFileRepository();
            IMigrationFileParser migrationFileParser = new MigrationFileParser();
            IMigrationFileService migrationFileService = new MigrationFileService( hashCalculator, migrationFileRepository, migrationFileParser );
            IConnectionStringService connectionStringService = new ConnectionStringService( configRepository );
            IPathService pathService = new PathService();
            App app = new App( logger, migrationDbRepository, migrationFileRepository, sqlCmdHelper, migrationOutputFileRepository, migrationFileService, connectionStringService, pathService );

            ExitReason result = app.RunMigrations( basePath, verbose, migrationFilesSourcePath, databaseInfo, currentAppVersion, migrationScriptFile );

            if ( wait ) {
                Console.WriteLine( "Migration complete, push any key to exit" );
                Console.ReadKey();
            }
            return (int)result;
        }
コード例 #2
0
ファイル: NantTask.cs プロジェクト: robrich/NAntTasks
        protected override void ExecuteTask()
        {
            ILogger logger = new ActionLogger( this.Log );

            // Lame DI solution here to avoid multiple dll dependencies for this tool
            IHashCalculator hashCalculator = new HashCalculator();
            ISqlHelper sqlHelper = new SqlHelper();
            IConfigRepository configRepository = new ConfigRepository();
            IMigrationDbRepository migrationDbRepository = new MigrationDbRepository( sqlHelper );
            IMigrationFileRepository migrationFileRepository = new MigrationFileRepository();
            ISqlCmdHelper sqlCmdHelper = new SqlCmdHelper( sqlHelper );
            IMigrationOutputFileRepository migrationOutputFileRepository = new MigrationOutputFileRepository();
            IMigrationFileParser migrationFileParser = new MigrationFileParser();
            IMigrationFileService migrationFileService = new MigrationFileService( hashCalculator, migrationFileRepository, migrationFileParser );
            IConnectionStringService connectionStringService = new ConnectionStringService( configRepository );
            IPathService pathService = new PathService();
            App app = new App( logger, migrationDbRepository, migrationFileRepository, sqlCmdHelper, migrationOutputFileRepository, migrationFileService, connectionStringService, pathService );

            DatabaseInfo databaseInfo = new DatabaseInfo {
                ConnectionStringSource = this.ConnectionStringSource,
                Server = this.Server,
                Database = this.Database,
                Username = this.Username,
                Password = this.Password,
                TrustedConnection = this.TrustedConnection
            };

            ExitReason result = app.RunMigrations( this.Project.BaseDirectory, this.Verbose, this.MigrationFilesSourcePath, databaseInfo, this.CurrentAppVersion, this.MigrationScriptFile );

            if ( this.FailOnError && result != ExitReason.Success ) {
                throw new BuildException( "Error in db-migration: "+result.ToString() );
            }
        }