internal void Deploy(Deployment deployment) { string errors = ""; try { Logger.Log(" - Deploying " + deployment.Name + " ----------- ", LogSeverities.Info); //Collect files to be deployed List <Deployable> deployables = new List <Deployable>(); foreach (Tool tool in deployment.Tools) { List <Deployable> toDeploy = tool.IsScript ? tool.SourceFiles : tool.OutputFiles; foreach (Deployable file in toDeploy) { deployables.Add(file); } //Add the packages (folders) if we have a compiled tool if (!tool.IsScript) { foreach (Deployable deployable in tool.SourceFiles) { if (!deployable.IsFile) { deployables.Add(deployable); } } } } //Get Output DirectoryInfo OutputInfo = new DirectoryInfo(deployment.OutputPath); if (OutputInfo.Exists) { string confirmation = ""; if (OutputInfo.GetDirectories().Count() > 0) { confirmation = "Your output directory is not supposed to have subdirectories\n"; } if (OutputInfo.GetFiles().Count() > deployables.Count * 2) { confirmation += "Your output directory contains much more files than your deployment\n"; } if (!string.IsNullOrEmpty(confirmation)) { DialogResult rslt = MessageBox.Show(confirmation + "Are you sure you want to remove folder " + deployment.OutputPath + " ?", "Check output folder", MessageBoxButtons.YesNoCancel); if (rslt == DialogResult.Cancel) { errors += "Output folder is not empty, deployment aborted by user"; return; } else { if (rslt == DialogResult.Yes) { OutputInfo.Delete(true); Logger.Log(OutputInfo.FullName + " deleted (confirmed by user).", LogSeverities.Log); } } } else { OutputInfo.Delete(true); Logger.Log(OutputInfo.FullName + " deleted.", LogSeverities.Log); } } // *** CopyLibrairies *** if (deployment.ExternalLibrary != "" && deployment.ExternalLibraryOut != "") { DirectoryInfo ExternalLibraryInfo = new DirectoryInfo(deployment.ExternalLibrary); if (!ExternalLibraryInfo.Exists) { errors += "Library " + ExternalLibraryInfo.FullName + " not found !\n"; } else { DirectoryInfo ExternalLibraryOutInfo = new DirectoryInfo(deployment.ExternalLibraryOut); if (ExternalLibraryOutInfo.Exists) { ExternalLibraryOutInfo.Delete(true); Logger.Log(ExternalLibraryOutInfo.FullName + " deleted.", LogSeverities.Log); } CreateDirectory(ExternalLibraryOutInfo); CopyFolder(ExternalLibraryInfo.FullName, ExternalLibraryOutInfo.FullName); Logger.Log(ExternalLibraryInfo.FullName + " copied to " + ExternalLibraryOutInfo.FullName, LogSeverities.Log); } } // *** Update Release Infos *** if (deployment.ReleaseInfoPath != "") { FileInfo releaseInfo = new FileInfo(deployment.ReleaseInfoPath); if (releaseInfo.Exists) { Logger.Log("Release Info will be updated", LogSeverities.Log); ReleaseInfo newInfo = new ReleaseInfo(); newInfo.LoadFromFile(deployment.ReleaseInfoPath); newInfo.sBuildDate = DateTime.Now.ToString("yyyy-MM-dd", null); if (deployment.Company != "") { newInfo.Company = deployment.Company; Logger.Log("Company changed to " + newInfo.Company, LogSeverities.Log); } if (deployment.Host != "") { newInfo.Host = deployment.Host; Logger.Log("Host changed to " + newInfo.Host, LogSeverities.Log); } if (deployment.Length != 0) { newInfo.Length = deployment.Length; Logger.Log("Length changed to " + newInfo.Length, LogSeverities.Log); } newInfo.Save(deployment.ReleaseInfoPath); } else { errors += "ReleaseInfos " + releaseInfo.FullName + " not found !\n"; } } // *** Build *** List <Tool> toolsToBuild = new List <Tool>(); List <string> builderPaths = new List <string>(); foreach (Tool tool in deployment.Tools) { if (!tool.IsScript && tool.BuilderFile.Path != "" && !builderPaths.Contains(tool.BuilderFile.Path)) { toolsToBuild.Add(tool); builderPaths.Add(tool.BuilderFile.Path); } } foreach (Tool tool in toolsToBuild) { FileInfo buildInfo = new FileInfo(tool.BuilderFile.Path); if (buildInfo.Exists) { //Determine if Building is obsolete //TODO : check sources modification date (and Librairies change...) //Let's rebuild anyway for now... bool needRebuild = true; DateTime buildDate = buildInfo.LastWriteTime; foreach (Deployable file in tool.OutputFiles) { FileInfo info = new FileInfo(deployment.ReplaceWildCards(tool, file.Path)); if (info.Exists) { if (info.LastWriteTime < buildDate) { needRebuild = true; break; } } } if (needRebuild) { Logger.Log(tool.Name + " is obsolete, rebuild !", LogSeverities.Log); string Configuration = deployment.Configuration.ToString(); string Platform = tool.Platform != "" ? tool.Platform : deployment.Platform.ToString(); if (Platform == "Any_CPU") { Platform = "Any CPU"; } execute("C:\\Windows\\Microsoft.NET\\Framework\\v3.5", "MSBuild.exe", "\"" + buildInfo.FullName + "\" /t:rebuild /p:Configuration=\"" + Configuration + "\" /p:Platform=\"" + Platform + "\""); } else { Logger.Log(tool.Name + " is up to date", LogSeverities.Log); } } else { errors += "Buildable " + buildInfo.FullName + " not found !\n"; } } // *** Publish *** OutputInfo = new DirectoryInfo(deployment.OutputPath); CreateDirectory(OutputInfo); foreach (Tool tool in deployment.Tools) { List <Deployable> toDeploy = new List <Deployable>(tool.IsScript ? tool.SourceFiles : tool.OutputFiles); //Add the packages (folders) if we have a compiled tool if (!tool.IsScript) { foreach (Deployable deployable in tool.SourceFiles) { if (!deployable.IsFile) { toDeploy.Add(deployable); } } } foreach (Deployable file in toDeploy) { //File if (file.IsFile) { FileInfo info = new FileInfo(deployment.ReplaceWildCards(tool, file.Path)); if (info.Exists) { string outFileName = OutputInfo.FullName + "\\" + info.Name; info.CopyTo(outFileName, true); Logger.Log(tool.Name + " copied to " + outFileName, LogSeverities.Log); } else { errors += "Tool " + tool.Name + ", " + info.FullName + " file not found !\n"; } } else { //Folder (package) DirectoryInfo info = new DirectoryInfo(deployment.ReplaceWildCards(tool, file.Path)); if (info.Exists) { string outFileName = OutputInfo.FullName + "\\" + info.Name; DirectoryInfo OutInfo = new DirectoryInfo(outFileName); CreateDirectory(OutInfo); CopyFolder(info.FullName, OutInfo.FullName); Logger.Log(info.FullName + " copied to " + OutInfo.FullName, LogSeverities.Log); } else { errors += "Tool " + tool.Name + ", " + info.FullName + " folder not found !\n"; } } } } if (errors == "") { Logger.Log(" - Deploy " + deployment.Name + " successfull --", LogSeverities.Info); } else { Logger.Log("Deployment error(s) : " + errors, LogSeverities.Error); } } catch (Exception e) { Logger.Log("Deployment error(s) : " + errors + "\n" + e.Message, LogSeverities.Error); } }