public SupportedDiagnosticAttribute(DiagnosticId code, DiagnosticSeverity severity = DiagnosticSeverity.Warning,
                                     DiagnosticCategory category = DiagnosticCategory.Security)
 {
     Code     = code.ToString();
     Severity = severity;
     Category = category;
 }
Пример #2
0
 public static string GetMessage(this DiagnosticId diagnosticId)
 {
     return(Resources.ResourceManager.GetString(diagnosticId.ToString()));
 }
        /// <summary>
        /// Adds a <see cref="StatusData"/> record to the <see cref="ReceivedStatusData"/> of this <see cref="TrackedDiagnostic"/>.
        /// </summary>
        /// <param name="statusData">The <see cref="StatusData"/> record to be added.</param>
        public void AddData(StatusData statusData)
        {
            // Throw exception if there is an attempt to add StatusData and this TrackedDiagnostic does not represent a Diagnostic of the StatusData category.
            if (DiagnosticCategoryType != DiagnosticCategory.StatusData)
            {
                throw new ArgumentException($"This TrackedDiagnostic represents a Diagnostic of the type '{DiagnosticCategoryType}' and cannot accept StatusData.");
            }

            // Validate to ensure StatusData is for the subject Device and Diagnostic.
            if (statusData.Device.Id != DeviceId)
            {
                throw new ArgumentException($"The supplied StatusData is for a Device with Id '{statusData.Device.Id.ToString()}' and cannot be added to this TrackedDiagnostic which represents the Device with Id '{DeviceId.ToString()}'.");
            }
            if (statusData.Diagnostic.Id != DiagnosticId)
            {
                throw new ArgumentException($"The supplied StatusData is for a Diagnostic with Id '{statusData.Diagnostic.Id.ToString()}' and cannot be added to this TrackedDiagnostic which represents the Diagnostic with Id '{DiagnosticId.ToString()}'.");
            }
            receivedStatusData.Add(statusData);

            // Update DeviceName with that of the statusData in case the device name has changed (the statusData will have the latest version of the Device since it gets updated with the device cache in the FeedProcessor before this AddData() method is called.
            if (DeviceName != statusData.Device.Name)
            {
                DeviceName = statusData.Device.Name;
            }
        }