Skip to content

Commit

Permalink
Added XML output
Browse files Browse the repository at this point in the history
  • Loading branch information
texhex committed Jan 11, 2015
1 parent ae6f444 commit 92a7318
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 43 deletions.
4 changes: 2 additions & 2 deletions scripts/BootstrapTemplate.html
Expand Up @@ -113,7 +113,7 @@ <h1>Overview <small>@@USERTEXT@@</small></h1>
</div>

<p>This report was generated on <strong><span id="EndDateTimeUTC">@@ENDDATETIMEUTC@@</span></strong> (UTC) in <strong>@@RUNTIMESECONDS@@</strong> seconds from <strong>@@USERNAME@@</strong> on <strong>@@COMPUTERNAME@@</strong>.</p>
<p>The version used was <strong>@@VERSIONSTRING@@</strong>, HTML template version is <strong>2.12</strong>.</p>
<p>The version used was <strong>@@VERSIONSTRING@@</strong>, HTML template version is <strong>2.15</strong>.</p>
<p>A total of <strong>@@ASSETS.TOTAL@@</strong> assets and <strong>@@TESTS.TOTAL@@</strong> tests were loaded from <strong>@@SOURCEFOLDER@@</strong>.</p>
<p>The unique ID of this report is <strong>@@REPORTID@@</strong>.</p>
<p>Thank you for using Xteq5.</p>
Expand Down Expand Up @@ -295,7 +295,7 @@ <h4>&nbsp;</h4>

<hr>
<footer>
<p><small>Automatically generated by <a href="http://www.Xteq5.com/">Xteq5</a>. Copyright &copy; 2010-2015 <a href="http://www.texhex.info/">Michael 'Tex' Hex</a>.</small></p>
<p><small>Automatically generated by <a href="http://www.xteq5.com/">Xteq5</a>. Copyright &copy; 2010-2015 <a href="http://www.texhex.info/">Michael 'Tex' Hex</a>.</small></p>
<p><small>HTML based on <a href="http://getbootstrap.com/">Bootstrap</a>. Bootswatch <a href="http://bootswatch.com/slate/">Slate</a> (<a href="https://github.com/thomaspark/bootswatch/blob/gh-pages/LICENSE">MIT licensed</a>) created by <a href="http://thomaspark.me">Thomas Park</a>.</small></p>
<p><small>Bootstrap files from <a href="http://www.bootstrapcdn.com/">BootstrapCDN</a> by <a href="https://www.maxcdn.com/">MaxCDN</a>. <a href="https://developers.google.com/speed/libraries/devguide#jquery">jQuery</a> and <a href="http://www.google.com/webfonts">web fonts</a> from <a href="http://www.google.com">Google</a>.</small></p>
<!-- My tribute to X-Tracker DMF files -->
Expand Down
62 changes: 62 additions & 0 deletions scripts/XMLtemplate.xml
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Xteq5 XML template version 1.06
It is assumed that this file will be used for automatic processing.
Therefore it contains only the minimum required information in order to reduce the file size.
-->

<report xmlns="http://www.xteq5.com/xmlreport/v1">

<summary>
<id>@@REPORTID@@</id>
<compilationfolder>@@SOURCEFOLDER@@</compilationfolder>
<engineversion>@@VERSIONSTRING@@</engineversion>
<username>@@USERNAME@@</username>
<computer>@@COMPUTERNAME@@</computer>
<text>@@USERTEXT@@</text>
<starttime>@@STARTDATETIMEUTC@@</starttime>
<endtime>@@ENDDATETIMEUTC@@</endtime>
<runtimeseconds>@@RUNTIMESECONDS@@</runtimeseconds>
</summary>

<issuesfound>
<any>@@ISSUESFOUND@@</any>
<assets>@@ASSETISSUESFOUND@@</assets>
<tests>@@TESTISSUESFOUND@@</tests>
</issuesfound>

<statistics>
<assets>
<total>@@ASSETS.TOTAL@@</total>
<doesnotapply>@@ASSETS.DOESNOTAPPLY@@</doesnotapply>
<success>@@ASSETS.SUCCESS@@</success>
<inconclusive>@@ASSETS.INCONCLUSIVE@@</inconclusive>
<minor>@@ASSETS.MINOR@@</minor>
<major>@@ASSETS.MAJOR@@</major>
<fatal>@@ASSETS.FATAL@@</fatal>
</assets>

