コード例 #1
0
        /// <summary>
        /// Load the measurement configuration with a supplied filename. This will
        /// normally be called as part of the command line options where the
        /// file name is supplied in the command arguments
        /// </summary>
        /// <param name="fileName">Config file name</param>
        /// <param name="showExceptionDialog">True if we want to show the user an exception dialog
        /// If false, the exception will not be caught.</param>
        /// <returns>BDC Settings</returns>
        public static BuildControlParameters LoadConfiguration(string fileName)
        {
            BuildControlParameters ret = null;

            try
            {
                XmlSerializer mySerializer = new XmlSerializer(typeof(BuildControlParameters));
                // To read the file, create a FileStream.
                FileStream myFileStream = new FileStream(fileName, FileMode.Open);
                // Call the Deserialize method and cast to the object type.
                ret = (BuildControlParameters)mySerializer.Deserialize(myFileStream);
                myFileStream.Close();
            }
            catch (FileNotFoundException e)
            {
                ProgramExecutionLog.AddEntry("Configuration file " + fileName +
                                             " was not found! Error was " + e.Message);
            }
            if (ret != null)
            {
                // For backwards compatibility, set the default to the HeroApps build
                // folder if this is not specified in the configuration file.
                if (String.IsNullOrEmpty(ret.ApplicationParentFolderName))
                {
                    ret.ApplicationParentFolderName = ApplicationParentDefaultFolderName;
                }
            }
            return(ret);
        }
コード例 #2
0
 /// <summary>
 /// Checks for error from SD operation.
 /// </summary>
 /// <param name="process">The process.</param>
 /// <param name="results">The results.</param>
 /// <param name="opToLog">The op to log.</param>
 private static void CheckForErrorFromSDOperation(
     ProcessInformation process,
     DailyBuildFullResults results,
     SingleOperationResults opToLog
     )
 {
     string[] errorOutput = process.GetErrorOutput();
     if (errorOutput != null)
     {
         if (errorOutput.Length > 1)
         {
             // Ignore message where the enlistment is up to date.
             if (errorOutput[0].ToLower().Contains("File(s) up-to-date".ToLower()))
             {
                 opToLog.Success = true;
                 return;
             }
             opToLog.Success = false;
             for (Int32 j = 0; j < errorOutput.Length; j++)
             {
                 opToLog.ErrorMessage += errorOutput[j] + " ";
             }
             ProgramExecutionLog.AddEntry(
                 "Source Depot message was: " + opToLog.ErrorMessage +
                 " . Severity not determined");
             return;
         }
     }
     opToLog.Success = true;
 }
