internal Result CreateResult(ResultVersionOne v1Result) { Result result = null; if (v1Result != null) { result = new Result { BaselineState = Utilities.CreateBaselineState(v1Result.BaselineState), CodeFlows = v1Result.CodeFlows?.Select(CreateCodeFlow).ToList(), Fixes = v1Result.Fixes?.Select(CreateFix).ToList(), InstanceGuid = v1Result.Id, Level = Utilities.CreateFailureLevel(v1Result.Level), Kind = Utilities.CreateResultKind(v1Result.Level), Locations = v1Result.Locations?.Select(CreateLocation).ToList(), Message = CreateMessage(v1Result.Message), Properties = v1Result.Properties, RelatedLocations = v1Result.RelatedLocations?.Select(CreateLocation).ToList(), Stacks = v1Result.Stacks?.Select(CreateStack).ToList(), SuppressionStates = Utilities.CreateSuppressionStates(v1Result.SuppressionStates) }; // The v2 spec says that analysisTarget is required only if it differs from the result location. // On the other hand, the v1 spec says that if the result is found in the file that the tool // was instructed to scan, then analysisTarget should be present and resultFile should be // absent -- so we should _not_ populate the v2 analysisTarget in this case. LocationVersionOne v1Location = v1Result.Locations?[0]; if (v1Location?.ResultFile != null && v1Location.AnalysisTarget?.Uri != v1Location.ResultFile.Uri) { result.AnalysisTarget = CreateFileLocation(v1Result.Locations[0].AnalysisTarget); } result.RuleId = v1Result.RuleId; string ruleKey = v1Result.RuleKey ?? v1Result.RuleId; result.RuleIndex = GetRuleIndexForRuleKey(ruleKey, _v1RuleKeyToV2IndexMap); if (v1Result.FormattedRuleMessage != null) { if (result.Message == null) { result.Message = new Message() { MessageId = v1Result.FormattedRuleMessage.FormatId }; } result.Message.Arguments = v1Result.FormattedRuleMessage.Arguments; } if (!string.IsNullOrWhiteSpace(v1Result.ToolFingerprintContribution)) { result.PartialFingerprints = new Dictionary <string, string> { { "Fingerprint", v1Result.ToolFingerprintContribution } }; } if (!string.IsNullOrWhiteSpace(v1Result.Snippet)) { if (result.Locations == null) { result.Locations = new List <Location>(); } if (result.Locations.Count == 0) { result.Locations.Add(new Location()); } if (result.Locations[0].PhysicalLocation == null) { result.Locations[0].PhysicalLocation = new PhysicalLocation(); } if (result.Locations[0].PhysicalLocation.Region == null) { result.Locations[0].PhysicalLocation.Region = new Region(); } result.Locations[0].PhysicalLocation.Region.Snippet = new ArtifactContent { Text = v1Result.Snippet }; } } return(result); }
internal Result CreateResult(ResultVersionOne v1Result) { Result result = null; if (v1Result != null) { result = new Result { BaselineState = Utilities.CreateBaselineState(v1Result.BaselineState), CodeFlows = v1Result.CodeFlows?.Select(CreateCodeFlow).ToList(), Fixes = v1Result.Fixes?.Select(CreateFix).ToList(), InstanceGuid = v1Result.Id, Level = Utilities.CreateResultLevel(v1Result.Level), Locations = v1Result.Locations?.Select(CreateLocation).ToList(), Message = CreateMessage(v1Result.Message), Properties = v1Result.Properties, RelatedLocations = v1Result.RelatedLocations?.Select(CreateLocation).ToList(), Stacks = v1Result.Stacks?.Select(CreateStack).ToList(), SuppressionStates = Utilities.CreateSuppressionStates(v1Result.SuppressionStates) }; // The spec says that analysisTarget is required only if it differs from the result file. if (v1Result.Locations?[0]?.AnalysisTarget?.Uri != v1Result.Locations?[0]?.ResultFile?.Uri) { result.AnalysisTarget = CreateFileLocation(v1Result.Locations[0].AnalysisTarget); } if (v1Result.RuleKey == null) { result.RuleId = v1Result.RuleId; } else { if (v1Result.RuleId == null) { result.RuleId = v1Result.RuleKey; } else { if (v1Result.RuleId == v1Result.RuleKey) { result.RuleId = v1Result.RuleId; } else { result.RuleId = v1Result.RuleKey; if (_currentRun.Resources == null) { _currentRun.Resources = new Resources(); } if (_currentRun.Resources.Rules == null) { _currentRun.Resources.Rules = new Dictionary <string, Rule>(); } IDictionary <string, Rule> rules = _currentRun.Resources.Rules; if (!rules.ContainsKey(v1Result.RuleKey)) { rules.Add(v1Result.RuleKey, new Rule()); } rules[v1Result.RuleKey].Id = v1Result.RuleId; } } } if (v1Result.FormattedRuleMessage != null) { result.RuleMessageId = v1Result.FormattedRuleMessage.FormatId; if (result.Message == null) { result.Message = new Message(); } result.Message.Arguments = v1Result.FormattedRuleMessage.Arguments; } if (!string.IsNullOrWhiteSpace(v1Result.ToolFingerprintContribution)) { result.PartialFingerprints = new Dictionary <string, string> { { "Fingerprint", v1Result.ToolFingerprintContribution } }; } if (!string.IsNullOrWhiteSpace(v1Result.Snippet)) { if (result.Locations == null) { result.Locations = new List <Location>(); } if (result.Locations.Count == 0) { result.Locations.Add(new Location()); } if (result.Locations[0].PhysicalLocation == null) { result.Locations[0].PhysicalLocation = new PhysicalLocation(); } if (result.Locations[0].PhysicalLocation.Region == null) { result.Locations[0].PhysicalLocation.Region = new Region(); } result.Locations[0].PhysicalLocation.Region.Snippet = new FileContent { Text = v1Result.Snippet }; } } return(result); }