internal Location CreateLocation(LocationVersionOne v1Location) { Location location = null; string key = v1Location.LogicalLocationKey ?? v1Location.FullyQualifiedLogicalName; if (v1Location != null) { location = new Location { FullyQualifiedLogicalName = v1Location.FullyQualifiedLogicalName, PhysicalLocation = CreatePhysicalLocation(v1Location.ResultFile ?? v1Location.AnalysisTarget), Properties = v1Location.Properties }; if (!string.IsNullOrWhiteSpace(location.FullyQualifiedLogicalName)) { if (_v1KeyToV2LogicalLocationMap.TryGetValue(key, out LogicalLocation logicalLocation)) { _v2LogicalLocationToIndexMap.TryGetValue(logicalLocation, out int index); if (!string.IsNullOrEmpty(logicalLocation.DecoratedName)) { logicalLocation.DecoratedName = v1Location.DecoratedName; _v2LogicalLocationToIndexMap[logicalLocation] = index; } location.LogicalLocationIndex = index; } } } return(location); }
internal Location CreateLocation(LocationVersionOne v1Location) { Location location = null; if (v1Location != null) { location = new Location { FullyQualifiedLogicalName = v1Location.LogicalLocationKey ?? v1Location.FullyQualifiedLogicalName, PhysicalLocation = CreatePhysicalLocation(v1Location.ResultFile), Properties = v1Location.Properties }; if (!string.IsNullOrWhiteSpace(location.FullyQualifiedLogicalName)) { if (_currentRun.LogicalLocations?.ContainsKey(location.FullyQualifiedLogicalName) == true) { _currentRun.LogicalLocations[location.FullyQualifiedLogicalName].DecoratedName = v1Location.DecoratedName; } else { LogicalLocation logicalLocation = CreateLogicalLocation(location.FullyQualifiedLogicalName, decoratedName: v1Location.DecoratedName); location.FullyQualifiedLogicalName = AddLogicalLocation(logicalLocation); } } } return(location); }
public override LocationVersionOne VisitLocationVersionOne(LocationVersionOne node) { if (!string.IsNullOrEmpty(node.LogicalLocationKey) && !string.IsNullOrEmpty(node.FullyQualifiedLogicalName) && !node.FullyQualifiedLogicalName.Equals(node.LogicalLocationKey)) { LogicalLocationKeyToFullyQualifiedNameMap[node.LogicalLocationKey] = node.FullyQualifiedLogicalName; } if (!string.IsNullOrEmpty(node.DecoratedName)) { string key = node.LogicalLocationKey ?? node.FullyQualifiedLogicalName; LogicalLocationKeyToDecoratedNameMap[key] = node.DecoratedName; } return(base.VisitLocationVersionOne(node)); }
internal LocationVersionOne CreateLocation(Location v2Location) { LocationVersionOne location = null; if (v2Location != null) { location = new LocationVersionOne { FullyQualifiedLogicalName = v2Location.FullyQualifiedLogicalName, Properties = v2Location.Properties, ResultFile = CreatePhysicalLocation(v2Location.PhysicalLocation) }; if (!string.IsNullOrWhiteSpace(v2Location.FullyQualifiedLogicalName) && _currentV2Run.LogicalLocations?.ContainsKey(v2Location.FullyQualifiedLogicalName) == true) { location.DecoratedName = _currentV2Run.LogicalLocations[v2Location.FullyQualifiedLogicalName].DecoratedName; } } return(location); }
internal LocationVersionOne CreateLocationVersionOne(Location v2Location) { LocationVersionOne location = null; if (v2Location != null) { location = new LocationVersionOne { FullyQualifiedLogicalName = v2Location.LogicalLocation?.FullyQualifiedName, Properties = v2Location.Properties, ResultFile = CreatePhysicalLocationVersionOne(v2Location.PhysicalLocation) }; if (!string.IsNullOrWhiteSpace(v2Location.LogicalLocation?.FullyQualifiedName)) { if (v2Location.LogicalLocation.Index != -1) { location.DecoratedName = _currentV2Run.LogicalLocations[v2Location.LogicalLocation.Index].DecoratedName; } } } return(location); }
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); }