/// <summary> /// Determines whether [is ydr installed] [the specified configuration]. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns> /// <c>true</c> if [is ydr installed] [the specified configuration]; otherwise, <c>false</c>. /// </returns> public static bool IsYdrInstalled(BuildControlParameters configuration) { string outputFile = Path.Combine(Application.StartupPath, InstallationFileCheckName); string app = Path.Combine(Application.StartupPath, InstallationCheckProgramName); try { string arguments = @"/p"; ProcessInformation process = ProcessOperations.RunProcess(app, Application.StartupPath, arguments, true); string[] contents = process.GetStandardOutput(); if (contents != null) { var ydrInstalled = (from installId in contents where installId.Contains(BuildControlParameters.YdrGuid) select installId).Count(); return(ydrInstalled > 0 ? true : false); } else { ProgramExecutionLog.AddEntry( "No output was returned from the msiinv.exe program"); return(false); } } catch (Exception e) { ProgramExecutionLog.AddEntry( "Failure checking for Installation of Wpdt. Error was " + e.Message); } return(false); }
/// <summary> /// Reverts the build version files. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> private static void RevertBuildVersionFiles( BuildControlParameters configuration, DailyBuildFullResults results) { string heroAppSource = FindHeroAppSourceFolder(configuration); for (Int32 i = 0; i < configuration.Projects.Length; i++) { string assemblyFile = ""; try { string appFolder = Path.Combine(heroAppSource, configuration.Projects[i].ProjectPath); assemblyFile = Path.Combine(appFolder, configuration.Projects[i].AssemblyFilePathAndNameFromProjectRoot); ProcessInformation process = ProcessOperations.SDRevert(configuration, assemblyFile); CheckForErrorFromSDOperation(process, results, results.BuildTargets[i].RevertVersion); results.BuildTargets[i].RevertVersion.Success = true; } catch (Exception e) { ProgramExecutionLog.AddEntry( "Failed to revert file " + assemblyFile + " Exception information was " + e.ToString()); results.BuildTargets[i].RevertVersion.SetResults(false, e.Message); } } }
/// <summary> /// Installs the ydr. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> public static void InstallYdr( BuildControlParameters configuration, DailyBuildFullResults results) { if (IsYdrInstalled(configuration)) { UninstallWdpt(configuration); } Console.WriteLine("Beginning install of Ydr for branch " + configuration.YdrBranchSelection + " ..."); string buildFolderFile = ""; string setupBranchRoot = ""; switch (configuration.YdrBranchSelection) { case YdrBranch.Mainline: buildFolderFile = File.ReadAllText( Path.Combine(BuildControlParameters.YdrRootFolder, BuildControlParameters.YdrLatestBuildFolderFile)); setupBranchRoot = Path.Combine(BuildControlParameters.YdrRootFolder, YdrBuildFolder(buildFolderFile)); break; case YdrBranch.Wm7_AppPlatform: case YdrBranch.Wm7_AppPlatform_DevDiv: string branchRoot = Path.Combine(BuildControlParameters.YdrRootFolder, configuration.YdrBranchSelection.ToString()); buildFolderFile = File.ReadAllText( Path.Combine(branchRoot, BuildControlParameters.YdrLatestBuildFolderFile)); setupBranchRoot = Path.Combine(branchRoot, YdrBuildFolder(buildFolderFile)); break; } string fullInstallPath = Path.Combine(setupBranchRoot, BuildControlParameters.YdrInstallPathFromBranchRoot); Console.WriteLine("Ydr Installation Path = " + fullInstallPath); try { string arguments = @""; ProcessInformation process = ProcessOperations.RunProcess(fullInstallPath, Application.StartupPath, arguments, true); results.InstallYdr.Success = true; results.YdrVersion = "Branch: " + configuration.YdrBranchSelection.ToString() + " Build " + YdrVersion(YdrBuildFolder(buildFolderFile)).ToString(); ; Console.WriteLine("Ydr Install Completed!"); } catch (Exception e) { string errorMessage = "Failed to install Ydr. Error message was " + e.Message; ProgramExecutionLog.AddEntry(errorMessage); results.InstallYdr.SetResults(false, errorMessage); } }
/// <summary> /// Uninstalls the WDPT. /// </summary> /// <param name="configuration">The configuration.</param> public static void UninstallWdpt(BuildControlParameters configuration) { ProcessOperations.KillSwanProcesses(); UninstallYdr(configuration); Console.WriteLine("Beginning uninstall of Wpdt ..."); GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.UninstallWdpt); string swanController = Path.Combine(configuration.SwanPath, BuildControlParameters.SwanControllerExeName); string swanArguments = "/f " + Path.Combine(configuration.SwanTestCasePath, configuration.WpdtUninstallTestCase); ProcessOperations.RunProcess(swanController, configuration.SwanTestCasePath, swanArguments, false); }
/// <summary> /// Installs the WDPT. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> public static void InstallWdpt( BuildControlParameters configuration, DailyBuildFullResults results) { ProcessOperations.KillSwanProcesses(); Console.WriteLine("Starting Wpdt installation ...."); GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.InstallWdpt); string swanController = Path.Combine(configuration.SwanPath, BuildControlParameters.SwanControllerExeName); string swanArguments = "/f " + Path.Combine(configuration.SwanTestCasePath, configuration.WpdtInstallTestCase); Console.WriteLine("SwanController = " + swanController); Console.WriteLine("SwanArguments = " + swanArguments); ProcessOperations.RunProcess(swanController, configuration.SwanTestCasePath, swanArguments, false); Console.WriteLine("Waiting " + configuration.WpdtInstallationTimeMinutes.ToString() + " minutes for install to complete"); bool wpdtInstalled = false; for (Int32 i = 0; i < configuration.WpdtInstallationTimeMinutes; i++) { for (Int32 j = 0; j < 12; j++) { Thread.Sleep(5000); Console.Write("."); } // Wait one more minute after we detect the product is installed to be sure // of any final cleanup required. if (wpdtInstalled) { break; } Console.WriteLine(""); Console.WriteLine("Waited " + (i + 1).ToString() + " minutes"); } wpdtInstalled = IsWpdtInstalled(configuration); if (wpdtInstalled) { results.InstallWdpt.SetResults(true, ""); Console.WriteLine("Completed Install of Wpdt!"); } else { results.InstallWdpt.SetResults(false, "Wpdt did not install int the alloted time!"); Console.WriteLine("Wpdt did not install int the alloted time!"); } ProcessOperations.KillSwanProcesses(); ProcessOperations.KillSetupProcesses(); results.WpdtVersion = WpdtOperations.DetermineWdptInstalledVersion(configuration); results.YdrVersion = "Same as Wpdt"; }
/// <summary> /// Creates the build script and execute. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> public static void CreateBuildScriptAndExecute( BuildControlParameters configuration, DailyBuildFullResults results) { string heroAppSource = FindHeroAppSourceFolder(configuration); if (String.IsNullOrEmpty(heroAppSource)) { Console.WriteLine("Could not find Application Parent Folder. Aborting ..."); ProgramExecutionLog.AddEntry("Could not find Application Parent Folder. Aborting ..."); return; } Console.Write("Starting Build/Sign/License Process... "); GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.Running); if (configuration.BuildType == BuildTypeEnum.Daily && configuration.UpdateDailyBuildVersion) { bool allCompletedWithSuccess = ModifyBuildVersionFiles(configuration, results); Console.WriteLine("Completed Modifying Revision Files. Overall status was " + allCompletedWithSuccess.ToString()); } else { foreach (BuildTargetResults t in results.BuildTargets) { t.ModifyVersion.RequestedToRun = false; } } Console.WriteLine("Completed!"); Console.Write("Beginning to create batch file for build/sign/license operations ... "); string commandFile = BuildBatchFile(configuration, results); Console.WriteLine("Completed. Running batch file ...."); ProcessOperations.RunProcess(commandFile, Application.StartupPath, "", true); Console.WriteLine("Batch File completed. Status not reported here"); ValidateBuildResults(configuration, results); PublishBuildOutput(configuration, results); if (configuration.BuildType == BuildTypeEnum.Daily && configuration.UpdateDailyBuildVersion) { RevertBuildVersionFiles(configuration, results); } if (configuration.EmailResults) { SendResultViaEmail(configuration, results); } }
/// <summary> /// WPDTs the ops uninstall. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> private static void WpdtOpsUninstall( BuildControlParameters configuration, DailyBuildFullResults results) { ExecutionStatus status = GeneralFileOperations.ReadProgramStatusFile(); results.WpdtVersion = WpdtOperations.DetermineWdptInstalledVersion(configuration); results.YdrVersion = "Same as Wpdt"; if (status != ExecutionStatus.UninstallWdpt && configuration.UpdateWpdt) { if (WpdtOperations.IsWpdtInstalled(configuration)) { if (!WpdtOperations.IsInstalledWpdtVersionSameAsLkg(configuration)) { WpdtOperations.UninstallWdpt(configuration); // Just show some time on the console before we exit for (Int32 i = 0; i < 10; i++) { Console.Write("."); Thread.Sleep(1000); } Console.WriteLine("Exiting process, waiting for Wpdt Uninstall to complete and reboot"); // Just show some more time on the console for (Int32 i = 0; i < 10; i++) { Console.Write("."); Thread.Sleep(1000); } Environment.Exit(0); } } else { Console.WriteLine("Requested to Uninstall Wpdt, but it was not installed!"); ProgramExecutionLog.AddEntry( "Requested to uninstall Wpdt, but it was not installed"); } } if (status == ExecutionStatus.UninstallWdpt) { results.UninstallWdpt.SetResults(true, ""); ProcessOperations.KillSwanProcesses(); Console.WriteLine("Continuing build process after reboot from Wpdt uninstall ..."); GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.Running); } }
/// <summary> /// Helper function that will check to see if a file has a read only /// attribute set. If it does, then the attribute is removed. /// </summary> /// <param name="configuration">Main program configuration</param> /// <param name="fullFileName">File Name to check for read only attribute</param> public static void RemoveReadOnlyAttribute( BuildControlParameters configuration, string fullFileName) { FileInfo f = new FileInfo(fullFileName); if ((f.Attributes & FileAttributes.ReadOnly) != 0) { if (configuration.SourceDepotOnlineMode) { ProcessOperations.SDEdit(configuration, fullFileName); } else { f.Attributes = f.Attributes & ~FileAttributes.ReadOnly; } } }
/// <summary> /// Uninstalls the ydr. /// </summary> /// <param name="configuration">The configuration.</param> public static void UninstallYdr(BuildControlParameters configuration) { if (IsYdrInstalled(configuration)) { Console.Write("Beginning uninstall of YDR... "); try { string arguments = @"/x" + BuildControlParameters.YdrGuid + @" /qb /quiet"; ProcessInformation process = ProcessOperations.RunProcess(MsiExec, Application.StartupPath, arguments, true); Console.WriteLine("Completed!"); } catch (Exception e) { Console.WriteLine(" Failed to uninstall YDR!"); ProgramExecutionLog.AddEntry( "Failed to uninstall Ydr. Error message was " + e.Message); } } }
/// <summary> /// Syncs the enlistment. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> public static void SyncEnlistment( BuildControlParameters configuration, DailyBuildFullResults results) { Console.Write("Syncing Enlistment ... "); GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.SynEnlistment); try { ProcessInformation process = ProcessOperations.SDSync(configuration); CheckForErrorFromSDOperation(process, results, results.EnlistmentSync); Console.WriteLine("Success!"); } catch (Exception e) { Console.WriteLine("Fail!"); results.EnlistmentSync.SetResults(false, e.Message); ProgramExecutionLog.AddEntry( "Failed to sync enlistment " + " Error was " + e.Message); } Console.WriteLine("Enlistment Sync Status = " + results.EnlistmentSync.ToString()); }
/// <summary> /// Modifies the build version files. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="results">The results.</param> /// <returns></returns> private static bool ModifyBuildVersionFiles( BuildControlParameters configuration, DailyBuildFullResults results) { bool allCompletedWithSuccess = true; string heroAppSource = FindHeroAppSourceFolder(configuration); if (!String.IsNullOrEmpty(heroAppSource)) { DateTime currentTime = DateTime.Now; for (Int32 i = 0; i < configuration.Projects.Length; i++) { results.BuildTargets[i].BuildStartTime = currentTime; string appFolder = Path.Combine(heroAppSource, configuration.Projects[i].ProjectPath); string assemblyFile = Path.Combine(appFolder, configuration.Projects[i].AssemblyFilePathAndNameFromProjectRoot); if (File.Exists(assemblyFile)) { try { ProcessInformation process = ProcessOperations.SDEdit(configuration, assemblyFile); CheckForErrorFromSDOperation(process, results, results.BuildTargets[i].ModifyVersion); string[] assemblyFileContents = File.ReadAllLines(assemblyFile); for (Int32 j = 0; j < assemblyFileContents.Length; j++) { if (assemblyFileContents[j].ToLower().Contains(RevisionFileStringBase.ToLower())) { string v = assemblyFileContents[j]; string[] versions = v.Split('.'); if (versions.Length >= 3) { versions[2] = CreateDateTimeFormatString(currentTime); } v = ""; for (Int32 k = 0; k < versions.Length; k++) { v += versions[k] + "."; } assemblyFileContents[j] = v.TrimEnd('.'); break; } } File.WriteAllLines(assemblyFile, assemblyFileContents); results.BuildTargets[i].ModifyVersion.Success = true; } catch (Exception e) { results.BuildTargets[i].ModifyVersion.SetResults(false, e.Message); ProgramExecutionLog.AddEntry( "Failed to modify file " + assemblyFile + " Exception information was " + e.ToString()); allCompletedWithSuccess = false; } } else { string errorMessage = "Assembly File did not exist. Path was " + assemblyFile; results.BuildTargets[i].ModifyVersion.SetResults(false, errorMessage); ProgramExecutionLog.AddEntry(errorMessage); allCompletedWithSuccess = false; } } } else { return(false); } return(allCompletedWithSuccess); }
/// <summary> /// Determines the WDPT installed version. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns></returns> public static string DetermineWdptInstalledVersion(BuildControlParameters configuration) { string wpdtVersion = ""; if (!IsWpdtInstalled(configuration)) { return(wpdtVersion); } using (RegistryKey hklm = Registry.LocalMachine) { string version = ""; if (ProcessOperations.Is64Bit()) { try { using (RegistryKey wow64 = hklm.OpenSubKey(Wpdt64InstallRegKey, true)) { version = (string)wow64.GetValue(WpdtInstallVersionProperty); } } catch (Exception e) { ProgramExecutionLog.AddEntry( "64 bit system. Failed to access Wpdt Version Key/value. Error was " + e.Message); } } else { try { using (RegistryKey software = hklm.OpenSubKey(Wpdt32InstallRegKey, true)) { version = (string)software.GetValue(WpdtInstallVersionProperty); } } catch (Exception e) { ProgramExecutionLog.AddEntry( "32 bit system. Failed to access Wpdt Version Key/value. Error was " + e.Message); } } if (!String.IsNullOrEmpty(version)) { Regex ntMatch = new Regex(WpdtVersionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.RightToLeft); Match m = ntMatch.Match(version); if (m.Success) { wpdtVersion = m.Value; } } if (!wpdtVersionLogged) { wpdtVersionLogged = true; Console.WriteLine("Wpdt installed version was " + wpdtVersion); ProgramExecutionLog.AddEntry("Wpdt installed version was " + wpdtVersion); } return(wpdtVersion); } }