internal Notification CreateNotification(NotificationVersionOne v1Notification)
        {
            Notification notification = null;

            if (v1Notification != null)
            {
                notification = new Notification
                {
                    Exception        = CreateExceptionData(v1Notification.Exception),
                    Id               = v1Notification.Id,
                    Level            = Utilities.CreateFailureLevel(v1Notification.Level),
                    Message          = CreateMessage(v1Notification.Message),
                    PhysicalLocation = CreatePhysicalLocation(v1Notification.PhysicalLocation),
                    Properties       = v1Notification.Properties,
                    RuleId           = v1Notification.RuleId,
                    ThreadId         = v1Notification.ThreadId,
                    TimeUtc          = v1Notification.Time
                };
            }

            return(notification);
        }
示例#2
0
        internal Notification CreateNotification(NotificationVersionOne v1Notification)
        {
            Notification notification = null;

            if (v1Notification != null)
            {
                notification = new Notification
                {
                    Exception  = CreateExceptionData(v1Notification.Exception),
                    Level      = Utilities.CreateFailureLevel(v1Notification.Level),
                    Message    = CreateMessage(v1Notification.Message),
                    Locations  = CreateLocations(v1Notification.PhysicalLocation),
                    Properties = v1Notification.Properties,
                    ThreadId   = v1Notification.ThreadId,
                    TimeUtc    = v1Notification.Time
                };

                if (!string.IsNullOrWhiteSpace(v1Notification.Id))
                {
                    notification.Descriptor = new ReportingDescriptorReference
                    {
                        Id = v1Notification.Id,
                    };
                }

                if (!string.IsNullOrWhiteSpace(v1Notification.RuleId))
                {
                    notification.AssociatedRule = new ReportingDescriptorReference
                    {
                        Id = v1Notification.RuleId,
                    };
                }
            }

            return(notification);
        }
        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);
        }