Exemplo n.º 1
0
        internal static bool RebuildBuildManagerFile(int defaultTimeout, string buildFileName, List <RebuilderData> rebuildData)
        {
            string tempPath = System.IO.Path.GetTempPath() + System.Guid.NewGuid();

            Directory.CreateDirectory(tempPath);
            try
            {
                string projFileName = Path.Combine(tempPath, SqlSync.SqlBuild.XmlFileNames.MainProjectFile);

                for (int i = 0; i < rebuildData.Count; i++)
                {
                    File.WriteAllText(Path.Combine(tempPath, rebuildData[i].ScriptFileName), rebuildData[i].ScriptText);
                }

                SqlSyncBuildData buildData = SqlBuildFileHelper.CreateShellSqlSyncBuildDataObject();
                buildData.AcceptChanges();

                if (!SqlBuildFileHelper.PackageProjectFileIntoZip(buildData, tempPath, buildFileName))
                {
                    return(false);
                }

                if (!ZipHelper.UnpackZipPackage(tempPath, buildFileName, false))
                {
                    return(false);
                }

                for (int i = 0; i < rebuildData.Count; i++)
                {
                    SqlBuildFileHelper.AddScriptFileToBuild(ref buildData,
                                                            projFileName,
                                                            rebuildData[i].ScriptFileName,
                                                            rebuildData[i].Sequence + 1,
                                                            string.Empty,
                                                            true,
                                                            true,
                                                            rebuildData[i].Database,
                                                            false,
                                                            buildFileName,
                                                            false,
                                                            false,
                                                            System.Environment.UserName,
                                                            defaultTimeout,
                                                            rebuildData[i].ScriptId,
                                                            rebuildData[i].Tag);
                }

                SqlBuildFileHelper.SaveSqlBuildProjectFile(ref buildData, projFileName, buildFileName);

                return(true);
            }
            finally
            {
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
        }