private void BackoutPackageForm_Load(object sender, EventArgs e)
        {
            try
            {
                SqlBuildFileHelper.GetFileDataForObjectUpdates(ref this.sourceBuildData, this.extractedProjectFile, out initialCanUpdateList, out manualScriptsCanNotUpdate);

                string pleaseSelect = "[Please select a {0} via Action --> Change SQL Server Connection menu]";
                lblDatabaseSetting.Text = this.connData.DatabaseName;
                lblServerSetting.Text   = this.connData.SQLServerName;

                if (lblDatabaseSetting.Text.Length == 0)
                {
                    lblDatabaseSetting.Text = String.Format(pleaseSelect, "database");
                }

                if (lblServerSetting.Text.Length == 0)
                {
                    lblServerSetting.Text = String.Format(pleaseSelect, "server");
                }

                txtBackoutPackage.Text = BackoutPackage.GetDefaultPackageName(this.sourceSbmFullFileName);

                SetSourceServerAndDatabase(this.connData.SQLServerName, this.connData.DatabaseName);

                if (this.connData.SQLServerName.Length > 0 && this.connData.DatabaseName.Length > 0 && !this.bgCheckTargetObjects.IsBusy)
                {
                    bgCheckTargetObjects.RunWorkerAsync(new string[] { this.connData.SQLServerName, this.connData.DatabaseName });
                }
                else
                {
                    BindListViews(this.initialCanUpdateList, this.notPresentOnTarget, this.manualScriptsCanNotUpdate);
                }
            }
            catch (Exception exe)
            {
                log.LogError(exe, "Error loading the Backout Package form");
                MessageBox.Show("Error loading form. Please see log file for details", "Whoops!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                this.bgCheckTargetObjects = null;
                this.bgMakeBackout        = null;
                this.Close();
            }
        }
예제 #2
0
        /// <summary>
        /// This method should only really be used with a command line, unattended execution.
        /// </summary>
        /// <param name="connData"></param>
        /// <param name="objectUpdates"></param>
        /// <param name="dontUpdate"></param>
        /// <param name="manualScriptsCanNotUpdate"></param>
        /// <param name="sourceBuildZipFileName"></param>
        /// <param name="sourceServer"></param>
        /// <param name="sourceDb"></param>
        /// <returns></returns>
        public static string CreateDefaultBackoutPackage(ConnectionData connData, string sourceBuildZipFileName, string sourceServer, string sourceDb)
        {
            /*How to create a backout package:
             *
             * 1. Extract the package and load the BuildData
             * 2. Get the list of sriptable objects and manually created scripts
             * 3. Targeting your "old" source, and see what scriptable objects are not there (i.e. are "new" in the package)
             *
             */
            List <string>        manualScriptsCanNotUpdate;
            List <ObjectUpdates> initialCanUpdateList;
            string           workingDirectory = string.Empty;
            string           projectFilePath  = string.Empty;
            string           projectFileName  = string.Empty;
            string           result;
            SqlSyncBuildData buildData;
            BackgroundWorker bg = new BackgroundWorker();

            bg.WorkerReportsProgress = true;

            //Extract and load the build data...
            log.LogDebug($"Extracting SBM zip file for {sourceBuildZipFileName}");
            bool success = SqlBuildFileHelper.ExtractSqlBuildZipFile(sourceBuildZipFileName, ref workingDirectory, ref projectFilePath, ref projectFileName, out result);

            if (success)
            {
                log.LogDebug($"Loading SqlSyncBuldData object from {projectFileName}");
                success = SqlBuildFileHelper.LoadSqlBuildProjectFile(out buildData, projectFileName, false);
                if (!success)
                {
                    return(string.Empty);
                }
            }
            else
            {
                return(string.Empty);
            }

            //Get the scriptable objects
            log.LogDebug($"Getting the scriptable objects from {sourceBuildZipFileName}");
            SqlBuildFileHelper.GetFileDataForObjectUpdates(ref buildData, projectFileName, out initialCanUpdateList, out manualScriptsCanNotUpdate);

            //Get object that are also on the target (ie are "existing") -- only these will be updated
            log.LogDebug($"Getting list of objects can be rolled back from {sourceServer}:{sourceDb}");
            List <ObjectUpdates> canUpdate = GetObjectThatCanBeUpdated(initialCanUpdateList, connData, sourceServer, sourceDb);

            SetBackoutSourceDatabaseAndServer(ref canUpdate, sourceServer, sourceDb);

            //Get the scriptable objects that are not found on the target (i.e. are "new") -- these will be dropped
            log.LogDebug($"Getting list of objects can not be rolled back from {sourceServer}:{sourceDb}");
            List <ObjectUpdates> notPresentOnTarget = GetObjectsNotPresentTargetDatabase(initialCanUpdateList, connData, sourceServer, sourceDb);

            //Get the name of the new package
            string backoutPackageName = GetDefaultPackageName(sourceBuildZipFileName);

            //Create the package!!
            log.LogDebug($"Creating backout package {backoutPackageName} from source package {sourceBuildZipFileName}");
            success = CreateBackoutPackage(connData, canUpdate, notPresentOnTarget, manualScriptsCanNotUpdate,
                                           sourceBuildZipFileName, backoutPackageName,
                                           sourceServer, sourceDb, true, true, true, ref bg);

            //Cleanup all the temp files created
            SqlBuildFileHelper.CleanUpAndDeleteWorkingDirectory(workingDirectory);

            if (!success)
            {
                log.LogError("Unable to create backout package!");
                return(string.Empty);
            }

            return(backoutPackageName);
        }