I collect data from two different sources in order to fill one object. My class
public class SampleClient { public string ClientId { get; set; } public string JobName { get; set; } public string JobUrl { get; set; } public string Version { get; set; } }
The first LINQ query populates a collection of SampleClient objects that receive values ββfor all but the version. Then I need to loop through SampleClient and use the ClientId value in the second request. The result of the second query is Version. Here is my first LINQ query:
private void btnProjects_Click(object sender, EventArgs e) { string[] stringArray = { "demo", "sample", "test", "training" }; List<SampleClient> jobList = ( from x in XDocument.Load(XML URL VALUE HERE).Root.Elements("job") where x.Element("name").Value.Contains("-config") && x.Element("name").Value.StartsWith("oba-") && (!stringArray.Any(s => x.Element("name").Value.Contains(s))) select new SampleClient { ClientId = getClientId((string)x.Element("name")), JobName = (string)x.Element("name"), JobUrl = (string)x.Element("url"), }).ToList(); foreach (SampleClient job in jobList) {
In the request that gets the version, I currently have:
var version = from item in doc.Descendants(ns + "properties") select new SampleClient { ClientId = strClientId, Version = (string)item.Element(ns + "product.version").Value };
It is important to note that the URL source used in the second request is created using the ClientId , which was obtained from the first. I may have a regular loop and cleanup / merge objects, but this seems like a hack. Is there a cleaner way to handle this?
This is an XML sample from the first request:
<?xml version="1.0"?> <allView> <description>PROD</description> <job> <name>abc</name> <url>http://ci-client.company.net/job/abc/</url> <color>blue</color> </job> <job> <name>acme</name> <url>http://ci-client.company.net/job/acme/</url> <color>blue</color> </job> </allView>
The second request URL is dynamically generated using the clientID from the results of the first. I use this to download the Maven POM file and get version information. Here is the XML fragment from the POM file.
<?xml version="1.0" encoding="UTF-8" ?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.company.xyz</groupId> <artifactId>io</artifactId> <version>6.11.7-ACME-SNAPSHOT</version> <packaging>pom</packaging> <properties> <product.version>6.11.7</product.version> <db.version>1.4</db.version> </properties> <modules> <module>policies</module> <module>templates</module> <module>assemble</module> </modules> </project>