/// <summary> /// Initializes a new instance of the <see cref="Run" /> class from the specified instance. /// </summary> /// <param name="other"> /// The instance from which the new instance is to be initialized. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other" /> is null. /// </exception> public Run(Run other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Tool, other.Invocation, other.Files, other.LogicalLocations, other.Results, other.ToolNotifications, other.ConfigurationNotifications, other.Rules, other.Id, other.StableId, other.AutomationId, other.BaselineId, other.Architecture); }
public bool ValueEquals(Run other) => ValueComparer.Equals(this, other);
private SarifErrorListItem GetResult(Run run, Result result, string logFilePath) { SarifErrorListItem sarifError = new SarifErrorListItem(run, result, logFilePath); return sarifError; }
public static void ValidateRun(Run run, Action<Result> resultAction) { ValidateTool(run.Tool); foreach (Result result in run.Results) { resultAction(result); } }
private void WriteRunToErrorList(Run run, string logFilePath) { List<SarifErrorListItem> sarifErrors = new List<SarifErrorListItem>(); if (run.Results != null) { foreach (Result result in run.Results) { SarifErrorListItem sarifError = GetResult(run, result, logFilePath); sarifErrors.Add(sarifError); } } CodeAnalysisResultManager.Instance.SarifErrors = sarifErrors; SarifTableDataSource.Instance.AddErrors(sarifErrors); }
public void SarifLogger_WritesRunProperties() { string propertyName = "numberValue"; double propertyValue = 3.14; string logicalId = nameof(logicalId) + ":" + Guid.NewGuid().ToString(); string baselineInstanceGuid = nameof(baselineInstanceGuid) + ":" + Guid.NewGuid().ToString(); string runInstanceGuid = Guid.NewGuid().ToString(); string automationLogicalId = nameof(automationLogicalId) + ":" + Guid.NewGuid().ToString(); string runInstanceId = automationLogicalId + "/" + runInstanceGuid; string architecture = nameof(architecture) + ":" + "x86"; var conversion = new Conversion() { Tool = DefaultTool }; var utcNow = DateTime.UtcNow; var versionControlUri = new Uri("https://www.github.com/contoso/contoso"); var versionControlDetails = new VersionControlDetails() { RepositoryUri = versionControlUri, AsOfTimeUtc = DateTime.UtcNow }; string originalUriBaseIdKey = "testBase"; Uri originalUriBaseIdValue = new Uri("https://sourceserver.contoso.com"); var originalUriBaseIds = new Dictionary <string, ArtifactLocation>() { { originalUriBaseIdKey, new ArtifactLocation { Uri = originalUriBaseIdValue } } }; string defaultEncoding = "UTF7"; List <string> redactionTokens = new List <string> { "[MY_REDACTION_TOKEN]" }; var sb = new StringBuilder(); var run = new Run(); using (var textWriter = new StringWriter(sb)) { run.SetProperty(propertyName, propertyValue); run.AutomationDetails = new RunAutomationDetails { Id = runInstanceId, Guid = runInstanceGuid, }; run.BaselineGuid = baselineInstanceGuid; run.Conversion = conversion; run.VersionControlProvenance = new[] { versionControlDetails }; run.OriginalUriBaseIds = originalUriBaseIds; run.DefaultEncoding = defaultEncoding; run.RedactionTokens = redactionTokens; using (var sarifLogger = new SarifLogger( textWriter, run: run, invocationPropertiesToLog: null)) { } } string output = sb.ToString(); var sarifLog = JsonConvert.DeserializeObject <SarifLog>(output); run = sarifLog.Runs[0]; run.GetProperty <double>(propertyName).Should().Be(propertyValue); run.AutomationDetails.Guid.Should().Be(runInstanceGuid); run.BaselineGuid.Should().Be(baselineInstanceGuid); run.AutomationDetails.Id.Should().Be(runInstanceId); run.Conversion.Tool.Should().BeEquivalentTo(DefaultTool); run.VersionControlProvenance[0].RepositoryUri.Should().BeEquivalentTo(versionControlUri); run.OriginalUriBaseIds[originalUriBaseIdKey].Uri.Should().Be(originalUriBaseIdValue); run.DefaultEncoding.Should().Be(defaultEncoding); run.RedactionTokens[0].Should().Be(redactionTokens[0]); }
public virtual Run VisitRun(Run node) { if (node != null) { node.Tool = VisitNullChecked(node.Tool); node.Invocation = VisitNullChecked(node.Invocation); if (node.Files != null) { var keys = node.Files.Keys.ToArray(); foreach (var key in keys) { var value = node.Files[key]; if (value != null) { node.Files[key] = VisitNullChecked(value); } } } if (node.LogicalLocations != null) { var keys = node.LogicalLocations.Keys.ToArray(); foreach (var key in keys) { var value = node.LogicalLocations[key]; if (value != null) { node.LogicalLocations[key] = VisitNullChecked(value); } } } if (node.Results != null) { for (int index_0 = 0; index_0 < node.Results.Count; ++index_0) { node.Results[index_0] = VisitNullChecked(node.Results[index_0]); } } if (node.ToolNotifications != null) { for (int index_0 = 0; index_0 < node.ToolNotifications.Count; ++index_0) { node.ToolNotifications[index_0] = VisitNullChecked(node.ToolNotifications[index_0]); } } if (node.ConfigurationNotifications != null) { for (int index_0 = 0; index_0 < node.ConfigurationNotifications.Count; ++index_0) { node.ConfigurationNotifications[index_0] = VisitNullChecked(node.ConfigurationNotifications[index_0]); } } if (node.Rules != null) { var keys = node.Rules.Keys.ToArray(); foreach (var key in keys) { var value = node.Rules[key]; if (value != null) { node.Rules[key] = VisitNullChecked(value); } } } } return(node); }
/// <summary> /// Resolve the RuleId for this Result, from direct properties or via Run.Rules lookup. /// </summary> /// <param name="run">Run containing this Result</param> /// <returns>RuleId of this Result</returns> public string ResolvedRuleId(Run run) { return(RuleId ?? Rule?.Id ?? GetRule(run ?? this.Run)?.Id); }
public void SarifConsolidator_Result() { Run run = new Run(); SarifConsolidator consolidator = new SarifConsolidator(run); Result result = new Result() { Message = new Message() { Text = new string('Z', 500) }, Locations = new List <Location>() { new Location(SampleLocation), new Location(SampleLocation) }, RelatedLocations = new List <Location>() { new Location(SampleLocation), new Location(SampleLocation) }, CodeFlows = new List <CodeFlow>(), Graphs = new List <Graph>(), GraphTraversals = new List <GraphTraversal>(), Stacks = new List <Stack>(), WebRequest = new WebRequest(), WebResponse = new WebResponse() }; Result expected = new Result(result) { Locations = new List <Location>() { new Location(SampleLocationTrimmed) }, RelatedLocations = new List <Location>() { new Location(SampleLocationTrimmed) }, }; consolidator.Trim(result); Assert.True(Result.ValueComparer.Equals(expected, result)); Assert.NotNull(result.CodeFlows); consolidator.MessageLengthLimitChars = 128; consolidator.RemoveCodeFlows = true; consolidator.RemoveGraphs = true; consolidator.RemoveRelatedLocations = true; consolidator.RemoveStacks = true; consolidator.RemoveWebRequests = true; consolidator.RemoveWebResponses = true; consolidator.Trim(result); Assert.Equal(128 + 3, result.Message.Text.Length); // Truncated + ellipse Assert.Null(result.CodeFlows); Assert.Null(result.Graphs); Assert.Null(result.GraphTraversals); Assert.Null(result.RelatedLocations); Assert.Null(result.Stacks); Assert.Null(result.WebRequest); Assert.Null(result.WebResponse); }
public ArtifactLocation Resolve(Run run) { return(Index >= 0 && Index < run?.Artifacts?.Count ? run.Artifacts[Index].Location : this); }