コード例 #1
0
        public Boolean SyncronizeDatabases(ConnectionData gold, ConnectionData toUpdate, bool continueOnFailure)
        {
            DatabaseDiffer diff = new DatabaseDiffer();


            DatabaseRunHistory toBeRun = diff.GetDatabaseHistoryDifference(gold, toUpdate);

            PushInfo(string.Format("{0} database packages found to run on {1}.{2}", toBeRun.BuildFileHistory.Count, toUpdate.SQLServerName, toUpdate.DatabaseName));

            if (toBeRun.BuildFileHistory.Count == 0) //already in sync
            {
                return(true);
            }

            //Make temp directory for rebuild packages...
            string tempPath = System.IO.Path.GetTempPath() + System.Guid.NewGuid();

            Directory.CreateDirectory(tempPath);
            List <string> rebuiltPackages = new List <string>();

            //Create SBM packages for each
            foreach (var buildFileHistory in toBeRun.BuildFileHistory)
            {
                PushInfo(string.Format("Rebuilding Package {0} (Hash:{1})", buildFileHistory.BuildFileName, buildFileHistory.BuildFileHash));

                var fileName    = tempPath + "\\" + Path.GetFileNameWithoutExtension(buildFileHistory.BuildFileName) + ".sbm"; //Make sure it creates and SBM and not an SBX
                var rebuildData = Rebuilder.RetreiveBuildData(gold, buildFileHistory.BuildFileHash, buildFileHistory.CommitDate);
                rebuildData.ForEach(h => h.ScriptFileName = Path.GetFileName(h.ScriptFileName));                               //trim off the path, we just want the file name

                bool success = Rebuilder.RebuildBuildManagerFile(500, fileName, rebuildData);
                if (!success)
                {
                    PushInfo(string.Format("Error creating package {0} (Hash:{1}) see error log for details.", buildFileHistory.BuildFileName, buildFileHistory.BuildFileHash));
                    ProcessDirectoryCleanup(tempPath);
                    return(false);
                }
                rebuiltPackages.Add(fileName);
            }

            bool syncronized = ProcessSyncronizationPackages(rebuiltPackages, toUpdate, false, continueOnFailure);

            if (syncronized)
            {
                PushInfo(string.Format("Syncronized database {0}.{1} to source {2}.{3}", toUpdate.SQLServerName,
                                       toUpdate.DatabaseName, gold.SQLServerName, gold.DatabaseName));
            }
            else
            {
                PushInfo(string.Format("Syncronize failed to {0}.{1} from source {2}.{3}. See log for details.", toUpdate.SQLServerName,
                                       toUpdate.DatabaseName, gold.SQLServerName, gold.DatabaseName));
            }
            ProcessDirectoryCleanup(tempPath);

            return(syncronized);
        }