コード例 #3
0
        /// <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);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks for WPDT test case files.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        private static void CheckForWpdtTestCaseFiles(BuildControlParameters configuration)
        {
            if (configuration.UpdateWpdt)
            {
                string uninstallTestCase = Path.Combine(configuration.SwanTestCasePath,
                                                        configuration.WpdtUninstallTestCase);
                string installTestCase = Path.Combine(configuration.SwanTestCasePath,
                                                      configuration.WpdtInstallTestCase);
                bool exitProgram = false;
                if (!File.Exists(uninstallTestCase))
                {
                    exitProgram = true;
                    string error1 = "Wpddt uninstall Test Case File " + uninstallTestCase +
                                    " not found. Program will exit";

                    Console.WriteLine(error1);
                    ProgramExecutionLog.AddEntry(error1);
                    Thread.Sleep(2000);
                }
                if (!File.Exists(installTestCase))
                {
                    exitProgram = true;
                    string error2 = "Wpddt install Test Case File " + installTestCase +
                                    " not found. Program will exit";
                    Console.WriteLine(error2);
                    ProgramExecutionLog.AddEntry(error2);
                    Thread.Sleep(2000);
                }
                if (exitProgram)
                {
                    Environment.Exit(1);
                }
            }
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <summary>
        /// Zips the source files.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="results">The results.</param>
        /// <param name="sourceDirectory">The source directory.</param>
        public static void ZipSourceFiles(
            BuildControlParameters configuration,
            DailyBuildFullResults results,
            string sourceDirectory)
        {
            string archive = Path.Combine(sourceDirectory, SourceArchiveName);

            try
            {
                string heroAppSource = FindHeroAppSourceFolder(configuration);
                using (ZipFile zip = new ZipFile(archive))
                {
                    for (Int32 i = 0; i < configuration.Projects.Length; i++)
                    {
                        if (configuration.Projects[i].BuildConfiguration != BuildProjectControl.None)
                        {
                            string appFolder = Path.Combine(heroAppSource, configuration.Projects[i].ProjectPath);
                            zip.AddDirectory(appFolder, configuration.Projects[i].ProjectPath);
                        }
                    }
                    zip.Save();
                }
            }
            catch (Exception e)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to archive source files" +
                    " Error was " + e.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// This function will send email messages for either a success or failed work item.
        /// The checking will be done whether we should send the mail messages, and mail
        /// will be sent for either success or fail
        /// </summary>
        public static void SendMailtoExchange(
            string senderEmailAddress,
            BuildControlParameters configuration,
            DailyBuildFullResults results)
        {
            if (configuration.EmailResults)
            {
                MailMessage message;
                SmtpClient  client;
                String      subject;
                try
                {
                    client                       = new SmtpClient(SmtpServer);
                    message                      = new MailMessage();
                    message.IsBodyHtml           = true;
                    client.UseDefaultCredentials = true;
                    MailAddress from = new MailAddress(senderEmailAddress + @"@microsoft.com");
                    message.From = from;
                    subject      = "Hero Apps Daily Build Status for: " + DateTime.Now.ToString("MM/dd/yyyy");
                    message.To.Add(new MailAddress(configuration.EmailAlias + @"@microsoft.com"));
                    message.Subject = subject;
                }
                catch (Exception e)
                {
                    ProgramExecutionLog.AddEntry("Email SMTP, send address or to address failure." + e.Message);
                    return;
                }

                try
                {
                    // No point sending if there are none in the email list
                    if (message.To.Count > 0)
                    {
                        message.Body += "\n\n";
                        message.Body  = results.MakeHeroAppsReport(configuration);
                        client.Send(message);
                        Debug.WriteLine("Sent WI email with subject: " + message.Subject);
                    }
                }
                catch (SmtpFailedRecipientException e)
                {
                    ProgramExecutionLog.AddEntry("Partial email send failure. " + e.Message);
                }
                catch (ArgumentException e)
                {
                    ProgramExecutionLog.AddEntry("Email send failure. " + e.Message);
                }
                catch (InvalidOperationException e)
                {
                    ProgramExecutionLog.AddEntry("Email send failure. " + e.Message);
                }
                catch (SmtpException e)
                {
                    ProgramExecutionLog.AddEntry("Email send failure. " + e.Message);
                }
            }
        }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
 public static void RenameFile(string sourceFileName, string targetFileName)
 {
     try
     {
         File.Move(sourceFileName, targetFileName);
     }
     catch (Exception e)
     {
         ProgramExecutionLog.AddEntry(
             "Failed to rename file " + sourceFileName + " to " + targetFileName + " Exception information was " +
             e.ToString());
     }
 }
コード例 #10
0
 public static void CreateDirectory(string directoryPath)
 {
     try
     {
         Directory.CreateDirectory(directoryPath);
     }
     catch (Exception e)
     {
         ProgramExecutionLog.AddEntry(
             "Failed to create directory " + directoryPath + " Exception information was " +
             e.ToString());
     }
 }
コード例 #11
0
 public static void DeleteFile(string fileName)
 {
     try
     {
         File.Delete(fileName);
     }
     catch (Exception e)
     {
         ProgramExecutionLog.AddEntry(
             "Failed to delete file " + fileName + " Exception information was " +
             e.ToString());
     }
 }
コード例 #12
0
        /// <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);
            }
        }
コード例 #13
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);
     }
 }
