/// <summary> /// Get the project status for a project /// </summary> /// <param name="xDoc">the XDocument to parse</param> /// <param name="currentStatus">the current stored status</param> public ProjectStatus GetProjectStatus(XDocument xDoc, ProjectStatus currentStatus) { // The first element in the document is named based on the type of project (freeStyleProject, mavenModuleSet, etc). Can't access based on name. var firstElement = xDoc.Descendants().First <XElement>(); var lastBuildElement = firstElement.Element("lastBuild"); // Will contain the latest (in progress) build number // GUARD if (!HasLastBuildNumberChanged(currentStatus, lastBuildElement)) { return(currentStatus); } var color = (string)firstElement.Element("color"); var lastSuccessfulBuildElement = firstElement.Element("lastSuccessfulBuild"); var lastCompletedBuildElement = firstElement.Element("lastCompletedBuild"); // Otherwise, we'll need to get the new status of the last completed build JenkinsBuildInformation lastCompletedBuildInfo = new JenkinsBuildInformation(); if (lastCompletedBuildElement != null) { lastCompletedBuildInfo = GetBuildInformation((string)lastCompletedBuildElement.Element("url")); } string lastSuccessfulBuildNumber = String.Empty; if (lastSuccessfulBuildElement != null) { lastSuccessfulBuildNumber = lastSuccessfulBuildElement.Element("number").Value; } var name = (string)firstElement.Element("name"); var projectStatus = new ProjectStatus(name, EnumUtils.GetIntegrationStatus(color), lastCompletedBuildInfo.Timestamp) { Activity = EnumUtils.GetProjectActivity(color), Status = EnumUtils.GetProjectIntegratorState(((string)firstElement.Element("buildable"))?.EndsWith("rue") ?? false), WebURL = (string)firstElement.Element("url"), LastBuildLabel = lastCompletedBuildInfo.Number, LastSuccessfulBuildLabel = lastSuccessfulBuildNumber, Queue = name, QueuePriority = 0, Description = (string)firstElement.Element("description"), ShowForceBuildButton = true, NextBuildTime = DateTime.MaxValue, // This will tell CCTray that the project isn't automatically triggered ShowStartStopButton = true }; return(projectStatus); }
/// <summary> /// Get the project status for a project /// </summary> /// <param name="xDoc">the XDocument to parse</param> /// <param name="currentStatus">the current stored status</param> public ProjectStatus GetProjectStatus(XDocument xDoc, ProjectStatus currentStatus) { // The first element in the document is named based on the type of project (freeStyleProject, mavenModuleSet, etc). Can't access based on name. var firstElement = xDoc.Descendants().First<XElement>(); var lastBuildElement = firstElement.Element("lastBuild"); // Will contain the latest (in progress) build number // GUARD if (!HasLastBuildNumberChanged(currentStatus, lastBuildElement)) { return currentStatus; } var color = (string)firstElement.Element("color"); var lastSuccessfulBuildElement = firstElement.Element("lastSuccessfulBuild"); var lastCompletedBuildElement = firstElement.Element("lastCompletedBuild"); // Otherwise, we'll need to get the new status of the last completed build JenkinsBuildInformation lastCompletedBuildInfo = new JenkinsBuildInformation(); if (lastCompletedBuildElement != null) { lastCompletedBuildInfo = GetBuildInformation((string) lastCompletedBuildElement.Element("url")); } string lastSuccessfulBuildNumber = String.Empty; if (lastSuccessfulBuildElement != null) { lastSuccessfulBuildNumber = lastSuccessfulBuildElement.Element("number").Value; } var name = (string) firstElement.Element("name"); var projectStatus = new ProjectStatus(name, EnumUtils.GetIntegrationStatus(color), lastCompletedBuildInfo.Timestamp) { Activity = EnumUtils.GetProjectActivity(color), Status = EnumUtils.GetProjectIntegratorState((bool)firstElement.Element("buildable")), WebURL = (string) firstElement.Element("url"), LastBuildLabel = lastCompletedBuildInfo.Number, LastSuccessfulBuildLabel = lastSuccessfulBuildNumber, Queue = name, QueuePriority = 0, Description = (string)firstElement.Element("description"), ShowForceBuildButton = true, NextBuildTime = DateTime.MaxValue, // This will tell CCTray that the project isn't automatically triggered ShowStartStopButton = true }; return projectStatus; }