<tests>
<total>@@TESTS.TOTAL@@</total>
<doesnotapply>@@TESTS.DOESNOTAPPLY@@</doesnotapply>
<success>@@TESTS.SUCCESS@@</success>
<inconclusive>@@TESTS.INCONCLUSIVE@@</inconclusive>
<minor>@@TESTS.MINOR@@</minor>
<major>@@TESTS.MAJOR@@</major>
<fatal>@@TESTS.FATAL@@</fatal>
</tests>
</statistics>


<assets>
<!--@@ASSETROWS@@-->
</assets>


<tests>
<!--@@TESTROWS@@-->
</tests>


<!-- E N D E -->
</report>
2 changes: 1 addition & 1 deletion src/SharedAssemblyInfo.cs
Expand Up @@ -8,7 +8,7 @@

[assembly: AssemblyTitle("Xteq5")] //Explorer: File description
[assembly: AssemblyProduct("http://www.xteq5.com/")] //Explorer: Product name
[assembly: AssemblyVersion("2.15.*")] //Explorer: Product version
[assembly: AssemblyVersion("2.16.*")] //Explorer: Product version
//[assembly: AssemblyFileVersion("1.0.0.0")] //If not set, AssemblyVersion is also used for AssemblyFileVersion. Explorer: File version


Expand Down
60 changes: 60 additions & 0 deletions src/Xteq5CLI/BatchTest.bat
@@ -0,0 +1,60 @@



REM First step is to find out if this is a x64 or a x86 machine.
REM This happens in order to start the correct version (bitness match) of Xteq5CLI.


SET BITNESS=64bit
IF "%PROCESSOR_ARCHITECTURE%" == "x86" (
if not defined PROCESSOR_ARCHITEW6432 SET BITNESS=32bit
)

REM Clear errorlevel variable, just to be sure
SET ERRORLEVEL=

REM Since Xteq5 is always installed into the native ProgramFiles folder, we can use the path directly
"C:\Program Files\Xteq5\%BITNESS%\Xteq5CLI.exe" -Run -Path "C:\dev\git\Xteq5\scripts" -Format XML -Filename "C:\Temp\result.xml" -Text "From BatchTestBAT"
SET RETURN_CODE=%ERRORLEVEL%

REM Execute Xteq5CLI (Debug Version)
REM "%~dp0bin\x64\Debug\Xteq5CLI.exe" -Run -Path "C:\dev\git\Xteq5\scripts" -Format XML -Filename "C:\Temp\result.xml" -Text "From BatchTestBAT"

REM Write found RETURN CODE
echo Error level is %RETURN_CODE%

REM Check the result with a STRING operator to avoid side effects
IF "%RETURN_CODE%"=="0" GOTO good
IF "%RETURN_CODE%"=="13" GOTO issuesfound
IF "%RETURN_CODE%"=="22" GOTO hell

REM We expected that this line will not be executed because of the GOTO commands.
REM If we are here, it means an unknown return code has been returned (e.g. 9009 for file not found).
REM Go to hell in this case.
goto hell


:good
echo.
echo All is good.
echo.
goto ENDE


:issuesfound
echo.
echo Some issues were found
echo.
goto ENDE


:hell
echo.
echo Fatal error during run!
echo.
goto ENDE



