Пример #1
0
        /// <summary>
        ///  Look up the ReportingDescriptor for this Result.
        /// </summary>
        /// <param name="run">Run instance containing this Result</param>
        /// <returns>ReportingDescriptor for Result Rule, if available</returns>
        public ReportingDescriptor GetRule(Run run = null)
        {
            // Follows SARIF Spec 3.52.3 (reportingDescriptor lookup)

            // Ensure run argument or Result.Run was set
            if (run == null)
            {
                EnsureRunProvided();
                run = this.Run;
            }

            if (run != null)
            {
                // Find the 'ToolComponent' for this Result (Run.Tool.Driver if absent)
                ToolComponent component           = run.GetToolComponentFromReference(this.Rule?.ToolComponent);
                IList <ReportingDescriptor> rules = component?.Rules;

                // Look up by this.RuleIndex, if present
                if (this.RuleIndex >= 0)
                {
                    return(GetRuleByIndex(rules, this.RuleIndex));
                }

                // Look up by this.Rule.Index, if present
                if (this.Rule?.Index >= 0)
                {
                    return(GetRuleByIndex(rules, this.Rule.Index));
                }

                // Look up by this.Rule.Guid, if present
                if (!string.IsNullOrEmpty(this.Rule?.Guid) && rules != null)
                {
                    ReportingDescriptor rule = component.GetRuleByGuid(this.Rule.Guid);
                    if (rule != null)
                    {
                        return(rule);
                    }
                }

                // Look up by this.RuleId or this.Rule.Id, if present
                string ruleId = this.RuleId ?? this.Rule?.Id;
                if (ruleId != null && rules != null)
                {
                    ReportingDescriptor rule = component.GetRuleById(ruleId);
                    if (rule != null)
                    {
                        return(rule);
                    }
                }
            }

            // Otherwise, metadata is not available and RuleId is the only available property
            return(new ReportingDescriptor()
            {
                Id = this.RuleId ?? this.Rule?.Id
            });
        }
Пример #2
0
        /// <summary>
        ///  Look up the ReportingDescriptor for this Result.
        /// </summary>
        /// <param name="run">Run instance containing this Result</param>
        /// <returns>ReportingDescriptor for Result Rule, if available</returns>
        public ReportingDescriptor GetRule(Run run = null)
        {
            // Follows SARIF Spec 3.52.3 (reportingDescriptor lookup)

            // Ensure run argument or Result.Run was set
            if (run == null)
            {
                EnsureRunProvided();
                run = this.Run;
            }

            if (run != null)
            {
                // Find the 'ToolComponent' for this Result (Run.Tool.Driver if absent)
                ToolComponent component           = run.GetToolComponentFromReference(this.Rule?.ToolComponent);
                IList <ReportingDescriptor> rules = component?.Rules;

                // Look up by this.RuleIndex, if present
                if (this.RuleIndex >= 0)
                {
                    return(GetRuleByIndex(rules, this.RuleIndex));
                }

                // Look up by this.RuleDescriptor.Index, if present
                if (this.Rule?.Index >= 0)
                {
                    return(GetRuleByIndex(rules, this.Rule.Index));
                }

                // Look up by this.RuleDescriptor, Guid, if present
                if (!String.IsNullOrEmpty(this.Rule?.Guid))
                {
                    if (rules != null)
                    {
                        foreach (ReportingDescriptor rule in rules)
                        {
                            if (rule.Guid == this.Rule.Guid)
                            {
                                return(rule);
                            }
                        }

                        throw new ArgumentException($"ReportingDescriptorReference referred to Guid {this.Rule.Guid}, which was not found in toolComponent.Rules.");
                    }
                }
            }

            // Otherwise, metadata is not available and RuleId is the only available property
            return(new ReportingDescriptor()
            {
                Id = this.RuleId ?? this.Rule?.Id
            });
        }