public SarifErrorListItem(Run run, Notification notification, string logFilePath, ProjectNameCache projectNameCache) : this() { ThreadHelper.ThrowIfNotOnUIThread(); _runId = CodeAnalysisResultManager.Instance.CurrentRunId; ReportingDescriptor rule; string ruleId = null; if (notification.AssociatedRule != null) { ruleId = notification.AssociatedRule.Id; } else if (notification.Descriptor != null) { ruleId = notification.Descriptor.Id; } run.TryGetRule(ruleId, out rule); Message = notification.Message.Text.Trim(); ShortMessage = ExtensionMethods.GetFirstSentence(notification.Message.Text); if (!Message.EndsWith(".")) { ShortMessage = ShortMessage.TrimEnd('.'); } Level = notification.Level; LogFilePath = logFilePath; FileName = SdkUIUtilities.GetFileLocationPath(notification.Locations?[0]?.PhysicalLocation?.ArtifactLocation, _runId) ?? ""; ProjectName = projectNameCache.GetName(FileName); Locations.Add(new LocationModel() { FilePath = FileName }); Tool = run.Tool.ToToolModel(); Rule = rule.ToRuleModel(ruleId); Invocation = run.Invocations?[0]?.ToInvocationModel(); WorkingDirectory = Path.Combine(Path.GetTempPath(), _runId.ToString()); }
public SarifErrorListItem(Run run, Result result, string logFilePath, ProjectNameCache projectNameCache) : this() { if (!SarifViewerPackage.IsUnitTesting) { #pragma warning disable VSTHRD108 // Assert thread affinity unconditionally ThreadHelper.ThrowIfNotOnUIThread(); #pragma warning restore VSTHRD108 // Assert thread affinity unconditionally } _runId = CodeAnalysisResultManager.Instance.CurrentRunId; ReportingDescriptor rule = result.GetRule(run); Tool = run.Tool.ToToolModel(); Rule = rule.ToRuleModel(result.RuleId); Invocation = run.Invocations?[0]?.ToInvocationModel(); Message = result.GetMessageText(rule, concise: false).Trim(); ShortMessage = result.GetMessageText(rule, concise: true).Trim(); if (!Message.EndsWith(".")) { ShortMessage = ShortMessage.TrimEnd('.'); } FileName = result.GetPrimaryTargetFile(run); ProjectName = projectNameCache.GetName(FileName); Category = result.GetCategory(); Region = result.GetPrimaryTargetRegion(); Level = result.Level != FailureLevel.Warning ? result.Level : Rule.FailureLevel; if (result.Suppressions?.Count > 0) { VSSuppressionState = VSSuppressionState.Suppressed; } LogFilePath = logFilePath; if (Region != null) { LineNumber = Region.StartLine; ColumnNumber = Region.StartColumn; } Tool = run.Tool.ToToolModel(); Rule = rule.ToRuleModel(result.RuleId); Invocation = run.Invocations?[0]?.ToInvocationModel(); WorkingDirectory = Path.Combine(Path.GetTempPath(), _runId.ToString()); if (result.Locations?.Any() == true) { // Adding in reverse order will make them display in the correct order in the UI. for (int i = result.Locations.Count - 1; i >= 0; --i) { Locations.Add(result.Locations[i].ToLocationModel(run)); } } if (result.RelatedLocations?.Any() == true) { for (int i = result.RelatedLocations.Count - 1; i >= 0; --i) { RelatedLocations.Add(result.RelatedLocations[i].ToLocationModel(run)); } } if (result.CodeFlows != null) { foreach (CodeFlow codeFlow in result.CodeFlows) { CallTree callTree = codeFlow.ToCallTree(run); if (callTree != null) { CallTrees.Add(callTree); } } CallTrees.Verbosity = 100; CallTrees.IntelligentExpand(); } if (result.Stacks != null) { foreach (Stack stack in result.Stacks) { Stacks.Add(stack.ToStackCollection()); } } if (result.Fixes != null) { foreach (Fix fix in result.Fixes) { Fixes.Add(fix.ToFixModel()); } } }