コード例 #14
0
 /// <summary>
 /// Write to config file
 /// </summary>
 /// <param name="config">BDC config settings</param>
 /// <param name="fileName">Config file</param>
 private static void WriteConfiguration(BuildControlParameters config, string fileName)
 {
     try
     {
         XmlSerializer mySerializer = new XmlSerializer(typeof(BuildControlParameters));
         // To write to a file, create a StreamWriter object.
         StreamWriter myWriter = new StreamWriter(fileName);
         mySerializer.Serialize(myWriter, config);
         myWriter.Close();
     }
     catch (Exception e)
     {
         ProgramExecutionLog.AddEntry("Configuration file " + fileName +
                                      " could not be written to disk! Error was " + e.Message);
     }
 }
コード例 #15
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);
            }
        }
コード例 #16
0
        /// <summary>
        /// Ydrs the version.
        /// </summary>
        /// <param name="ydrFolder">The ydr folder.</param>
        /// <returns></returns>
        private static Int32 YdrVersion(string ydrFolder)
        {
            Int32 version = 0;

            try
            {
                string[] folderParts = ydrFolder.Split('.');
                if (folderParts.Length >= 2)
                {
                    Int32.TryParse(folderParts[0], out version);
                }
            }
            catch (Exception e)
            {
                ProgramExecutionLog.AddEntry("Failed to determine Ydr version from build " +
                                             "folder. Error was " + e.Message);
            }
            return(version);
        }
コード例 #17
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);
                }
            }
        }
コード例 #18
0
 /// <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);
         }
     }
 }
コード例 #19
0
        /// <summary>
        /// Helper function to delete a directory and all subdirectories
        /// </summary>
        /// <param name="directoryPath">Directory to delete</param>
        public static void DeleteDirectory(string directoryPath)
        {
            try
            {
                ClearAttributes(directoryPath);

                Directory.Delete(directoryPath, true);
            }
            catch (IOException e1)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to delete directory " + directoryPath + " Exception information was " +
                    e1.ToString());
            }
            catch (UnauthorizedAccessException e2)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to delete directory " + directoryPath + " Exception information was " +
                    e2.ToString());
            }
        }
コード例 #20
0
        /// <summary>
        /// Finds the hero app source folder.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        private static string FindHeroAppSourceFolder(BuildControlParameters configuration)
        {
            try
            {
                DirectoryInfo current       = new DirectoryInfo(Application.StartupPath);
                DirectoryInfo heroAppSource = current;
                do
                {
                    heroAppSource = heroAppSource.Parent;
                }while (heroAppSource.Name.ToLower() !=
                        configuration.ApplicationParentFolderName.ToLower());
                return(heroAppSource.FullName);
            }

            catch (Exception e)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to find Application parent source folder" +
                    " Error was " + e.Message);
                return(null);
            }
        }
コード例 #21
0
 /// <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());
 }
コード例 #22
0
        /// <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);
        }
コード例 #23
0
        public static void KillSwanProcesses()
        {
            Process[] fullList = Process.GetProcesses();
            for (Int32 i = 0; i < fullList.Length; i++)
            {
                if (fullList[i].ProcessName.ToLower().Contains("controller"))
                {
                    fullList[i].Kill();
                }
            }

            //try
            //{

            //    Registry.LocalMachine.DeleteSubKeyTree(@"Software\Wow6432Node\Swan");
            //}
            //catch (Exception e)
            //{


            //}


            using (RegistryKey hklm = Registry.LocalMachine)
            {
                if (Is64Bit())
                {
                    try
                    {
                        using (RegistryKey wow64 = hklm.OpenSubKey(@"SOFTWARE\Wow6432Node", true))
                        {
                            string[] keyNames = wow64.GetSubKeyNames();
                            for (Int32 i = 0; i < keyNames.Length; i++)
                            {
                                if (keyNames[i].ToLower() == "swan")
                                {
                                    wow64.DeleteSubKeyTree("Swan");
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ProgramExecutionLog.AddEntry(
                            "64 bit system. Failed to delete  Swan  subkey Error was " +
                            e.Message);
                    }
                }
                else
                {
                    try
                    {
                        using (RegistryKey software = hklm.OpenSubKey(@"SOFTWARE", true))
                        {
                            string[] keyNames = software.GetSubKeyNames();
                            for (Int32 i = 0; i < keyNames.Length; i++)
                            {
                                if (keyNames[i].ToLower() == "swan")
                                {
                                    software.DeleteSubKeyTree("Swan");
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ProgramExecutionLog.AddEntry(
                            "32 bit system. Failed to delete  Swan  subkey Error was " +
                            e.Message);
                    }
                }
            }
        }
コード例 #24
0
        /// <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);
            }
        }
コード例 #25
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);
     }
 }
コード例 #26
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);
        }
