/// <summary>
 /// This function was added as a defensive measure where we saw a couple of times
 /// a file was created for what should have been a directory. This caused the
 /// build scripts to fail in a very non obvious way.
 ///
 /// </summary>
 /// <param name="path"></param>
 private static void DeleteIntermediateDirectory(string path)
 {
     if (File.Exists(path))
     {
         GeneralFileOperations.DeleteFile(path);
     }
     if (Directory.Exists(path))
     {
         GeneralFileOperations.DeleteDirectory(path);
     }
 }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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";
        }
Example #4
0
        /// <summary>
        /// Helper function to initialize a test set of files for development
        /// </summary>
        /// <param name="configuration">Main program configuration</param>
        /// <returns>Destination folder path. To use for other operations</returns>
        public static string PrepareWpdtTargetDirectory(
            BuildControlParameters configuration,
            DailyBuildFullResults results)
        {
            string sourcePath      = configuration.WpdtLkgSourcePath;
            string destinationPath = configuration.WpdtLkgTargetPath;

            if (Directory.Exists(destinationPath))
            {
                GeneralFileOperations.DeleteDirectory(destinationPath);
            }
            CopyWpdtLkgToTargetDirectory(sourcePath, destinationPath, results);
            return(destinationPath);
        }
        /// <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);
            }
        }
Example #6
0
 /// <summary>
 /// Writes the summary results.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="results">The results.</param>
 private static void WriteSummaryResults(
     BuildControlParameters configuration,
     DailyBuildFullResults results)
 {
     // Summary results via writing execution logs to output share.
     GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.Idle);
     string[] logEntries   = ProgramExecutionLog.FullLogContents();
     string[] emailSummary = results.GenerateResultsSummary().ToArray <string>();
     File.WriteAllLines(ExecutionLogFile, logEntries);
     File.WriteAllLines(EmailSummaryLogFile, emailSummary);
     if (!String.IsNullOrEmpty(results.PublishLogShare))
     {
         File.WriteAllLines(Path.Combine(results.PublishLogShare, ExecutionLogFile), logEntries);
         File.WriteAllLines(Path.Combine(results.PublishLogShare, EmailSummaryLogFile), emailSummary);
     }
 }
Example #7
0
        /// <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);
            }
        }
Example #8
0
        /// <summary>
        /// Helper function to copy test data from an archive location to a test file location.
        /// </summary>
        /// <param name="sourceFolderName">Source folder name</param>
        /// <param name="targetFolderName">Destination folder name</param>
        public static void CopyWpdtLkgToTargetDirectory(
            string sourceFolderName,
            string targetFolderName,
            DailyBuildFullResults results)
        {
            DirectoryInfo dirInfo;

            DirectoryInfo[] directories;
            string          fileNameOnly        = "";
            string          sourceFileName      = "";
            string          destinationFileName = "";

            try
            {
                dirInfo     = new DirectoryInfo(sourceFolderName);
                directories = dirInfo.GetDirectories();
                GeneralFileOperations.CheckForFolderAndCreate(targetFolderName);
                FileInfo[] f = dirInfo.GetFiles("*.*");
                for (Int32 i = 0; i < f.Length; i++)
                {
                    fileNameOnly        = f[i].Name;
                    sourceFileName      = Path.Combine(sourceFolderName, fileNameOnly);
                    destinationFileName = Path.Combine(targetFolderName, fileNameOnly);
                    File.Copy(sourceFileName, destinationFileName);
                }
            }
            catch (IOException e)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to read file information from source folder. Operation canceled");
                results.InstallWdpt.SetResults(false, e.Message);
                return;
            }
            if (directories.Length > 0)
            {
                foreach (DirectoryInfo dinfo in directories)
                {
                    string newDirInfo      = dinfo.FullName.Replace(sourceFolderName, "");
                    string newTargetFolder = targetFolderName + newDirInfo;
                    CopyWpdtLkgToTargetDirectory(dinfo.FullName, newTargetFolder, results);
                }
            }
        }
 /// <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());
 }
