public void SarifLogger_DoNotScrapeFilesFromNotifications() { var sb = new StringBuilder(); using (var textWriter = new StringWriter(sb)) { using (var sarifLogger = new SarifLogger( textWriter, analysisTargets: null, verbose: false, computeTargetsHash: true, logEnvironment: false, prereleaseInfo: null, invocationTokensToRedact: null)) { var toolNotification = new Notification { PhysicalLocation = new PhysicalLocation { Uri = new Uri(@"file:///file0.cpp") } }; sarifLogger.LogToolNotification(toolNotification); var configurationNotification = new Notification { PhysicalLocation = new PhysicalLocation { Uri = new Uri(@"file:///file0.cpp") } }; sarifLogger.LogConfigurationNotification(configurationNotification); } } string logText = sb.ToString(); var sarifLog = JsonConvert.DeserializeObject<SarifLog>(logText); sarifLog.Runs[0].Files.Should().BeNull(); }
public bool ValueEquals(Notification other) => ValueComparer.Equals(this, other);
/// <summary> /// Initializes a new instance of the <see cref="Notification" /> class from the specified instance. /// </summary> /// <param name="other"> /// The instance from which the new instance is to be initialized. /// </param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="other" /> is null. /// </exception> public Notification(Notification other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } Init(other.Id, other.RuleId, other.RuleKey, other.PhysicalLocation, other.Message, other.Level, other.ThreadId, other.Time, other.Exception, other.Properties); }
private static Notification CreateNotification( Uri uri, string notificationId, string ruleId, NotificationLevel level, Exception exception, bool persistExceptionStack, params object[] args) { string messageFormat = GetMessageFormatResourceForNotification(notificationId); string message = string.Format(CultureInfo.CurrentCulture, messageFormat, args); string exceptionMessage = exception?.Message; if (!string.IsNullOrEmpty(exceptionMessage)) { message += string.Format(CultureInfo.InvariantCulture, SdkResources.NotificationWithExceptionMessage, message, exceptionMessage); } var exceptionData = exception != null && persistExceptionStack ? ExceptionData.Create(exception) : null; var physicalLocation = uri != null ? new PhysicalLocation { Uri = uri } : null; var notification = new Notification { PhysicalLocation = physicalLocation, Id = notificationId, RuleId = ruleId, Level = level, Message = message, Exception = exceptionData }; return notification; }
private void WriteToConsole(Notification notification) { switch (notification.Level) { // This notification type is optionally emitted. case NotificationLevel.Note: if (Verbose) { Console.WriteLine(FormatNotificationMessage(notification)); } break; // These notification types are always emitted. case NotificationLevel.Error: case NotificationLevel.Warning: Console.WriteLine(FormatNotificationMessage(notification)); break; default: throw new InvalidOperationException(); } }
private string FormatNotificationMessage(Notification notification) { string issueType = null; switch (notification.Level) { case NotificationLevel.Error: { issueType = "error"; break; } case NotificationLevel.Warning: { issueType = "warning"; break; } case NotificationLevel.Note: { issueType = "note"; break; } default: throw new InvalidOperationException("Unknown notification level: " + notification.Level); } var sb = new StringBuilder(issueType); if (!string.IsNullOrEmpty(notification.Id)) { sb.Append(notification.Id + " : "); } if (!string.IsNullOrEmpty(notification.RuleId)) { sb.Append(notification.RuleId + " : "); } sb.Append(notification.Message); return sb.ToString(); }
public void LogToolNotification(Notification notification) { WriteToConsole(notification); }
public void LogConfigurationNotification(Notification notification) { WriteToConsole(notification); }
public void LogToolNotification(Notification notification) { throw new NotImplementedException(); }
public void LogConfigurationNotification(Notification notification) { ConfigurationErrorTargets.Add(notification.PhysicalLocation.Uri.LocalPath); }