public static string RenderHtmlQualitySpecification( [NotNull] HtmlQualitySpecification qualitySpecification, [NotNull] string templateFilePath, [NotNull] string reportFilePath, bool throwTemplateErrors = false) { Assert.ArgumentNotNull(qualitySpecification, nameof(qualitySpecification)); Assert.ArgumentNotNullOrEmpty(templateFilePath, nameof(templateFilePath)); Assert.ArgumentNotNullOrEmpty(reportFilePath, nameof(reportFilePath)); Assert.ArgumentCondition(File.Exists(templateFilePath), "template file does not exist: {0}", (object)templateFilePath); _msg.DebugFormat( "Rendering quality specification documentation based on template {0}", templateFilePath); LiquidUtils.RegisterSafeType <HtmlQualitySpecification>(); LiquidUtils.RegisterSafeType <HtmlTexts>(); const string rootName = "specification"; string output = LiquidUtils.Render( templateFilePath, throwTemplateErrors, new KeyValuePair <string, object>(rootName, qualitySpecification), new KeyValuePair <string, object>("text", new HtmlTexts())); _msg.DebugFormat("Writing quality specification report to {0}", reportFilePath); FileSystemUtils.WriteTextFile(output, reportFilePath); _msg.InfoFormat("Quality specification report written to {0}", reportFilePath); return(reportFilePath); }
private static void WriteHtmlReport( [NotNull] QualitySpecification qualitySpecification, [NotNull] string directory, [NotNull] HtmlReportDefinition reportDefinition, [NotNull] IssueStatistics issueStatistics, [NotNull] XmlVerificationReport verificationReport, [NotNull] string verificationReportFileName, [CanBeNull] string issueGdbPath, [CanBeNull] IEnumerable <string> issueMapFilePaths, [NotNull] IEnumerable <string> htmlReportFileNames, [CanBeNull] IEnumerable <string> qualitySpecificationReportFilePaths) { Assert.ArgumentNotNull(reportDefinition, nameof(reportDefinition)); Assert.ArgumentCondition(File.Exists(reportDefinition.TemplatePath), "Template file does not exist: {0}", reportDefinition.TemplatePath); string reportFilePath = Path.Combine(directory, reportDefinition.FileName); _msg.DebugFormat("Preparing html report model"); var reportModel = new HtmlReportModel(qualitySpecification, issueStatistics, verificationReport, directory, verificationReportFileName, issueGdbPath, issueMapFilePaths, htmlReportFileNames, qualitySpecificationReportFilePaths, reportDefinition); _msg.DebugFormat("Rendering html report based on template {0}", reportDefinition.TemplatePath); LiquidUtils.RegisterSafeType <HtmlReportModel>(); LiquidUtils.RegisterSafeType <HtmlTexts>(); string output = LiquidUtils.Render( reportDefinition.TemplatePath, new KeyValuePair <string, object>("report", reportModel), new KeyValuePair <string, object>("text", new HtmlTexts())); _msg.DebugFormat("Writing html report to {0}", reportFilePath); FileSystemUtils.WriteTextFile(output, reportFilePath); _msg.InfoFormat("Html report written to {0}", reportFilePath); }
public void LiquidUtilsRenderTest() { const string tempFolder = @"C:\Temp"; Assert.True(Directory.Exists(tempFolder), "Directory {0} does not exist", tempFolder); string templateFileName = Path.Combine(tempFolder, @"test.html.tpl"); string reportFileName = Path.Combine(tempFolder, @"report.html"); File.Delete(templateFileName); File.Delete(reportFileName); var report = new TestReport(); report.StartTime = new DateTime(2000, 12, 31, 23, 59, 58); report.AddVerifiedDataset(new VerifiedDataset("ds1", "ws1")); report.AddVerifiedDataset(new VerifiedDataset("ds2", "ws2")); var sb = new StringBuilder(); sb.AppendLine( "<html><head><title>LiquidUtilsRenderTest{{report.StartTime}}</title></head>"); sb.AppendLine("<body>"); sb.AppendLine("<table>"); sb.AppendLine("{% for dataset in report.VerifiedDatasets -%}"); sb.AppendLine( "<tr><td>dataset:</td><td>{{dataset.Name}}</td><td>{{dataset.WorkspaceName | Upcase}}</td></tr>"); sb.AppendLine("{% endfor -%}"); sb.AppendLine("</table>"); sb.AppendLine("</body>"); sb.AppendLine("</html>"); FileSystemUtils.WriteTextFile(sb.ToString(), templateFileName); Assert.True(File.Exists(templateFileName), "{0} does not exist", templateFileName); LiquidUtils.RegisterSafeType <TestReport>(); string output = LiquidUtils.Render(templateFileName, report, "report"); Assert.True(output.Length > 0, "output is empty"); FileSystemUtils.WriteTextFile(output, reportFileName); Assert.True(File.Exists(reportFileName), "{0} does not exist", reportFileName); }