Example #10
0
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        static void Main(string[] args)
        {
            DailyBuildFullResults  results       = new DailyBuildFullResults();
            BuildControlParameters configuration = null;

            try
            {
                if (File.Exists(MainConfigurationFile))
                {
                    Console.Write("Reading Configuration File .... ");
                    configuration = BuildControlParameters.LoadConfiguration(MainConfigurationFile);
                    Console.WriteLine(" Success");
                }
                else
                {
                    Console.WriteLine("Fail. No Configuration file found, creating sample starting file...");
                    configuration = new BuildControlParameters();
                    configuration.SampleInit();
                    BuildControlParameters.SaveConfiguration(configuration, MainConfigurationFile);
                    Console.WriteLine("Sample file created ");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to read Configuration File. Program will exit. " +
                                  "See log file");
                Thread.Sleep(5000);
                ProgramExecutionLog.AddEntry("Failed to read Configuration File. Error was " +
                                             e.Message);
                ProgramExecutionLog.AddEntry("Required configuration file is " +
                                             MainConfigurationFile + " and in the same directory");

                string[] logEntries = ProgramExecutionLog.FullLogContents();
                File.WriteAllLines(ExecutionLogFile, logEntries);
                Environment.Exit(1);
            }
            configuration.UpdateWpdtLkgLink();
            results.Reset(configuration);
            results.UpdateWpdtOpsForInstalledVersion(configuration);

            CheckForWpdtTestCaseFiles(configuration);

            ExecutionStatus status = GeneralFileOperations.ReadProgramStatusFile();

            ParseCommandLineArguments(args, status);

            WpdtOpsUninstall(configuration, results);

            if (configuration.SyncEnlistment)
            {
                SourceCodeOps.SyncEnlistment(configuration, results);
            }

            WpdtOpsInstall(configuration, results);

            UpdateYdr(configuration, results);

            SourceCodeOps.CreateBuildScriptAndExecute(configuration, results);

            WriteSummaryResults(configuration, results);
            GeneralFileOperations.WriteProgramStatusFile(ExecutionStatus.Idle);
        }
        /// <summary>
        /// Publishes the build output.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="results">The results.</param>
        private static void PublishBuildOutput(
            BuildControlParameters configuration,
            DailyBuildFullResults results)
        {
            Console.WriteLine("Publishing results to release share ...");
            string dateFolder = CreateDateTimeFormatString(results.BuildStartTime);

            results.PublishToReleaseShare.Success = true;
            try
            {
                string publishShare       = Path.Combine(configuration.ReleaseShareRoot, dateFolder);
                string publishLogShare    = Path.Combine(publishShare, LogsFolder);
                string publishSourceShare = Path.Combine(publishShare, SourceArchiveFolder);
                string signedXapFolder    = Path.Combine(publishShare, SignedXapFolder);
                string unsignedXapFolder  = Path.Combine(publishShare, UnsignedXapFolder);
                results.PublishShare       = publishShare;
                results.PublishLogShare    = publishLogShare;
                results.PublishSourceShare = publishSourceShare;
                GeneralFileOperations.CreateDirectory(publishShare);
                GeneralFileOperations.CreateDirectory(signedXapFolder);
                GeneralFileOperations.CreateDirectory(unsignedXapFolder);
                GeneralFileOperations.CreateDirectory(publishLogShare);
                GeneralFileOperations.CreateDirectory(publishSourceShare);
                string[] files = null;
                // Copy Signed xaps and license files
                try
                {
                    files = Directory.GetFiles(configuration.BuildOutputPath);
                    foreach (string file in files)
                    {
                        try
                        {
                            string extension = Path.GetExtension(file);
                            if (extension == ".xap" ||
                                file.ToLower().Contains("license"))
                            {
                                string targetFile =
                                    Path.Combine(signedXapFolder, Path.GetFileName(file));
                                File.Copy(file, targetFile);
                            }
                        }
                        catch (Exception e)
                        {
                            ProgramExecutionLog.AddEntry(
                                "Failed to copy result file " + file + " Error message: " + e.Message);
                            results.PublishToReleaseShare.SetResults(false, e.Message);
                        }
                    }
                }
                catch (Exception e1)
                {
                    ProgramExecutionLog.AddEntry(
                        "Failed to access directory " + configuration.BuildOutputPath +
                        " Error message: " + e1.Message);
                    results.PublishToReleaseShare.SetResults(false, e1.Message);
                }

                // Copy unigned xaps
                try
                {
                    files = Directory.GetFiles(
                        Path.Combine(configuration.BuildOutputPath, UnsignedXapFolder));
                    foreach (string file in files)
                    {
                        try
                        {
                            string extension = Path.GetExtension(file);
                            if (extension == ".xap")
                            {
                                string targetFile =
                                    Path.Combine(unsignedXapFolder, Path.GetFileName(file));
                                File.Copy(file, targetFile);
                            }
                        }
                        catch (Exception e)
                        {
                            ProgramExecutionLog.AddEntry(
                                "Failed to copy result file " + file + " Error message: " + e.Message);
                            results.PublishToReleaseShare.SetResults(false, e.Message);
                        }
                    }
                }
                catch (Exception e1)
                {
                    ProgramExecutionLog.AddEntry(
                        "Failed to access directory " + configuration.BuildOutputPath +
                        " " + UnsignedXapFolder +
                        " Error message: " + e1.Message);
                    results.PublishToReleaseShare.SetResults(false, e1.Message);
                }

                // Copy License Files
                try
                {
                    files = Directory.GetFiles(
                        Path.Combine(configuration.BuildOutputPath, LicenseSubDirectory));
                    foreach (string file in files)
                    {
                        try
                        {
                            string extension = Path.GetExtension(file);
                            if (extension == ".xap" ||
                                file.ToLower().Contains("license"))
                            {
                                string targetFile =
                                    Path.Combine(signedXapFolder, Path.GetFileName(file));
                                File.Copy(file, targetFile);
                            }
                        }
                        catch (Exception e)
                        {
                            ProgramExecutionLog.AddEntry(
                                "Failed to copy result file " + file + " Error message: " + e.Message);
                            results.PublishToReleaseShare.SetResults(false, e.Message);
                        }
                    }
                }
                catch (Exception e1)
                {
                    ProgramExecutionLog.AddEntry(
                        "Failed to access directory " + configuration.BuildOutputPath +
                        " " + LicenseSubDirectory +
                        " Error message: " + e1.Message);
                    results.PublishToReleaseShare.SetResults(false, e1.Message);
                }

                // Copy Log Files
                try
                {
                    files = Directory.GetFiles(configuration.LogPath);
                    foreach (string file in files)
                    {
                        try
                        {
                            string logTargetFile =
                                Path.Combine(publishLogShare, Path.GetFileName(file));
                            File.Copy(file, logTargetFile);
                        }
                        catch (Exception e)
                        {
                            ProgramExecutionLog.AddEntry(
                                "Failed to copy result file " + file + " Error message: " + e.Message);
                            results.PublishToReleaseShare.SetResults(false, e.Message);
                        }
                    }
                }
                catch (Exception e1)
                {
                    ProgramExecutionLog.AddEntry(
                        "Failed to access directory " + configuration.LogPath +
                        " Error message: " + e1.Message);
                    results.PublishToReleaseShare.SetResults(false, e1.Message);
                }

                for (Int32 i = 0; i < results.BuildTargets.Length; i++)
                {
                    results.BuildTargets[i].BuildLogFileLink =
                        Path.Combine(publishLogShare,
                                     Path.GetFileName(results.BuildTargets[i].BuildLogFileLink));
                }
            }
            catch (Exception e)
            {
                ProgramExecutionLog.AddEntry(
                    "General fail during Publish" + "Error message: " + e.Message);
                results.PublishToReleaseShare.SetResults(false, e.Message);
            }
            if (configuration.ArchiveSource)
            {
                ZipSourceFiles(configuration, results, results.PublishSourceShare);
            }
            Console.WriteLine("Finish publish operation. Overall status was " +
                              results.PublishToReleaseShare.Success.ToString());
        }
