public SimpleXMLDataImporter(ResultLevel thresholdLevel) { _extractConfigurations = new List <IExtractConfiguration>(); _validationRules = new List <IValidationRule>(); _thresholdLevel = thresholdLevel; //_location = location; }
public ParsingResult(ResultLevel level, string message, object value, IDataSourceLocation dataSourceLocation) { _level = level; _message = message; _value = value; _dataSourceLocation = dataSourceLocation; }
private void WriteToConsole(ResultLevel level, Uri uri, Region region, string ruleId, string message) { switch (level) { // These result types are optionally emitted. case ResultLevel.Pass: case ResultLevel.Note: case ResultLevel.NotApplicable: { if (Verbose) { Console.WriteLine(GetMessageText(uri, region, ruleId, message, level)); } break; } // These result types are always emitted. case ResultLevel.Error: case ResultLevel.Warning: { Console.WriteLine(GetMessageText(uri, region, ruleId, message, level)); break; } default: { throw new InvalidOperationException(); } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="success">结果状态</param> /// <param name="msg">提示消息</param> /// <param name="data">结果</param> public Result(bool success, string msg, T data, ResultLevel level = 0) { Success = success; Msg = msg; Data = data; Level = level; if (string.IsNullOrWhiteSpace(Msg)) { switch (Level) { case ResultLevel.ERROR: Msg = "错误提示:操作出错,请稍后再试!"; break; case ResultLevel.WARNING: Msg = "警告提示:操作失败,请稍后再试!"; break; case ResultLevel.NOLOGIN: Msg = "您未登录或登录已超时,请重新登录!"; break; case ResultLevel.NOFOLLOW: Msg = "您未关注该公众号,请关注后重试!"; break; default: Msg = Success ? "提示信息,操作成功!" : "提示信息,操作失败,请稍后再试!"; break; } } if (Success && Data != null) { DataTotal = Data.GetType().GetInterface("ICollection") != null ? (Data as ICollection).Count : 1; } else { DataTotal = 0; } }
private Result MakeResultFromTestCase(ResultLevel level, Region region, string path) { return(new Result { RuleId = TestRuleId, Level = level, Locations = new List <Location> { new Location { AnalysisTarget = new PhysicalLocation { Uri = new Uri(path, UriKind.RelativeOrAbsolute), Region = region } } }, FormattedRuleMessage = new FormattedRuleMessage { FormatId = TestFormatId, Arguments = new List <string> { "42", "54" } } }); }
private Result MakeResultFromTestCase(ResultLevel level, Region region, string path) { return(new Result { RuleId = TestRuleId, Level = level, Locations = new List <Location> { new Location { PhysicalLocation = new PhysicalLocation { FileLocation = new FileLocation { Uri = new Uri(path, UriKind.RelativeOrAbsolute) }, Region = region } } }, RuleMessageId = TestMessageStringId, Message = new Message { Arguments = new List <string> { "42", "54" } } }); }
public void NoteTestResult(ResultLevel level, string targetPath) { switch (level) { case ResultLevel.Pass: { PassTargets.Add(targetPath); break; } case ResultLevel.Error: { FailTargets.Add(targetPath); break; } case ResultLevel.NotApplicable: { NotApplicableTargets.Add(targetPath); break; } default: { throw new InvalidOperationException(); } } }
private Result ParseResult(string[] fields) { string rawMessage = fields[(int)FieldIndex.Message]; string normalizedMessage; IList <AnnotatedCodeLocation> relatedLocations = NormalizeRawMessage(rawMessage, out normalizedMessage); Region region = MakeRegion(fields); var result = new Result { Message = normalizedMessage, Locations = new Location[] { new Location { ResultFile = new PhysicalLocation { Uri = new Uri(GetString(fields, FieldIndex.RelativePath), UriKind.Relative), UriBaseId = "$srcroot", Region = region } } }, RelatedLocations = relatedLocations }; ResultLevel level = ResultLevelFromSemmleSeverity(GetString(fields, FieldIndex.Severity)); if (level != ResultLevel.Warning) { result.Level = level; } return(result); }
public void NoteTestResult(ResultLevel messageKind, string targetPath) { switch (messageKind) { case ResultLevel.Pass: { PassTargets.Add(targetPath); break; } case ResultLevel.Error: { FailTargets.Add(targetPath); break; } case ResultLevel.NotApplicable: { NotApplicableTargets.Add(targetPath); break; } case ResultLevel.Note: { throw new NotImplementedException(); } default: { throw new InvalidOperationException(); } } }
private void LogJsonIssue(ResultLevel level, string targetPath, Region region, string ruleId, string formatId, params string[] arguments) { if (!ShouldLog(level)) { return; } Result result = new Result(); result.RuleId = ruleId; result.FormattedRuleMessage = new FormattedRuleMessage() { FormatId = formatId, Arguments = arguments }; result.Level = level; if (targetPath != null) { result.Locations = new List <Location> { new Sarif.Location { AnalysisTarget = new PhysicalLocation { Uri = new Uri(targetPath), Region = region } } }; } _issueLogJsonWriter.WriteResult(result); }
public bool ShouldLog(ResultLevel level) { switch (level) { case ResultLevel.Note: case ResultLevel.Pass: case ResultLevel.Open: case ResultLevel.NotApplicable: { if (!Verbose) { return(false); } break; } case ResultLevel.Error: case ResultLevel.Default: case ResultLevel.Warning: { break; } default: { throw new InvalidOperationException(); } } return(true); }
public static void Write <T>(this ILog input, Result result, ResultLevel level = ResultLevel.Normal, [CallerMemberName] string member = "", [CallerLineNumber] int line = 0) { if (input.Enabled) { var logEntry = new LogEntry(level, typeof(T).Name, result, member, line); input.Add(logEntry); } }
public MultiLevelXMLDataImporter(ResultLevel thresholdLevel, string rootNode) { _extractConfigurations = new List <IExtractConfiguration>(); _validationRules = new List <IValidationRule>(); _thresholdLevel = thresholdLevel; _rootNode = rootNode; //_location = location; }
public void Result_FormatForVisualStudioTests(ResultLevel level, Region region, string expected, string path) { Result result = MakeResultFromTestCase(level, region, path); string actual = result.FormatForVisualStudio(TestRule); actual.Should().Be(expected); }
public static Result BuildResult(ResultLevel level, IAnalysisContext context, Region region, string ruleMessageId, params string[] arguments) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } ruleMessageId = NormalizeRuleMessageId(ruleMessageId, context.Rule.Id); Result result = new Result { RuleId = context.Rule.Id, Message = new Message { MessageId = ruleMessageId, Arguments = arguments }, Level = level }; string targetPath = context.TargetUri?.LocalPath; if (targetPath != null) { result.Locations = new List <Location> { new Sarif.Location { PhysicalLocation = new PhysicalLocation { FileLocation = new FileLocation { Uri = new Uri(targetPath) }, Region = region } } }; } if (level == ResultLevel.Warning) { context.RuntimeErrors |= RuntimeConditions.OneOrMoreWarningsFired; } if (level == ResultLevel.Error) { context.RuntimeErrors |= RuntimeConditions.OneOrMoreErrorsFired; } return(result); }
public Result(DomRegion region, string message, ResultLevel level, ResultCertainty certainty, ResultImportance importance) { this.Region = region; this.Message = message; this.Level = level; this.Certainty = certainty; this.Importance = importance; }
public Result (DomRegion region, string message, ResultLevel level, ResultCertainty certainty, ResultImportance importance) { this.Region = region; this.Message = message; this.Level = level; this.Certainty = certainty; this.Importance = importance; }
public void SarifLogger_ShouldLog(ResultLevel resultLevel, bool verboseLogging, bool expectedReturn) { LoggingOptions loggingOptions = verboseLogging ? LoggingOptions.Verbose : LoggingOptions.None; var sb = new StringBuilder(); var logger = new SarifLogger(new StringWriter(sb), loggingOptions); bool result = logger.ShouldLog(resultLevel); result.Should().Be(expectedReturn); }
public static bool LevelIsHigherThanOrEqualToThreshold(ResultLevel threshold, ResultLevel actualLevel) { if (levelDictionary.ContainsKey(threshold)) { return levelDictionary[threshold].Contains(actualLevel) || (threshold == actualLevel); } else { throw new KeyNotFoundException(threshold.ToString() + " is not a supported Analysis result level"); } }
public static bool LevelIsHigherThanOrEqualToThreshold(ResultLevel threshold, ResultLevel actualLevel) { if (levelDictionary.ContainsKey(threshold)) { return(levelDictionary[threshold].Contains(actualLevel) || (threshold == actualLevel)); } else { throw new KeyNotFoundException(threshold.ToString() + " is not a supported Analysis result level"); } }
public static string FormatForVisualStudio(this ResultLevel level) { switch (level) { case ResultLevel.Error: return("error"); case ResultLevel.Warning: return("warning"); default: return("info"); } }
public void Log(ResultLevel messageKind, IAnalysisContext context, Region region, string ruleMessageId, params string[] arguments) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Rule != null) { Rules[context.Rule.Id] = context.Rule; } ruleMessageId = RuleUtilities.NormalizeRuleMessageId(ruleMessageId, context.Rule.Id); LogJsonIssue(messageKind, context.TargetUri.LocalPath, region, context.Rule.Id, ruleMessageId, arguments); }
private LogLevel GetLogLevel(ResultLevel level) { switch (level) { case ResultLevel.Success: return LogLevel.Verbose; case ResultLevel.Info: return LogLevel.Info; case ResultLevel.Warning: return LogLevel.Warning; case ResultLevel.Error: return LogLevel.Error; default: throw new NotSupportedException(level.ToString()); } }
private PSResultLevel Convert(ResultLevel value) { switch (value) { case ResultLevel.Error: return(PSResultLevel.Error); case ResultLevel.Info: return(PSResultLevel.Info); case ResultLevel.Warning: return(PSResultLevel.Warning); default: throw new ArgumentException($"{value.GetType().Name} value {value} is unsupported"); } }
/// <summary> /// Converts the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>PSResultLevel.</returns> /// <exception cref="ArgumentException"></exception> private PSResultLevel Convert(ResultLevel value) { switch (value) { case ResultLevel.Error: return(PSResultLevel.Error); case ResultLevel.Info: return(PSResultLevel.Info); case ResultLevel.Warning: return(PSResultLevel.Warning); default: throw new ArgumentException(string.Format(StorageSyncResources.UnsupportedErrorFormat, value.GetType().Name, value)); } }
public void AddResult(ResultLevel resultLevel, string message, Action <ValidationResult> notify = null) { if (resultLevel == ResultLevel.NotPassed) { ErrorCount++; } CheckCount++; _messages.Add(new ValidationMessage { ResultLevel = resultLevel, Message = message }); if (notify != null) { notify(this); } }
static string GetIcon(ResultLevel severity) { switch (severity) { case ResultLevel.Error: return(Gtk.Stock.DialogError); case ResultLevel.Warning: return(Gtk.Stock.DialogWarning); case ResultLevel.Suggestion: return(Gtk.Stock.Info); default: return(null); } }
public static Result BuildResult(ResultLevel level, IAnalysisContext context, Region region, string formatId, params string[] arguments) { //validating parameters if (context == null) { throw new ArgumentNullException(nameof(context)); } if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId); Result result = new Result { RuleId = context.Rule.Id, FormattedRuleMessage = new FormattedRuleMessage() { FormatId = formatId, Arguments = arguments }, Level = level }; string targetPath = context.TargetUri?.LocalPath; if (targetPath != null) { result.Locations = new List<Location> { new Sarif.Location { AnalysisTarget = new PhysicalLocation { Uri = new Uri(targetPath), Region = region } }}; } return result; }
public void Log(ResultLevel level, string ruleId) { switch (level) { case ResultLevel.Pass: break; case ResultLevel.Error: break; case ResultLevel.Warning: break; case ResultLevel.NotApplicable: break; default: throw new InvalidOperationException(); } }
private LogLevel GetLogLevel(ResultLevel level) { switch (level) { case ResultLevel.Success: return(LogLevel.Verbose); case ResultLevel.Info: return(LogLevel.Info); case ResultLevel.Warning: return(LogLevel.Warning); case ResultLevel.Error: return(LogLevel.Error); default: throw new NotSupportedException(level.ToString()); } }
public static ResultLevelVersionOne CreateResultLevelVersionOne(ResultLevel v2ResultLevel) { switch (v2ResultLevel) { case ResultLevel.Error: return(ResultLevelVersionOne.Error); case ResultLevel.Note: return(ResultLevelVersionOne.Note); case ResultLevel.Pass: return(ResultLevelVersionOne.Pass); case ResultLevel.Warning: return(ResultLevelVersionOne.Warning); case ResultLevel.NotApplicable: return(ResultLevelVersionOne.NotApplicable); default: return(ResultLevelVersionOne.Default); } }
private void Init(string id, string name, string shortDescription, string fullDescription, IDictionary <string, string> messageFormats, RuleConfiguration configuration, ResultLevel defaultLevel, Uri helpUri, IDictionary <string, SerializedPropertyInfo> properties) { Id = id; Name = name; ShortDescription = shortDescription; FullDescription = fullDescription; if (messageFormats != null) { MessageFormats = new Dictionary <string, string>(messageFormats); } Configuration = configuration; DefaultLevel = defaultLevel; if (helpUri != null) { HelpUri = new Uri(helpUri.OriginalString, helpUri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative); } if (properties != null) { Properties = new Dictionary <string, SerializedPropertyInfo>(properties); } }
private __VSERRORCATEGORY GetSeverity(ResultLevel level) { switch (level) { case ResultLevel.Error: { return(__VSERRORCATEGORY.EC_ERROR); } case ResultLevel.Warning: { return(__VSERRORCATEGORY.EC_WARNING); } case ResultLevel.NotApplicable: case ResultLevel.Pass: case ResultLevel.Note: { return(__VSERRORCATEGORY.EC_MESSAGE); } } return(__VSERRORCATEGORY.EC_WARNING); }
/// <summary> /// Initializes a new instance of the <see cref="Result" /> class from the supplied values. /// </summary> /// <param name="ruleId"> /// An initialization value for the <see cref="P: RuleId" /> property. /// </param> /// <param name="ruleKey"> /// An initialization value for the <see cref="P: RuleKey" /> property. /// </param> /// <param name="level"> /// An initialization value for the <see cref="P: Level" /> property. /// </param> /// <param name="message"> /// An initialization value for the <see cref="P: Message" /> property. /// </param> /// <param name="formattedRuleMessage"> /// An initialization value for the <see cref="P: FormattedRuleMessage" /> property. /// </param> /// <param name="locations"> /// An initialization value for the <see cref="P: Locations" /> property. /// </param> /// <param name="snippet"> /// An initialization value for the <see cref="P: Snippet" /> property. /// </param> /// <param name="id"> /// An initialization value for the <see cref="P: Id" /> property. /// </param> /// <param name="toolFingerprintContribution"> /// An initialization value for the <see cref="P: ToolFingerprintContribution" /> property. /// </param> /// <param name="stacks"> /// An initialization value for the <see cref="P: Stacks" /> property. /// </param> /// <param name="codeFlows"> /// An initialization value for the <see cref="P: CodeFlows" /> property. /// </param> /// <param name="relatedLocations"> /// An initialization value for the <see cref="P: RelatedLocations" /> property. /// </param> /// <param name="suppressionStates"> /// An initialization value for the <see cref="P: SuppressionStates" /> property. /// </param> /// <param name="baselineState"> /// An initialization value for the <see cref="P: BaselineState" /> property. /// </param> /// <param name="fixes"> /// An initialization value for the <see cref="P: Fixes" /> property. /// </param> /// <param name="properties"> /// An initialization value for the <see cref="P: Properties" /> property. /// </param> public Result(string ruleId, string ruleKey, ResultLevel level, string message, FormattedRuleMessage formattedRuleMessage, IEnumerable<Location> locations, string snippet, string id, string toolFingerprintContribution, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IEnumerable<AnnotatedCodeLocation> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties) { Init(ruleId, ruleKey, level, message, formattedRuleMessage, locations, snippet, id, toolFingerprintContribution, stacks, codeFlows, relatedLocations, suppressionStates, baselineState, fixes, properties); }
public FixableResult (DomRegion region, string message, ResultLevel level, ResultCertainty certainty, ResultImportance importance, params IAnalysisFix[] fixes) : base (region, message, level, certainty, importance) { this.Fixes = fixes; }
public void LevelIsHigherThanOrEqualToThresholdTest(ResultLevel threshold, ResultLevel actualLevel, bool isHigher) { var actualIsHigher = ResultLevelHelper.LevelIsHigherThanOrEqualToThreshold(threshold, actualLevel); Assert.AreEqual(isHigher, actualIsHigher); }
public MappingResult(ResultLevel level, string message, IDataSourceLocation dataSourceLocation) { _level = level; _message = message; _dataSourceLocation = dataSourceLocation; }
private void Init(string id, string name, string shortDescription, string fullDescription, IDictionary<string, string> messageFormats, RuleConfiguration configuration, ResultLevel defaultLevel, Uri helpUri, IDictionary<string, SerializedPropertyInfo> properties) { Id = id; Name = name; ShortDescription = shortDescription; FullDescription = fullDescription; if (messageFormats != null) { MessageFormats = new Dictionary<string, string>(messageFormats); } Configuration = configuration; DefaultLevel = defaultLevel; if (helpUri != null) { HelpUri = new Uri(helpUri.OriginalString, helpUri.IsAbsoluteUri ? UriKind.Absolute : UriKind.Relative); } if (properties != null) { Properties = new Dictionary<string, SerializedPropertyInfo>(properties); } }
/// <summary> /// Initializes a new instance of the <see cref="Rule" /> class from the supplied values. /// </summary> /// <param name="id"> /// An initialization value for the <see cref="P: Id" /> property. /// </param> /// <param name="name"> /// An initialization value for the <see cref="P: Name" /> property. /// </param> /// <param name="shortDescription"> /// An initialization value for the <see cref="P: ShortDescription" /> property. /// </param> /// <param name="fullDescription"> /// An initialization value for the <see cref="P: FullDescription" /> property. /// </param> /// <param name="messageFormats"> /// An initialization value for the <see cref="P: MessageFormats" /> property. /// </param> /// <param name="configuration"> /// An initialization value for the <see cref="P: Configuration" /> property. /// </param> /// <param name="defaultLevel"> /// An initialization value for the <see cref="P: DefaultLevel" /> property. /// </param> /// <param name="helpUri"> /// An initialization value for the <see cref="P: HelpUri" /> property. /// </param> /// <param name="properties"> /// An initialization value for the <see cref="P: Properties" /> property. /// </param> public Rule(string id, string name, string shortDescription, string fullDescription, IDictionary<string, string> messageFormats, RuleConfiguration configuration, ResultLevel defaultLevel, Uri helpUri, IDictionary<string, SerializedPropertyInfo> properties) { Init(id, name, shortDescription, fullDescription, messageFormats, configuration, defaultLevel, helpUri, properties); }
private Result MakeResultFromTestCase(ResultLevel level, Region region, string path) { return new Result { RuleId = TestRuleId, Level = level, Locations = new List<Location> { new Location { AnalysisTarget = new PhysicalLocation { Uri = new Uri(path, UriKind.RelativeOrAbsolute), Region = region } } }, FormattedRuleMessage = new FormattedRuleMessage { FormatId = TestFormatId, Arguments = new List<string> { "42", "54" } } }; }
static string GetIcon (ResultLevel severity) { switch (severity) { case ResultLevel.Error: return Gtk.Stock.DialogError; case ResultLevel.Warning: return Gtk.Stock.DialogWarning; case ResultLevel.Suggestion: return Gtk.Stock.Info; default: return null; } }
public ParseResult(ResultLevel resultLevel) { ResultLevel = resultLevel; }
public ParseResult(ResultLevel resultLevel, string message) { ResultLevel = resultLevel; Message = message; }
private void Init(string ruleId, ResultLevel level, Message message, string ruleMessageId, FileLocation analysisTarget, IEnumerable <Location> locations, string instanceGuid, string correlationGuid, IDictionary <string, string> partialFingerprints, IDictionary <string, string> fingerprints, IEnumerable <Stack> stacks, IEnumerable <CodeFlow> codeFlows, IEnumerable <Graph> graphs, IEnumerable <GraphTraversal> graphTraversals, IEnumerable <Location> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable <Attachment> attachments, IEnumerable <Uri> workItemUris, IEnumerable <PhysicalLocation> conversionProvenance, IEnumerable <Fix> fixes, IDictionary <string, SerializedPropertyInfo> properties) { RuleId = ruleId; Level = level; if (message != null) { Message = new Message(message); } RuleMessageId = ruleMessageId; if (analysisTarget != null) { AnalysisTarget = new FileLocation(analysisTarget); } if (locations != null) { var destination_0 = new List <Location>(); foreach (var value_0 in locations) { if (value_0 == null) { destination_0.Add(null); } else { destination_0.Add(new Location(value_0)); } } Locations = destination_0; } InstanceGuid = instanceGuid; CorrelationGuid = correlationGuid; if (partialFingerprints != null) { PartialFingerprints = new Dictionary <string, string>(partialFingerprints); } if (fingerprints != null) { Fingerprints = new Dictionary <string, string>(fingerprints); } if (stacks != null) { var destination_1 = new List <Stack>(); foreach (var value_1 in stacks) { if (value_1 == null) { destination_1.Add(null); } else { destination_1.Add(new Stack(value_1)); } } Stacks = destination_1; } if (codeFlows != null) { var destination_2 = new List <CodeFlow>(); foreach (var value_2 in codeFlows) { if (value_2 == null) { destination_2.Add(null); } else { destination_2.Add(new CodeFlow(value_2)); } } CodeFlows = destination_2; } if (graphs != null) { var destination_3 = new List <Graph>(); foreach (var value_3 in graphs) { if (value_3 == null) { destination_3.Add(null); } else { destination_3.Add(new Graph(value_3)); } } Graphs = destination_3; } if (graphTraversals != null) { var destination_4 = new List <GraphTraversal>(); foreach (var value_4 in graphTraversals) { if (value_4 == null) { destination_4.Add(null); } else { destination_4.Add(new GraphTraversal(value_4)); } } GraphTraversals = destination_4; } if (relatedLocations != null) { var destination_5 = new List <Location>(); foreach (var value_5 in relatedLocations) { if (value_5 == null) { destination_5.Add(null); } else { destination_5.Add(new Location(value_5)); } } RelatedLocations = destination_5; } SuppressionStates = suppressionStates; BaselineState = baselineState; if (attachments != null) { var destination_6 = new List <Attachment>(); foreach (var value_6 in attachments) { if (value_6 == null) { destination_6.Add(null); } else { destination_6.Add(new Attachment(value_6)); } } Attachments = destination_6; } if (workItemUris != null) { var destination_7 = new List <Uri>(); foreach (var value_7 in workItemUris) { destination_7.Add(value_7); } WorkItemUris = destination_7; } if (conversionProvenance != null) { var destination_8 = new List <PhysicalLocation>(); foreach (var value_8 in conversionProvenance) { if (value_8 == null) { destination_8.Add(null); } else { destination_8.Add(new PhysicalLocation(value_8)); } } ConversionProvenance = destination_8; } if (fixes != null) { var destination_9 = new List <Fix>(); foreach (var value_9 in fixes) { if (value_9 == null) { destination_9.Add(null); } else { destination_9.Add(new Fix(value_9)); } } Fixes = destination_9; } if (properties != null) { Properties = new Dictionary <string, SerializedPropertyInfo>(properties); } }
public bool ShouldLog(ResultLevel level) { switch (level) { case ResultLevel.Note: case ResultLevel.Pass: case ResultLevel.NotApplicable: { if (!Verbose) { return false; } break; } case ResultLevel.Error: case ResultLevel.Default: case ResultLevel.Warning: { break; } default: { throw new InvalidOperationException(); } } return true; }
private void Init(string ruleId, string ruleKey, ResultLevel level, string message, FormattedRuleMessage formattedRuleMessage, IEnumerable<Location> locations, string snippet, string id, string toolFingerprintContribution, IEnumerable<Stack> stacks, IEnumerable<CodeFlow> codeFlows, IEnumerable<AnnotatedCodeLocation> relatedLocations, SuppressionStates suppressionStates, BaselineState baselineState, IEnumerable<Fix> fixes, IDictionary<string, SerializedPropertyInfo> properties) { RuleId = ruleId; RuleKey = ruleKey; Level = level; Message = message; if (formattedRuleMessage != null) { FormattedRuleMessage = new FormattedRuleMessage(formattedRuleMessage); } if (locations != null) { var destination_0 = new List<Location>(); foreach (var value_0 in locations) { if (value_0 == null) { destination_0.Add(null); } else { destination_0.Add(new Location(value_0)); } } Locations = destination_0; } Snippet = snippet; Id = id; ToolFingerprintContribution = toolFingerprintContribution; if (stacks != null) { var destination_1 = new List<Stack>(); foreach (var value_1 in stacks) { if (value_1 == null) { destination_1.Add(null); } else { destination_1.Add(new Stack(value_1)); } } Stacks = destination_1; } if (codeFlows != null) { var destination_2 = new List<CodeFlow>(); foreach (var value_2 in codeFlows) { if (value_2 == null) { destination_2.Add(null); } else { destination_2.Add(new CodeFlow(value_2)); } } CodeFlows = destination_2; } if (relatedLocations != null) { var destination_3 = new List<AnnotatedCodeLocation>(); foreach (var value_3 in relatedLocations) { if (value_3 == null) { destination_3.Add(null); } else { destination_3.Add(new AnnotatedCodeLocation(value_3)); } } RelatedLocations = destination_3; } SuppressionStates = suppressionStates; BaselineState = baselineState; if (fixes != null) { var destination_4 = new List<Fix>(); foreach (var value_4 in fixes) { if (value_4 == null) { destination_4.Add(null); } else { destination_4.Add(new Fix(value_4)); } } Fixes = destination_4; } if (properties != null) { Properties = new Dictionary<string, SerializedPropertyInfo>(properties); } }
private void LogJsonIssue(ResultLevel level, string targetPath, Region region, string ruleId, string formatId, params string[] arguments) { if (!ShouldLog(level)) { return; } Result result = new Result(); result.RuleId = ruleId; result.FormattedRuleMessage = new FormattedRuleMessage() { FormatId = formatId, Arguments = arguments }; result.Level = level; if (targetPath != null) { result.Locations = new List<Location> { new Sarif.Location { AnalysisTarget = new PhysicalLocation { Uri = new Uri(targetPath), Region = region } }}; } _issueLogJsonWriter.WriteResult(result); }
private static string GetMessageText( Uri uri, Region region, string ruleId, string message, ResultLevel resultLevel) { string path = null; if (uri != null) { // If a path refers to a URI of form file://blah, we will convert to the local path if (uri.IsAbsoluteUri && uri.Scheme == Uri.UriSchemeFile) { path = uri.LocalPath; } else { path = uri.ToString(); } } string issueType = null; switch (resultLevel) { case ResultLevel.Error: issueType = "error"; break; case ResultLevel.Warning: issueType = "warning"; break; case ResultLevel.NotApplicable: case ResultLevel.Note: case ResultLevel.Pass: issueType = "info"; break; default: throw new InvalidOperationException("Unknown message kind:" + resultLevel.ToString()); } string detailedDiagnosis = NormalizeMessage(message, enquote: false); string location = ""; if (region != null) { // TODO if (region.Offset > 0 || region.StartColumn == 0) { throw new NotImplementedException(); } if (region.StartLine == 0) { throw new InvalidOperationException(); } location = region.FormatForVisualStudio(); } string result = (path != null ? (path + location + ": ") : "") + issueType + (!string.IsNullOrEmpty(ruleId) ? " " : "") + (resultLevel != ResultLevel.Note ? ruleId : "") + ": " + detailedDiagnosis; return result; }
public void Log(ResultLevel messageKind, IAnalysisContext context, Region region, string formatId, params string[] arguments) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Rule != null) { Rules[context.Rule.Id] = context.Rule; } formatId = RuleUtilities.NormalizeFormatId(context.Rule.Id, formatId); LogJsonIssue(messageKind, context.TargetUri.LocalPath, region, context.Rule.Id, formatId, arguments); }