示例#1
0
文件: ApplyTask.cs 项目: defize/Gus
        public bool Execute(ApplyTaskConfiguration configuration, GusTaskExecutionContext context)
        {
            var databaseHelper = new DatabaseHelper(context);
            var fileSystemHelper = new FileSystemHelper(context);

            var connection = databaseHelper.CreateAndOpenConnection(configuration.Server);
            if (connection == null)
            {
                return false;
            }

            var serverConnection = new ServerConnection(connection);
            var server = new Server(serverConnection);

            var database = databaseHelper.InitializeDatabase(server, configuration.Database, configuration.CreateDatabaseIfMissing, configuration.CreateDatabaseIfMissing || configuration.CreateManagementSchemaIfMissing);
            if (database == null)
            {
                return false;
            }

            context.RaiseExecutionEvent("Determining scripts to apply.");
            var scriptsToApply = GetScriptsToApply(configuration.SourcePath, database, databaseHelper, fileSystemHelper);
            if (scriptsToApply == null)
            {
                return false;
            }

            context.ExecutionStepCount = (uint)scriptsToApply.Count;
            context.RaiseExecutionEvent(string.Format("Found {0} scripts to apply.", scriptsToApply.Count));

            var success = ApplyScripts(scriptsToApply, server, database, databaseHelper, fileSystemHelper, configuration.RecordOnly, context, configuration.HaltOnError);

            return success;
        }
示例#2
0
文件: StatusTask.cs 项目: defize/Gus
        public bool Execute(StatusTaskConfiguration configuration, GusTaskExecutionContext context)
        {
            var databaseHelper = new DatabaseHelper(context);
            var fileSystemHelper = new FileSystemHelper(context);

            var connection = databaseHelper.CreateAndOpenConnection(configuration.Server);
            if (connection == null)
            {
                return false;
            }

            var serverConnection = new ServerConnection(connection);
            var server = new Server(serverConnection);

            var database = databaseHelper.InitializeDatabase(server, configuration.Database, false, false);
            if (database == null)
            {
                return false;
            }

            context.RaiseExecutionEvent("Determining scripts not yet applied.");
            var scriptsToApply = GetScriptsToApply(configuration.SourcePath, database, databaseHelper, fileSystemHelper);
            if (scriptsToApply == null)
            {
                return false;
            }

            context.ExecutionStepCount = (uint)scriptsToApply.Count;
            context.RaiseExecutionEvent(string.Format("Found {0} scripts not yet applied.", scriptsToApply.Count));

            foreach (var script in scriptsToApply)
            {
                context.RaiseExecutionEvent(ExecutionEventType.Default, script.Name);
            }

            return true;
        }