:ENDE
pause
1 change: 1 addition & 0 deletions src/Xteq5CLI/Xteq5CLI.csproj
Expand Up @@ -90,6 +90,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="BatchTest.bat" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xteq5Engine\Xteq5Engine.csproj">
Expand Down
4 changes: 3 additions & 1 deletion src/Xteq5CLI/Xteq5CLIMain.cs
Expand Up @@ -22,6 +22,8 @@
-Run -Filename "C:\Temp\batchresult.htm"
-Run -Filename "C:\Temp\daresult.xml" -Format XML
-Run -Filename "C:\Temp\daresult.xml" -Format XML -Text "blah BLUB"
-Run -Path "C:\dev\git\Xteq5\scripts" -Format XML -Filename "C:\Temp\result.xml" -Text "My comment"
*/
namespace Xteq5CLI
{
Expand Down Expand Up @@ -107,7 +109,7 @@ static int Main(string[] args)


Console.WriteLine();
Console.WriteLine("Exiting. Return code {0}", returnCode);
Console.WriteLine("Exiting, return code is {0}.", returnCode);
#if DEBUG
Console.ReadLine();
#endif
Expand Down
12 changes: 8 additions & 4 deletions src/Xteq5OutputGenerator/BaseTemplateReplaceGenerator.cs
Expand Up @@ -54,7 +54,9 @@ protected void StartGenerating(Report Report)
foreach (AssetRecord asset in Report.Assets)
{
BaseRecord baseRec = asset as BaseRecord;
ProcessAsset(sbAssets, asset, baseRec);
ResultPrimarySecondary rps = new ResultPrimarySecondary(baseRec);

ProcessAsset(sbAssets, asset, baseRec, rps);
}
EndAssetDetails(sbAssets);

Expand All @@ -68,7 +70,9 @@ protected void StartGenerating(Report Report)
foreach (TestRecord test in Report.Tests)
{
BaseRecord baseRec = test as BaseRecord;
ProcessTest(sbTests, test, baseRec);
ResultPrimarySecondary rps = new ResultPrimarySecondary(baseRec);

ProcessTest(sbTests, test, baseRec, rps);
}
EndTestDetails(sbAssets);

Expand Down Expand Up @@ -231,7 +235,7 @@ private void ReplaceTestRecommendedActionTextInternal(string ValueName, string V
protected abstract void StartAssetDetails(StringBuilder sbAssets);

//Called by this class for each asset that exists. Imlementation must add the content to the given stringbuilder.
protected abstract void ProcessAsset(StringBuilder sbAssets, AssetRecord Asset, BaseRecord BaseRec);
protected abstract void ProcessAsset(StringBuilder sbAssets, AssetRecord Asset, BaseRecord BaseRec, ResultPrimarySecondary ResultPrimSecond);

//Called once when the imlementation should end the asset replacement. Can be used to add a footer to the given StringBuilder
protected abstract void EndAssetDetails(StringBuilder sbAssets);
Expand All @@ -247,7 +251,7 @@ private void ReplaceTestRecommendedActionTextInternal(string ValueName, string V
protected abstract void StartTestDetails(StringBuilder sbTests);

//Called by this class for each test that exists. Imlementation must add the content to the given stringbuilder.
protected abstract void ProcessTest(StringBuilder sbTests, TestRecord Test, BaseRecord BaseRec);
protected abstract void ProcessTest(StringBuilder sbTests, TestRecord Test, BaseRecord BaseRec, ResultPrimarySecondary ResultPrimSecond);

//Called once when the imlementation should end the test replacement. Can be used to add a footer to the given StringBuilder
protected abstract void EndTestDetails(StringBuilder sbTests);
Expand Down
29 changes: 7 additions & 22 deletions src/Xteq5OutputGenerator/BootstrapHTMLGenerator2.cs
Expand Up @@ -64,16 +64,10 @@ protected override void StartAssetDetails(StringBuilder sbAssets)
//We do not need any header, it's all in the template file
}

protected override void ProcessAsset(StringBuilder sbAssets, AssetRecord Asset, BaseRecord BaseRec)
protected override void ProcessAsset(StringBuilder sbAssets, AssetRecord Asset, BaseRecord BaseRec, ResultPrimarySecondary ResultPrimSecond)
{
if (Asset.Conclusion == ConclusionEnum.Success)
{
sbAssets.AppendLine(CreateTableRow(BaseRec, Asset.Data));
}
else
{
sbAssets.AppendLine(CreateTableRow(BaseRec, ""));
}

sbAssets.AppendLine(CreateTableRow(BaseRec, ResultPrimSecond));
}

protected override void EndAssetDetails(StringBuilder sbAssets)
Expand All @@ -97,9 +91,9 @@ protected override void StartTestDetails(StringBuilder sbTests)
//We do not need any header, it's all in the template file
}

protected override void ProcessTest(StringBuilder sbTests, TestRecord Test, BaseRecord BaseRec)
protected override void ProcessTest(StringBuilder sbTests, TestRecord Test, BaseRecord BaseRec, ResultPrimarySecondary ResultPrimSecond)
{
sbTests.AppendLine(CreateTableRow(BaseRec, ""));
sbTests.AppendLine(CreateTableRow(BaseRec, ResultPrimSecond));
}

protected override void EndTestDetails(StringBuilder sbTests)
Expand Down Expand Up @@ -129,7 +123,7 @@ void ReplaceHTMLComment(string ValueName, string Value)


//Bootstrap helper function
string CreateTableRow(BaseRecord Record, string PrimaryData)
string CreateTableRow(BaseRecord Record, ResultPrimarySecondary PrimarySecondary)
{
WeakHTMLTag tr = new WeakHTMLTag("tr");

Expand All @@ -151,16 +145,7 @@ string CreateTableRow(BaseRecord Record, string PrimaryData)
//Create <td> for Name and Script file
string tdName = CreateHTMLElement_TdTextSmallText(Record.Name, Record.ScriptFilename);

//Prepare the data for primary and secondary data
ResultPrimarySecondary rps = new ResultPrimarySecondary(Record);

//If the caller gave us PrimaryData, we will use that in any case.
if (string.IsNullOrWhiteSpace(PrimaryData) == false)
{
rps.Primary = PrimaryData;
}

string tdValue = CreateHTMLElement_TdTextSmallText(rps.Primary, rps.Secondary);
string tdValue = CreateHTMLElement_TdTextSmallText(PrimarySecondary.Primary, PrimarySecondary.Secondary);
tr.HTML = tdStatus + tdName + tdValue;

return tr.ToString() + "\r\n";
Expand Down
8 changes: 5 additions & 3 deletions src/Xteq5OutputGenerator/OutputGenerator.cs
Expand Up @@ -26,11 +26,13 @@ public static string GenerateReportOutput(Report Report, OutputFormatEnum Format
{
case OutputFormatEnum.HTML:
string htmlTemplatePath = PathExtension.Combine(Report.CompilationFolder, "BootstrapTemplate.html");

BootstrapHTMLGenerator2 htmlGenerator = new BootstrapHTMLGenerator2();

BootstrapHTMLGenerator2 htmlGenerator = new BootstrapHTMLGenerator2();
return htmlGenerator.Generate(Report, htmlTemplatePath);

case OutputFormatEnum.XML:
string xmlTemplate = PathExtension.Combine(Report.CompilationFolder, "XMLtemplate.xml");
XMLGenerator xmlGenerator = new XMLGenerator();
return xmlGenerator.Generate(Report, xmlTemplate);

default:
throw new NotImplementedException("Only HTML is currently supported");
Expand Down
22 changes: 17 additions & 5 deletions src/Xteq5OutputGenerator/ResultPrimarySecondary.cs
Expand Up @@ -8,11 +8,14 @@ namespace Xteq5
{
/// <summary>
/// Represents how to display the result of an item (Test or Asset) to a user.
/// For an assets we have the conclusion, data and description, while for a test we have only conclusion and description. Description might be empty if the script does not return anything for .Text.
///
/// For an assets we have the conclusion, data and description, while for a test we have only conclusion and description.
/// Description might be empty if the script does not return anything for .Text.
///
/// Therefore it's not trivial what to display as important information (Primary) and less important (Secondary) information to a user.
/// This class tries to solve this.
/// </summary>
internal class ResultPrimarySecondary
public class ResultPrimarySecondary
{
private ResultPrimarySecondary()
{
Expand All @@ -35,9 +38,18 @@ internal ResultPrimarySecondary(BaseRecord Record)
case ConclusionEnum.Success:
case ConclusionEnum.DoesNotApply:
case ConclusionEnum.Fatal:

//Set Primary to a descriptive text, e.g. Conclusiong==Success -> "OK (Success)"
Primary = ConclusionEnumConverter.ConclusionHumanized(Conclusion);

if (Record is AssetRecord)
{
//For an asset that returned SUCCESS, the VALUE the asset has retrieved is the interessting part, hence change primary to the value
if (Conclusion == ConclusionEnum.Success)
{
Primary = (Record as AssetRecord).Data;
}

//Assign to secondary either the default conclusion description or the one from the script
Secondary = string.IsNullOrWhiteSpace(description) ? ConclusionEnumConverter.AssetRecordConclusionDescription(Conclusion) : description;
}
Expand Down Expand Up @@ -79,16 +91,16 @@ internal ResultPrimarySecondary(BaseRecord Record)
/// <summary>
/// Caches the Conclusion from the BaseRecord that was created to initialize this class
/// </summary>
internal ConclusionEnum Conclusion { get; set; }
public ConclusionEnum Conclusion { get; private set; }

/// <summary>
/// Primary (important) result
/// </summary>
internal string Primary { get; set; }
public string Primary { get; private set; }

/// <summary>
/// Secondary (less important) result
/// </summary>
internal string Secondary { get; set; }
public string Secondary { get; private set; }
}
}

0 comments on commit 92a7318

Please sign in to comment.