Inheritance: PropertyBagHolder, ISarifNode
Example #1
0
        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();
        }
Example #2
0
 public bool ValueEquals(Notification other) => ValueComparer.Equals(this, other);
Example #3
0
        /// <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);
        }
Example #4
0
        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;
        }
Example #5
0
        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();
            }
        }
Example #6
0
        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();
        }
Example #7
0
 public void LogToolNotification(Notification notification)
 {
     WriteToConsole(notification);
 }
Example #8
0
 public void LogConfigurationNotification(Notification notification)
 {
     WriteToConsole(notification);
 }
Example #9
0
 public void LogToolNotification(Notification notification)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public void LogConfigurationNotification(Notification notification)
 {
     ConfigurationErrorTargets.Add(notification.PhysicalLocation.Uri.LocalPath);
 }