/// <summary> /// 编辑报表分期 /// </summary> /// <param name="id">报表分期ID</param> /// <param name="rule">报表分期</param> /// <returns>Result</returns> public Result <object> editRule(string id, ReportRule rule) { if (!verify("editRule")) { return(result); } var data = DbHelper.find <ReportRule>(id); if (data == null) { return(result.notFound()); } if (data.isBuiltin) { return(result.notBeModified()); } data.cycleType = rule.cycleType; data.name = rule.name; data.cycle = rule.cycle; data.startTime = rule.startTime; data.remark = rule.remark; if (existed(data)) { return(result.dataAlreadyExists()); } return(DbHelper.update(data) ? result.success() : result.dataBaseError()); }
/// <summary> /// 规则是否存在 /// </summary> /// <param name="rule"></param> /// <returns>bool 是否存在</returns> public static bool existed(ReportRule rule) { using (var context = new Entities()) { return(context.rules.Any(i => i.id != rule.id && i.tenantId == rule.tenantId && i.name == rule.name)); } }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(report.GetEmailMessage().Body); var body = htmlDocument.DocumentNode.Find(HtmlElementType.Body).FirstOrDefault(); var blocks = htmlDocument.DocumentNode.Find("#block"); var tables = htmlDocument.DocumentNode.Find(HtmlElementType.Table); var styleRegex = new Regex(@"background[\s]*:.*(!#fff|!#ffffff|white|transparent)"); var isVisibleColor = new Func<string, bool>(x => { var value = x.ToLower(); var hiddenValues = new string[] { "#fff", "#ffffff", "white", "transparent" }; return !string.IsNullOrEmpty(value) && !hiddenValues.Any(y => value.Contains(y)); }); var valid = body == null || (body.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value)) || body.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower())) || blocks.Any(block => block.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower()))) || blocks.Any(block => block.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value))) || tables.Any(table => table.Attributes.Any(x => x.Name.ToLower() == "style" && styleRegex.IsMatch(x.Value.ToLower()))) || tables.Any(table => table.Attributes.Any(x => x.Name.ToLower() == "bgcolor" && isVisibleColor(x.Value)))); return new EmailValidationResult { Valid = valid, ReportRule = rule }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var maxWordCount = 200; var maxCharCount = 1000; var paragraphRegex = new Regex("<p.*>.*</p>"); var blockRegex = new Regex("<table.*id=.*BLOCK.*>.*</table>"); var htmlRegex = new Regex("<.*?>", RegexOptions.Compiled); var body = report.GetEmailMessage().Body; var paragraphMatches = paragraphRegex.Matches(body); var blockMatches = blockRegex.Matches(body); var validate = new Func<Match, bool>(match => { var value = match.Value.StripHtml(); var words = value.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries); return words.Length < maxWordCount && value.Length < maxCharCount; }); var valid = paragraphMatches.Cast<Match>().All(validate) && blockMatches.Cast<Match>().All(validate); return new EmailValidationResult { ReportRule = rule, Valid = valid }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var strongRegex = new Regex("<strong>", RegexOptions.IgnoreCase); var inlineBoldRegex = new Regex("<b>", RegexOptions.IgnoreCase); var cssBoldRegex = new Regex("font-weight:bold;", RegexOptions.IgnoreCase); var inlineItalicsRegex = new Regex("<i>.*</i>", RegexOptions.IgnoreCase); var cssItalicsRegex = new Regex("font-style:.italic;", RegexOptions.IgnoreCase); var inlineUnderlineRegex = new Regex("<u>.</u>", RegexOptions.IgnoreCase); var underlineRegex = new Regex("text-decoration:.underline;", RegexOptions.IgnoreCase); return new EmailValidationResult { ReportRule = rule, Valid = strongRegex.Match(emailMessage.Body).Success || inlineBoldRegex.Match(emailMessage.Body).Success || cssItalicsRegex.Match(emailMessage.Body).Success || inlineItalicsRegex.Match(emailMessage.Body).Success || cssBoldRegex.Match(emailMessage.Body).Success || inlineUnderlineRegex.Match(emailMessage.Body).Success || underlineRegex.Match(emailMessage.Body).Success }; }
public static List <PGItem> GetPG(Document doc, AdditionalInfo addiInfo) { _doc = doc; _addiInfo = addiInfo; _myLevel = MyLevel.GetMyLevel(); _abandonWriter = AbandonmentWriter.GetWriter(); _PGItems = new List <PGItem>(4); _GypWalls = new List <RichWall>(10); _GeneticWalls = new List <RichWall>(6); if (_addiInfo.requiredComp[(byte)PGComponents.GypWall] && _addiInfo.requiredComp[(byte)PGComponents.WallFinish]) { _reportRule = ReportRule.Both; } else if (_addiInfo.requiredComp[(byte)PGComponents.GypWall]) { _reportRule = ReportRule.Gyp; } else { _reportRule = ReportRule.Finish; } ExtractObjects(); Process(); return(_PGItems); }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); var body = report.GetEmailMessage().Body; document.LoadHtml(body); // Get all image tags in there var imageTags = document.DocumentNode.Find(HtmlElementType.Img); var valid = true; // For each image tag foreach(var imageTag in imageTags) { var widthAttr = imageTag.Attributes["width"]; if (widthAttr == null || string.IsNullOrEmpty(widthAttr.Value)) continue; float width; if(float.TryParse(widthAttr.Value, out width) && width > 610) { valid = false; } } return new EmailValidationResult { Valid = valid, ReportRule = rule }; }
public void ShouldGenerateExampleReportWithInnerQueries() { var reportRule = new ReportRule { Parameters = new ReportParameter[0], QueryLinks = new IReportQuery[] { new ReportQuery { Key = "Tasks", Text = @"Tasks select #Id# #Repository# select end" } }, ReportTitle = "Test query", Template = new ReportTemplate { Root = new IteratorReportBlock { Child = new QueryScopeReportBlock { Query = new ReportQuery { Key = "Results", Text = @"TaskResults where #TaskId# == {Id} select #Id# #Type# #RawLine# select end" }, Child = new TableReportBlock { BorderPx = 1, QueryKey = "Results" }, Parameters = new [] { new QueryScopeParameter { Key = "Id", Template = "$TasksItem.Id$" } } }, QueryKey = "Tasks" } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); return new EmailValidationResult { ReportRule = rule, Valid = emailMessage.Subject.Count() < 50 }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); document.LoadHtml(report.GetEmailMessage().Body); var anchorTags = document.DocumentNode.Find(HtmlElementType.A); var valid = anchorTags.Any(tag => rule.Dictionary.Any(entry => tag.Attributes.Any(a => a.Name.ToLower() == "href" && a.Value.ToLower().Contains(entry.Value.ToLower())))); var first = anchorTags.FirstOrDefault(tag => rule.Dictionary.Any(entry => tag.Attributes.Any(a => a.Name.ToLower() == "href" && a.Value.ToLower().Contains(entry.Value.ToLower())))); return new EmailValidationResult {ReportRule = rule, Valid = valid}; }
public void ShouldGenerateTaskTelemetryReport() { const string queryKey = "TaskOperations"; var reportRule = new ReportRule { Parameters = new ReportParameter[0], QueryLinks = new IReportQuery[] { new ReportQuery { Key = queryKey, Text = @"TaskTelemetry order #DateTimeLocal# asc select DateTimeLocal=#DateTimeLocal.ToString()# #OperationName# #OperationDuration# #UserLogin# #OperationStatus# #EntityId# #Branch# #TaskStatus# #TaskResolution# #TaskSdlStatus# #VcsPluginName# #ItPluginName# select end" } }, ReportTitle = "Task telemetry", Template = new ReportTemplate { Root = new HtmlDocReportBlock(true) { Id = "HtmlRootBlock", Child = new ContainerReportBlock("MainContainerBlock") { Orientation = ContainerOrientation.Vertical, Childs = new[] { VcsTelemetryReport.GetHeader(), ProjectTelemetryReport.GetOperationDurationChart(queryKey), VcsTelemetryReport.GetTable(queryKey, "Table 1. Operations list") } } } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public static EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var valid = rule.Dictionary.Any(dictionary => emailMessage.Body.ToLower().Contains(dictionary.Value.ToLower())); return new EmailValidationResult { ReportRule = rule, Valid = valid }; }
public static EmailValidationResult ValidateRegion(EmailReport report, ReportRule rule, double start, double end) { var emailMessage = report.GetEmailMessage(); var emailBody = emailMessage.Body; var region = emailBody.GetRegion(start, end); var valid = rule.Dictionary.Any(dictionary => region.ToLower().Contains(dictionary.Value.ToLower())); return new EmailValidationResult { ReportRule = rule, Valid = valid }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); document.LoadHtml(report.GetEmailMessage().Body); var isUrl = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); var anchorTags = document.DocumentNode.Find(HtmlElementType.A); var valid = !anchorTags.Any(x => (!rule.Dictionary.Any(dict => x.InnerText == dict.Value)) && (isUrl.Match(x.InnerText).Success)); return new EmailValidationResult {ReportRule = rule, Valid = valid}; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage().Body.Replace('\n',' '); // Matches any dictionary entry text plus a link including the text 'click' somewhere further on (Having trouble viewing? <a href='blah'>Click here</a>) var valid = rule.Dictionary.Any(x => new Regex(x.Value.ToLower() + ".*<a.*click.*").Match(emailMessage.ToLower()).Success); return new EmailValidationResult { ReportRule = rule, Valid = valid }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var emailBody = emailMessage.Body; var topBody = emailBody.Substring(0, (int) Math.Ceiling(emailBody.Length*.1)); var imageRegex = new Regex("<img .*>"); return new EmailValidationResult { ReportRule = rule, Valid = imageRegex.Match(topBody).Success }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var bottomRegion = report.GetEmailMessage().Body.GetRegion(0.8, 1.0); var zipCodeRegex = new Regex(@"[\d]{5}|[\d]{5}\-[\d]{4}"); bottomRegion = StripHtml(bottomRegion); return new EmailValidationResult { ReportRule = rule, Valid = zipCodeRegex.Match(bottomRegion).Success }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var htmlDocument = new HtmlDocument(); htmlDocument.Load(new StringReader(emailMessage.Body)); var images = htmlDocument.DocumentNode.SelectNodes("//img"); return new EmailValidationResult { ReportRule = rule, Valid = !images.Any(x => !x.XPath.Contains("href")) }; }
public void GenerateDevPolicySucceedMailReport() { var body = FileLoader.FromResource($"{GetType().Namespace}.NotificationTemplates.DevPolicySucceed.html"); var repo = new ReportRule { Parameters = new[] { new ReportParameter("Task Id", "TaskId", "1") }, QueryLinks = new IReportQuery[] { new ReportQuery { Key = "Task", Text = @"Tasks where #Id# == {TaskId} select #Id# #ProjectId# #Created# #Finished# Branch=#Repository# #SdlStatus# ProjectName=#Projects.DisplayName# ProjectSdlStatus=#Projects.SdlPolicyStatus# ProjectBranch=#Projects.DefaultBranchName# TaskSdlAccomplished=#SdlStatus# == 1 ProjectSdlAccomplished=#Projects.SdlPolicyStatus# == 1 HasVulnerabilities=#Todo# + #Reopen# > 0 #HighSeverityVulns# TotalVulnerabilities=#HighSeverityVulns#+#LowSeverityVulns#+#MediumSeverityVulns# select end" } }, ReportTitle = "$if(Task)$ $Task:{ Task | [Dev] FYI: $Task.Value.ProjectName$ - Policy accomplished (branch: $Task.Value.ProjectBranch$) }$ $endif$", Template = new ReportTemplate { Root = new HtmlReportBlock { Id = "HtmlBody", Template = body } } }; var serialized = repo.ToJson(); serialized.Should().NotBeNullOrEmpty(); }
public void ShouldGenerateIssueTrackerTelemetryReport() { const string queryKey = "PluginTelemetry"; var reportRule = new ReportRule { Parameters = new ReportParameter[0], QueryLinks = new IReportQuery[] { new ReportQuery { Key = queryKey, Text = @"ItPluginTelemetry order #DateTimeLocal# asc select DateTimeLocal=#DateTimeLocal.ToString()# #OperationName# #OperationDuration# #UserLogin# #DisplayName# #TypeFullName# #AssemblyName# select end" } }, ReportTitle = "IT plugin telemetry", Template = new ReportTemplate { Root = new HtmlDocReportBlock(true) { Id = "HtmlRootBlock", Child = new ContainerReportBlock("MainContainerBlock") { Orientation = ContainerOrientation.Vertical, Childs = new[] { VcsTelemetryReport.GetHeader(), ProjectTelemetryReport.GetOperationDurationChart(queryKey), VcsTelemetryReport.GetTable(queryKey, "Table 1. Operations list") } } } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var htmlDocument = new HtmlDocument(); htmlDocument.Load(new StringReader(emailMessage.Body)); var bodyWords = htmlDocument.DocumentNode.InnerText.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); return new EmailValidationResult { ReportRule = rule, Valid = bodyWords.Length < 500 //Valid = bodyWords.Length < 200 }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(report.GetEmailMessage().Body); var body = htmlDocument.DocumentNode.Find(HtmlElementType.Body).FirstOrDefault(); var valid = body == null || !body.Attributes.Any(x => x.Name.ToLower() == "background"); return new EmailValidationResult { Valid = valid, ReportRule = rule }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); document.LoadHtml(report.GetEmailMessage().Body); var isUrl = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); var anchorTags = document.DocumentNode.Find(HtmlElementType.A); var valid = anchorTags.Any(x => { var href = x.Attributes["href"]; return href != null && isUrl.Match(href.Value).Success; }); return new EmailValidationResult {ReportRule = rule, Valid = valid}; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); var body = report.GetEmailMessage().Body; // Get the HTML of the first half of the body text document.LoadHtml(body.Substring(0, body.Length / 2)); // Get all image tags in there var imageTags = document.DocumentNode.Find(HtmlElementType.Img); return new EmailValidationResult { ReportRule = rule, // If there are any image tags, return true Valid = (imageTags.Count > 0?true:false) }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var emailMessage = report.GetEmailMessage(); var inlineFontsRegex = new Regex("<font.>.</font>", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); var cssFontsRegex = new Regex("font-family:.", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase); var inlineFonts = inlineFontsRegex.Match(emailMessage.Body); var cssFonts = cssFontsRegex.Match(emailMessage.Body); var totalUniqueFontCount = inlineFonts.Captures.Count + cssFonts.Captures.Count; return new EmailValidationResult { ReportRule = rule, Valid = totalUniqueFontCount < 3 }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); var body = report.GetEmailMessage().Body; // Get the HTML of the first half of the body text document.LoadHtml(body.Substring(0, body.Length / 2)); // Get all image tags in there var imageTags = document.DocumentNode.Find(HtmlElementType.Img); var valid = imageTags.Any(x => HtmlDocumentExtensions.Parent(x, HtmlElementType.A) != null); return new EmailValidationResult { Valid = valid, ReportRule = rule }; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); var body = report.GetEmailMessage().Body; // Get the HTML of the first half of the body text document.LoadHtml(body.Substring(0, body.Length / 2)); // Get all image tags in there var imageTags = document.DocumentNode.Find(HtmlElementType.Img); var valid = !imageTags.Any(x => (!rule.Dictionary.Any(dict => x.Attributes["src"].Value != dict.Value)) && (x.Attributes.Any(y => y.Name == "alt" && string.IsNullOrEmpty(y.Value)) || !x.Attributes.Any(y => y.Name == "alt"))); return new EmailValidationResult { ReportRule = rule, Valid = valid }; }
public static List<PGItem> GetPG(Document doc, AdditionalInfo addiInfo) { _doc = doc; _addiInfo = addiInfo; _myLevel = MyLevel.GetMyLevel(); _abandonWriter = AbandonmentWriter.GetWriter(); _PGItems = new List<PGItem>(4); _GypWalls = new List<RichWall>(10); _GeneticWalls = new List<RichWall>(6); if (_addiInfo.requiredComp[(byte)PGComponents.GypWall] && _addiInfo.requiredComp[(byte)PGComponents.WallFinish]) _reportRule = ReportRule.Both; else if (_addiInfo.requiredComp[(byte)PGComponents.GypWall]) _reportRule = ReportRule.Gyp; else _reportRule = ReportRule.Finish; ExtractObjects(); Process(); return _PGItems; }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { var document = new HtmlDocument(); var body = report.GetEmailMessage().Body; document.LoadHtml(body); // Get all image tags in there var imageTags = document.DocumentNode.Find(HtmlElementType.Img); var valid = true; // For each image tag foreach(var imageTag in imageTags) { var src = imageTag.Attributes["src"]; if (src == null || string.IsNullOrEmpty(src.Value)) continue; // If supported by the webserver, get the content length. // This way we don't have to download the image! try { var href = new Uri(src.Value); System.Net.WebRequest req = System.Net.HttpWebRequest.Create(href); req.Method = "HEAD"; System.Net.WebResponse resp = req.GetResponse(); int ContentLength; if (int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength)) { if (ContentLength > 256000) valid = false; } } catch (Exception) { } } return new EmailValidationResult { Valid = valid, ReportRule = rule }; }
public void ShouldCreatePlaceholderReport() { var reportRule = new ReportRule { Parameters = new ReportParameter[0], QueryLinks = new IReportQuery[0], ReportTitle = "AI SSDL analyst report", Template = new ReportTemplate { Root = new LabelReportBlock { Id = "PlaceholderLabel", Text = "Placehoder for some data." } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public void Get() { var reportRule = new ReportRule { Parameters = new ReportParameter[0], QueryLinks = new IReportQuery[0], Template = new ReportTemplate { Root = new HtmlDocReportBlock { Child = new ContainerReportBlock("ContainerMain") { Childs = new IReportBlock[] { new LabelReportBlock { Text = "Test" }, new ContainerReportBlock { BreakPageBefore = true, Childs = new IReportBlock[] { new LabelReportBlock { Text = "Second" } } } } } } } }; var serialized = reportRule.ToJson(); serialized.Should().NotBeNullOrEmpty(); }
/// <summary> /// 新建报表分期 /// </summary> /// <param name="rule">报表分期</param> /// <returns>Result</returns> public Result <object> addRule(ReportRule rule) { if (!verify("newRule")) { return(result); } rule.id = Util.newId(); rule.tenantId = tenantId; rule.isBuiltin = false; rule.isInvalid = false; rule.creatorDeptId = deptId; rule.creator = userName; rule.creatorId = userId; rule.createTime = DateTime.Now; if (existed(rule)) { return(result.dataAlreadyExists()); } return(DbHelper.insert(rule) ? result.created(rule) : result.dataBaseError()); }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { return DictionaryValidator.ValidateRegion(report, rule, 0, 1.0); }
public void ShouldSerializeReportRule() { var reportRule = new ReportRule { Parameters = new [] { new ReportParameter("Project Id", "ProjectId", "1") }, QueryLinks = new IReportQuery[] { new ReportQueryLink("Task", 51) }, Template = new ReportTemplate { Root = new HtmlDocReportBlock(true) { Child = new ContainerReportBlock { Childs = new IReportBlock[] { new LabelReportBlock { HorizontalAlign = LabelHorizontalAlign.Center, FontStyle = new LabelFontStyle(46), Text = "AI SDL Report: Scan tasks" }, new LabelReportBlock { HorizontalAlign = LabelHorizontalAlign.Center, FontStyle = new LabelFontStyle(28), Text = "AI core work time chart" }, new LabelReportBlock { HorizontalAlign = LabelHorizontalAlign.Center, FontStyle = new LabelFontStyle(16), Text = "Report prepared: $CurrentDate$" }, new ContainerReportBlock { Childs = new IReportBlock[] { new ContainerReportBlock { Childs = new IReportBlock[] { new LabelReportBlock { FontStyle = new LabelFontStyle(18), HorizontalAlign = LabelHorizontalAlign.Center, Text = "Chart 1: Bar chart", VerticalAlign = LabelVerticalalign.Middle }, new ChartReportBlock { Columns = new[] { new ChartColumn { ColumnKey = "WorkTime", DisplayName = "Scan core working time [s]" }, new ChartColumn { ColumnKey = "Size", DisplayName = "Sources size [kb]" } }, HeightPx = 500, Label = new ChartLabel { ColumnKey = "Created" }, Type = ChartType.Bar, QueryKey = "Task" } }, Orientation = ContainerOrientation.Vertical }, new ContainerReportBlock { Childs = new IReportBlock[] { new LabelReportBlock { FontStyle = new LabelFontStyle(18), HorizontalAlign = LabelHorizontalAlign.Center, Text = "Chart 2: Line graph", VerticalAlign = LabelVerticalalign.Middle }, new ChartReportBlock { Columns = new[] { new ChartColumn { ColumnKey = "WorkTime", DisplayName = "Scan core working time" }, new ChartColumn { ColumnKey = "Size", DisplayName = "Sources size" } }, HeightPx = 500, Label = new ChartLabel { ColumnKey = "Created" }, Type = ChartType.Line, QueryKey = "Task" } }, Orientation = ContainerOrientation.Vertical } }, Orientation = ContainerOrientation.Horizontal }, new TableReportBlock { BorderPx = 1, QueryKey = "Task" }, new LabelReportBlock { FontStyle = new LabelFontStyle(12), HorizontalAlign = LabelHorizontalAlign.Center, Text = "System version: $SystemVersion$" } }, Orientation = ContainerOrientation.Vertical } } } }; var serialized = reportRule.ToJson(); serialized.Should().NotBeNullOrEmpty(); }
public void GenerateVcsTelemetryReport() { var reportRule = new ReportRule { Parameters = new ReportParameter[0], ReportTitle = "VCS telemetry", QueryLinks = new IReportQuery[] { new ReportQuery { Key = "VcsOperations", Text = @"VcsPluginTelemetry select DateTimeLocal=#DateTimeLocal.ToString()# #DisplayName# #OperationName# OperationDuration = #OperationDuration# / 1000 #UserLogin# #CreatedBranchName# #CommittedSize# select end" }, new ReportQuery { Key = "VcsOperationsByName", Text = @"VcsPluginTelemetry select #OperationName# select end group #OperationName# select Operation = #Key.OperationName# Count = #Count()# select end order #Count# desc #Operation# asc" }, new ReportQuery { Key = "VcsOperationsByType", Text = @"VcsPluginTelemetry select #DisplayName# select end group #DisplayName# select Type = #Key.DisplayName# Count = #Count()# select end order #Count# desc #Type# asc" }, new ReportQuery { Key = "VcsCommitOperations", Text = @"VcsPluginTelemetry where #OperationName# == ""commit"" order #DateTimeUtc# asc select Time = #DateTimeUtc.ToString()# OperationDuration = #OperationDuration# / 1000 select end" }, new ReportQuery { Key = "VcsCreateBranchOperations", Text = @"VcsPluginTelemetry where #OperationName# == ""create-branch"" order #DateTimeUtc# asc select Time = #DateTimeUtc.ToString()# OperationDuration = #OperationDuration# / 1000 select end" }, new ReportQuery { Key = "VcsCheckoutOperations", Text = @"VcsPluginTelemetry where #OperationName# == ""checkout"" order #DateTimeUtc# asc select Time = #DateTimeUtc.ToString()# OperationDuration = #OperationDuration# / 1000 select end" } }, Template = new ReportTemplate { Root = new HtmlDocReportBlock(true) { Id = "HtmlRootBlock", Child = new ContainerReportBlock("MainContainerBlock") { Orientation = ContainerOrientation.Vertical, Childs = new[] { GetHeader(), GetDohnuts(), GetCharts(), GetTable("VcsOperations", "Table 1. VCS operations") } } } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public EmailValidationResult Validate(EmailReport report, ReportRule rule) { return new EmailValidationResult {ReportRule = rule, Valid = true}; }
public void ShouldCreateFtpTechReport() { var reportRule = new ReportRule { Parameters = new[] { new ReportParameter("Project identifier", "ProjectId", "1") }, QueryLinks = new IReportQuery[] { new ReportQuery { Key = "Project", Text = @"Projects where #Id# == {ProjectId} select #DisplayName# #DefaultBranchName# Created = #Created.ToString()# Modified = #Modified.ToString()# VcsPlugin = #Plugins1.DisplayName# ItPlugin = #Plugins?.DisplayName# #VcsLastSyncUtc# select end" }, new ReportQuery { Key = "ProjectTasks", Text = @"Tasks where #ProjectId# == {ProjectId} order #Created# asc select Created = #Created.ToString()# Finished = #Finished.ToString()# StartedBy = #Users.DisplayName# High = #HighSeverityVulns# Med = #MediumSeverityVulns# Low = #LowSeverityVulns# Ldap = #TaskResults.Count(r => r.TypeShort == ""LDAP"")# Xss = #TaskResults.Count(r => r.TypeShort == ""XSS"")# Total = #HighSeverityVulns# + #MediumSeverityVulns# + #LowSeverityVulns# FolderSize = #FolderSize# / 1024 AnalyzedSize = #AnalyzedSize# / 1024 / 1024 #Todo# #Reopen# #Fixed# #FP# select end" } }, ReportTitle = "AI SSDL technical report", Template = new ReportTemplate { Root = new HtmlDocReportBlock(true) { Id = "HtmlRootBlock", Child = new ContainerReportBlock("MainContainerBlock") { Orientation = ContainerOrientation.Vertical, Childs = new[] { GetHeader(), GetFirstPart(), GetSecondPart(), GetAfterParty() } } } } }; var serializedRule = reportRule.ToJson(); serializedRule.Should().NotBeNullOrEmpty(); }
public EmailValidationResult ValidateRule(EmailReport report, ReportRule rule) { var validator = GetReportRuleValidator(rule.Name); return validator == null ? new EmailValidationResult {ReportRule = rule, Valid = false} : validator.Validate(report, rule); }
public ReportRule SaveRule(ReportRule rule) { return _baseRepository.SaveOrUpdate(rule); }
public void GenerateMgrScanFinishedMailReport() { var body = FileLoader.FromResource($"{GetType().Namespace}.NotificationTemplates.ManScanFinished.html"); var repo = new ReportRule { Parameters = new[] { new ReportParameter("Task Id", "TaskId", "1") }, QueryLinks = new IReportQuery[] { new ReportQuery { Key = "Task", Text = @"Tasks where #Id# == {TaskId} select #Id# #ProjectId# #Created# #Finished# Branch=#Repository# #SdlStatus# ProjectName=#Projects.DisplayName# ProjectSdlStatus=#Projects.SdlPolicyStatus# ProjectBranch=#Projects.DefaultBranchName# TaskSdlAccomplished=#SdlStatus# == 1 ProjectSdlAccomplished=#Projects.SdlPolicyStatus# == 1 HasVulnerabilities=#Todo# + #Reopen# > 0 #HighSeverityVulns# TotalVulnerabilities=#HighSeverityVulns#+#LowSeverityVulns#+#MediumSeverityVulns# select end" }, new ReportQuery { Key = "ResultSummary", Text = @"TaskResults where #TaskId# == {TaskId} select #Type# #SeverityType# #IssueNumber# #IssueUrl# select end group Type,SeverityType,IssueNumber,IssueUrl select Type=#Key.Type# SeverityType=#Key.SeverityType# Count=#Count()# IsLowSeverity=#Key.SeverityType# == 1 IsMedSeverity=#Key.SeverityType# == 2 IsHighSeverity=#Key.SeverityType# == 3 IssueNumber=#Key.IssueNumber# IssueUrl=#Key.IssueUrl# select end order #SeverityType# desc, #Type# asc" } }, ReportTitle = "$if(Task)$ $Task:{ Task | [Man] FYA: $Task.Value.ProjectName$ - Scan finished (branch: $Task.Value.Branch$) }$ $endif$", Template = new ReportTemplate { Root = new HtmlReportBlock { Id = "HtmlBody", Template = body } } }; var serialized = repo.ToJson(); serialized.Should().NotBeNullOrEmpty(); }