I have a project that reads xml of expected build results for each build area, and compares against build logs to see if the build passed. Right now, the linq is showing each condition in a separate line of results, but (since I’m looping thru each linq result line to check for success) I need to be able to check both conditions (if there are two) at the same time, not different times. Otherwise I could be checking the wrong line of the log file. Note that sometimes there are two success criteria but not always. It’s just the two conditions I need to check at once.
To make this change, I moved my SuccessCriteria tag out of the Conditions tag and below Conditions. With that change, the linq isn’t picking up the xml lines. There should be about 69 lines of results_b with my full xml, but it’s picking up a couple sections I’m not showing that I left in the old format. I tried changing cName = (string)p.Attribute(“name”), to cName = (string)b.Attribute(“name”), in the LINQ but have the same results. The cValue was changed similarly at the same time.
My question is, how do I change the LINQ to pick up the full xml file, and the groupBy_b to check both conditions at once? I want to have the conditions together in a list but have the other data around it like build machine, process name, and success criteria.
For example, the table I put in xml looks like this for some of the log, ParseISLogStats (so I need to check BuildProject and BaseBuildArea are correct together in the log because they are different columns, but the success criteria is only one for those two conditions):
ParseISLogStats Desctiption=nightly v17 partb Projects=8 Status=Success
ParseISLogStats Description=nightly v17 partb Projects=8 Status=Success
ParseISLogStats Description=nightly v17 Projects=33 Status=Success
I’ve been looking at these examples:
linq
linq
So far I have this code (with added groupBy to try and get conditions into a list together):
void ReadXml()
{
int i_results = 0; //0 is successful for all; if it increases we have failed in one
XmlDocument xml = new XmlDocument();
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string newPath = Path.GetFullPath(Path.Combine(path, @"...."));
string finalPathXmlb = Path.GetFullPath(Path.Combine(newPath, @"BuildVerificationBuildAttributes_b.xml")); //new format
teamPost = "";
//linq
XDocument xmlDoc2 = XDocument.Load(finalPathXmlb);
//XElement buildVerificationElement = xmlDoc1.Element("BuildVerification");
//IEnumerable<XElement> buildElements = buildVerificationElement.Elements("build");
//IEnumerable<XElement> buildMachines = buildElements.Elements("BuildMachine");
//get just the times from the xml
//var codeFreezeTime = xmlDoc1.Descendants("codeFreezeTime").First()?.Value;
//logToFileAndScreen(codeFreezeTime);
//get build info from xml, such as process (log name), condition, successCriteria, build machine, start time header,
IEnumerable<XElement> processes = buildMachines.Elements("Process");
var results_b =
xmlDoc2.Descendants("build")
.SelectMany(b => b.Descendants("Process")
.SelectMany(p => p.Descendants("Condition")
.SelectMany(c => c.Descendants("SuccessCriteria")
.Select(sc => new
{
buildMach = (string)b.Element("BuildMachine"),
p1 = (string)p.Element("ProcessName"),
startTimeHeader = (string)p.Element("startTimeHeader"),
cName = (string)c.Attribute("name"),
cValue = (string)c.Attribute("value"),
f1 = (string)sc.Element("field"),
c1 = (string)sc.Element("comparison"),
v1 = (string)sc.Element("value")
})))).ToList();
var groups_b = results_b.GroupBy(x => new { build_machine = x.buildMach, process_name = x.p1, name = x.cName }).ToList();
} //ParseLogFile
I want my groups_b to look like this (but with the linq not working it will never do that, but I don’t think I have it correct in my groups_b either if the linq did work):
{buildMach = mach64, p1=ParseISLogStats, startTimeHeader = StartTime, {cName=Description, cValue=nightly v17 partb, cName=Projects, cValue=8}, f1=Status, c1=equal, v1=Succcess}
{buildmach = mach64, p1=ParseISLogStats, startTimeheader = StartTime, {cName=Description, cValue = nightly v17, cName=Projects, cValue=33},f1=status, c1=equal, v1=Success}
This is what my xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<BuildVerification>
<codeFreezeTime>19:00</codeFreezeTime>
<build>
<BuildMachine>mach31</BuildMachine>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperRfilename1.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperRfilename2.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperRfilename3.h">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
</build>
<build>
<BuildMachine>mach46</BuildMachine>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKfilename4.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKfiename5.h">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKfilename6.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperDfilename7.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKKfilename8.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKKfilename9.h">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKKfilename11.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison> <!--can't use >= here -->
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKfilename22.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinFileVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='VersionFile' value="\viewBuild_NightlyDeveloperKfilename33.cs">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinISProjectVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='ProductName' value="P1">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinISProjectVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='ProductName' value="P2">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>SpinISProjectVersionStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='ProductName' value="P3">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>GetSWStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='DestinationPath' value="D:BuildsRetailnightly">
</Condition>
<Condition
name='DestinationPath' value="D:BuildsRetailnightly">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Successful</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>ParseISLogStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='Nightly' value="D:nightly V17">
</Condition>
<Condition
name='Projects' value=33>
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>ParseISLogStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='Nightly' value="D:nightly V17 partb">
</Condition>
<Condition
name='Projects' value=8>
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>ParseISLogStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='BuildProject' value="DInstallerBuild">
</Condition>
<Condition
name='BaseBuildArea' value="D:R_BuildsKv2.1nightly">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
<Process>
<ProcessName>ParseISLogStats</ProcessName>
<startTimeHeader>StartTime</startTimeHeader>
<Conditions>
<Condition
name='BuildProject' value="KInstallerBuild">
</Condition>
<Condition
name='BaseBuildArea' value="D:R_BuildsKv2.1nightly">
</Condition>
</Conditions>
<SuccessCriteria>
<field>Status</field>
<comparison>equal</comparison>
<value>Success</value>
</SuccessCriteria>
</Process>
</build>
</BuildVerification>