Example #12
0
 /// <summary>
 /// Modifies the install for W2K8.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="results">The results.</param>
 public static void ModifyInstallForW2k8(
     BuildControlParameters configuration,
     DailyBuildFullResults results)
 {
     Console.WriteLine("Modifying Installation for W2k8 ....");
     try
     {
         string fileName = Path.Combine(configuration.WpdtLkgTargetPath, BuildControlParameters.FileToModifyForW2k8);
         File.SetAttributes(fileName, FileAttributes.Normal);
         string[] fileContents             = File.ReadAllLines(fileName);
         bool     foundSection             = false;
         bool     foundInstallOnLHS        = false;
         bool     foundInstallonWin7Server = false;
         for (Int32 i = 0; i < fileContents.Length; i++)
         {
             if (!foundSection)
             {
                 if (fileContents[i].Contains(InstallSection))
                 {
                     foundSection = true;
                     continue;
                 }
             }
             else
             {
                 if (fileContents[i].ToLower().Contains(InstallLhs.ToLower()))
                 {
                     fileContents[i]   = InstallLhs + "=0";
                     foundInstallOnLHS = true;
                     continue;
                 }
                 if (fileContents[i].ToLower().Contains(InstallServer.ToLower()))
                 {
                     fileContents[i]          = InstallServer + "=0";
                     foundInstallonWin7Server = true;
                     break;
                 }
             }
         }
         if (foundSection && foundInstallOnLHS && foundInstallonWin7Server)
         {
             File.WriteAllLines(fileName + ".tmp", fileContents);
             GeneralFileOperations.DeleteFile(fileName);
             GeneralFileOperations.RenameFile(fileName + ".tmp", fileName);
             Console.WriteLine("Successfully completed modifying the installation for W2k8!");
         }
         else
         {
             ProgramExecutionLog.AddEntry(
                 "Failed to find expected settings to enable W2k8 install. This may or not be a problem");
             results.ModifyWdpt.SetResults(false,
                                           "Failed to find expected settings to enable W2k8 install. This may or not be a problem");
         }
     }
     catch (Exception e)
     {
         ProgramExecutionLog.AddEntry(
             "Failed to modify for W2k8 install. This may or not be a problem");
         results.ModifyWdpt.SetResults(false, e.Message);
     }
 }