コード例 #27
0
        /// <summary>
        /// Builds the batch file.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="results">The results.</param>
        /// <returns></returns>
        private static string BuildBatchFile(
            BuildControlParameters configuration,
            DailyBuildFullResults results)
        {
            results.BuildStartTime = DateTime.Now;
            string progFiles   = System.Environment.GetEnvironmentVariable("ProgramFiles");
            string envVarSetup = Path.Combine(progFiles, @"Microsoft Visual Studio 10.0\VC\vcvarsall.bat");

            DeleteIntermediateDirectory(configuration.BuildOutputPath);
            DeleteIntermediateDirectory(configuration.LogPath);

            List <string> buildScript = new List <string>();

            buildScript.Add("@echo off");
            buildScript.Add("call " + "\"" + envVarSetup + "\"" + " x86");
            buildScript.Add("set ScriptDir=%~d0%~p0");
            buildScript.Add("set LogDir=" + configuration.LogPath);
            buildScript.Add("set BuildDir=" + configuration.BuildOutputPath);
            buildScript.Add("set UnsignedXapDir=" + Path.Combine(configuration.BuildOutputPath, UnsignedXapFolder));
            buildScript.Add("rd %LogDir% /s /q");
            buildScript.Add("md %LogDir%");
            buildScript.Add("rd %BuildDir% /s /q");
            buildScript.Add("md %BuildDir%");
            buildScript.Add("md %UnsignedXapDir%");
            buildScript.Add("copy XapUpdater.* %BuildDir%");

            string heroAppSource = FindHeroAppSourceFolder(configuration);

            for (Int32 i = 0; i < configuration.Projects.Length; i++)
            {
                if (configuration.Projects[i].BuildConfiguration != BuildProjectControl.None)
                {
                    StringBuilder b = new StringBuilder();
                    BuildProjectControlParameters p = configuration.Projects[i];
                    string appFolder       = Path.Combine(heroAppSource, p.ProjectPath);
                    string solutionName    = Path.GetFileName(p.SolutionPathAndNameFromProjectRoot);
                    string projectName     = Path.GetFileName(p.ProjectPathAndNameFromProjectRoot);
                    string solution        = Path.Combine(appFolder, p.SolutionPathAndNameFromProjectRoot);
                    string project         = Path.Combine(appFolder, p.ProjectPathAndNameFromProjectRoot);
                    string outputDirectory = Path.Combine(appFolder,
                                                          Path.GetDirectoryName(p.XapPathAndNameFromProjectRoot));
                    string buildtarget = p.BuildConfiguration == BuildProjectControl.Solution ?
                                         solution : project;
                    string logFileName        = Path.GetFileName(buildtarget) + ".log";
                    string xapFileName        = Path.GetFileName(p.XapPathAndNameFromProjectRoot);
                    string signLogFileName    = xapFileName + "_sign" + ".log";
                    string licenseLogFileName = xapFileName + "_license" + ".log";
                    results.BuildTargets[i].BuildLogFileLink = Path.Combine(configuration.LogPath, logFileName);

                    buildScript.Add("echo Building " + solutionName);
                    buildScript.Add("del " + outputDirectory + @"\* /q");
                    buildScript.Add("msbuild " + buildtarget + @" /t:Rebuild /p:Configuration=Release >%LogDir%\" + logFileName + " 2>&1");
                    buildScript.Add(@"IF %ERRORLEVEL% NEQ 0 echo " + solutionName + " build failed");
                    buildScript.Add("copy " + outputDirectory + @"\*.xap" + " %BuildDir%");
                    buildScript.Add("copy " + outputDirectory + @"\*.xap" + " %UnsignedXapDir%");
                    buildScript.Add("cd %BuildDir%");
                    buildScript.Add("XapUpdater.exe -xap " + xapFileName + @" >%LogDir%\" + signLogFileName);
                    buildScript.Add("XapUpdater.exe -generatepreinstalllicense " + xapFileName + @" >%LogDir%\" + licenseLogFileName);
                    buildScript.Add("cd %ScriptDir%");
                }
            }
            try
            {
                File.WriteAllLines("BuildHeroApps.cmd", buildScript.ToArray <string>());
            }
            catch (Exception e)
            {
                ProgramExecutionLog.AddEntry(
                    "Failed to write build commannd file" +
                    " Error was " + e.Message);
            }
            return("BuildHeroApps.cmd");
        }
コード例 #28
0
        /// <summary>
        /// Validates the build results.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="results">The results.</param>
        private static void ValidateBuildResults(
            BuildControlParameters configuration,
            DailyBuildFullResults results)
        {
            Console.Write("Beginning validation of Build target results... ");
            string        heroAppSource   = FindHeroAppSourceFolder(configuration);
            string        outputPath      = configuration.BuildOutputPath;
            string        licensePath     = Path.Combine(outputPath, LicenseSubDirectory);
            List <string> installScript   = new List <string>();
            List <string> uninstallScript = new List <string>();
            string        quote           = "\"";
            string        deviceList      = quote + @"%ProgramFiles%\Zune\updatewp.exe" + quote + " /list";

            installScript.Add(deviceList);
            uninstallScript.Add(deviceList);

            for (Int32 i = 0; i < configuration.Projects.Length; i++)
            {
                try
                {
                    string xapName           = Path.GetFileName(configuration.Projects[i].XapPathAndNameFromProjectRoot);
                    string xapNameNoExt      = Path.GetFileNameWithoutExtension(configuration.Projects[i].XapPathAndNameFromProjectRoot);
                    string xapNameBeforeSign = xapName + BuildControlParameters.SignedXapOrigFileExtension;
                    string licenseName       = xapNameNoExt + BuildControlParameters.LicenseNameAddition;
                    results.BuildTargets[i].Build.Success      = File.Exists(Path.Combine(configuration.BuildOutputPath, xapName));
                    results.BuildTargets[i].SignXap.Success    = File.Exists(Path.Combine(configuration.BuildOutputPath, xapNameBeforeSign));
                    results.BuildTargets[i].LicenseXap.Success = File.Exists(Path.Combine(licensePath, licenseName));
                    installScript.Add(RelativePathToWpapp + WpappProgramPathAndName
                                      + " i " + Path.Combine(configuration.BuildOutputPath, xapName));
                    uninstallScript.Add(RelativePathToWpapp + WpappProgramPathAndName
                                        + " u " + Path.Combine(configuration.BuildOutputPath, xapName));
                }
                catch (Exception e)
                {
                    ProgramExecutionLog.AddEntry(
                        "Failed to validate output files for build target " + configuration.Projects[i].ProjectPath +
                        " Error was " + e.Message);
                    Console.WriteLine("Failed!");
                    Console.WriteLine("For project " + configuration.Projects[i].ProjectPath +
                                      " Error was " + e.Message);
                }
            }
            try
            {
                File.WriteAllLines(InstallXapsOnDevice, installScript.ToArray <string>());
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to write " + InstallXapsOnDevice + " File. See log");
                ProgramExecutionLog.AddEntry(
                    "Failed to write " + InstallXapsOnDevice + " File. " +
                    " Error was " + e.Message);
            }
            try
            {
                File.WriteAllLines(UninstallXapsFromDevice, uninstallScript.ToArray <string>());
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to write " + UninstallXapsFromDevice + " File. See log");
                ProgramExecutionLog.AddEntry(
                    "Failed to write " + UninstallXapsFromDevice + " File. " +
                    " Error was " + e.Message);
            }
            Console.WriteLine("Completed!");
        }
コード例 #29
0
        /// <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());
        }