public async Task SendReport(AzureSummaryManager manager, ExperimentSummary expSummary, ExperimentSummary refSummary, string recipientsStr, string linkPage) { int expId = expSummary.Id; int?refId = refSummary != null ? (int?)refSummary.Id : null; var submissionTime = expSummary.Date; var statusSummary = await manager.GetStatusSummary(expId, refId); var alerts = new ExperimentAlerts(expSummary, statusSummary, linkPage); if (alerts != null && alerts[""].Count > 0 && alerts[""].Level != AlertLevel.None) { Trace.WriteLine("Building summary HTML report..."); string new_report = "<body>"; new_report += "<h1>Z3 Nightly Alert Report</h1>"; new_report += "<p>This are alerts for <a href=" + linkPage + "?job=" + expId + " style='text-decoration:none'>job #" + expId + "</a> (submitted " + submissionTime + ").</p>"; if (alerts[""].Count == 0) { new_report += "<p>"; new_report += "<img src='cid:ok'/> "; new_report += "<font color=Green>All is well everywhere!</font>"; new_report += "</p>"; } else { new_report += "<h2>Alert Summary</h2>"; new_report += createReportTable("", alerts); //detailed report new_report += "<h2>Detailed alerts</h2>"; foreach (string cat in alerts.Categories) { if (cat != "" && alerts[cat].Count > 0) { new_report += "<h3><a href='" + linkPage + "?job=" + expId + "&cat=" + cat + "' style='text-decoration:none'>" + cat + "</a></h3>"; new_report += createReportTable(cat, alerts); } } new_report += "<p>For more information please see the <a href='" + linkPage + "' style='text-decoration:none'>Z3 Nightly Webpage</a>.</p>"; } new_report += "</body>"; Trace.WriteLine("Send emails with report..."); try { var recipients = recipientsStr.Split(';'); foreach (string recipient in recipients) { Send(recipient, "Z3 Alerts", new_report, true); } } catch (Exception ex) { Trace.WriteLine("Failed to send email: " + ex.Message); } } }
private string createReportTable(string category, ExperimentAlerts alerts) { AlertSet alertSet = alerts[category]; string new_table = ""; //add table if (alertSet.Count > 0) { new_table += "<table>"; foreach (KeyValuePair <AlertLevel, List <string> > kvp in alertSet.Messages) { AlertLevel level = kvp.Key; List <string> messages = kvp.Value; new_table += "<tr>"; switch (level) { case AlertLevel.None: new_table += "<td align=left valign=top><img src='https://raw.githubusercontent.com/Z3Prover/PerformanceTest/gh-pages/images/ok.png'/></td>"; new_table += "<td align=left valign=middle><font color=Green>"; break; case AlertLevel.Warning: new_table += "<td align=left valign=top><img src='https://raw.githubusercontent.com/Z3Prover/PerformanceTest/gh-pages/images/warning.png'/></td>"; new_table += "<td align=left valign=middle><font color=Orange>"; break; case AlertLevel.Critical: new_table += "<td align=left valign=top><img src='https://raw.githubusercontent.com/Z3Prover/PerformanceTest/gh-pages/images/critical.png'/></td>"; new_table += "<td align=left valign=middle><font color=Red>"; break; } foreach (string m in messages) { new_table += m + "<br/>"; } new_table += "</font></td>"; new_table += "<tr>"; } new_table += "</table>"; } return(new_table); }