private static async Task AddInfoBarIfRequiredAsync( ExceptionalConditions detectedConditions, ExceptionalConditions individualCondition, string message, ImageMoniker imageMoniker) { InfoBar infoBar = null; if ((detectedConditions & individualCondition) == individualCondition) { using (s_infoBarLock.EnterWriteLock()) { if (!s_infoBarToConditionDictionary.Values.Contains(individualCondition)) { infoBar = new InfoBar(message, imageMoniker: imageMoniker); if (!s_infoBarToConditionDictionary.TryAdd(infoBar, individualCondition)) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.ErrorInfoBarAlreadyPresent, individualCondition)); } } } } if (infoBar != null) { await infoBar.ShowAsync(); } }
/// <summary> /// Display info bars appropriate to the specified set of "exceptional conditions". /// </summary> /// <param name="conditions"> /// The conditions that require an info bar to be shown. /// </param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> internal static async Task CreateInfoBarsForExceptionalConditionsAsync(ExceptionalConditions conditions) { // The most recently shown bar is displayed at the bottom, so show the bars in order // of decreasing severity. Note that this only works within the info bars shown for // a single SARIF log. Across logs, the "most recent" rule means that the bars are // show in the order the logs are processed. So if the first log has an info-level bar // and the second has an error-level bar, the info-level bar will be on top. await AddInfoBarIfRequiredAsync( conditions, ExceptionalConditions.InvalidJson, Resources.ErrorInvalidSarifStream, KnownMonikers.StatusError); await AddInfoBarIfRequiredAsync( conditions, ExceptionalConditions.ExecutionError, Resources.ErrorLogHasErrorLevelToolExecutionNotifications, KnownMonikers.StatusError); await AddInfoBarIfRequiredAsync( conditions, ExceptionalConditions.ConfigurationError, Resources.ErrorLogHasErrorLevelToolConfigurationNotifications, KnownMonikers.StatusError); await AddInfoBarIfRequiredAsync( conditions, ExceptionalConditions.NoResults, Resources.InfoNoResultsInLog, KnownMonikers.StatusInformation); }
/// <summary> /// Calculates the "exceptional conditions", such as the lack of results or the presence of /// catastrophic errors, encountered while processing a SARIF log. /// </summary> /// <param name="log"> /// The SARIF log to analyze, or null if the log could not be parsed because it was not in /// valid JSON format. /// </param> /// <returns> /// A set of flags specifying all the exceptional conditions present in <paramref name="log"/>. /// </returns> internal static ExceptionalConditions Calculate(SarifLog log) { ExceptionalConditions conditions = ExceptionalConditions.None; if (log != null) { if (log.HasErrorLevelToolConfigurationNotifications()) { conditions |= ExceptionalConditions.ConfigurationError; } if (log.HasErrorLevelToolExecutionNotifications()) { conditions |= ExceptionalConditions.ExecutionError; } // If any error conditions are present, don't bother to mention the fact that there // were no results. if (conditions == ExceptionalConditions.None && !log.HasResults()) { conditions |= ExceptionalConditions.NoResults; } } else { conditions |= ExceptionalConditions.InvalidJson; } return(conditions); }
private static async Task ShowInfoBarAsync(ExceptionalConditions conditions) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); InfoBar.CreateInfoBarsForExceptionalConditionsAsync(conditions).FileAndForget(FileAndForgetEventName.InfoBarOpenFailure); // After Sarif results loaded to Error List, make sure Viewer package is loaded SarifViewerPackage.LoadViewerPackage(); }
/// <summary> /// Calculates the "exceptional conditions", such as the lack of results or the presence of /// catastrophic errors, encountered while processing a set of SARIF logs. /// </summary> /// <param name="logs"> /// The SARIF logs to analyze. A log value of null means that the log could not be parsed /// because it was not in valid JSON format. /// </param> /// <returns> /// A set of flags specifying all the exceptional conditions present in at least one of /// the <paramref name="logs"/>. /// </returns> internal static ExceptionalConditions Calculate(IEnumerable <SarifLog> logs) { logs = logs ?? throw new ArgumentNullException(nameof(logs)); ExceptionalConditions conditions = ExceptionalConditions.None; foreach (SarifLog log in logs) { conditions |= Calculate(log); } return(conditions); }
public void ExceptionalConditionsCalculator_ProducesExpectedResults() { var sb = new StringBuilder(); foreach (TestCase testCase in s_testCases) { ExceptionalConditions actualResult = ExceptionalConditionsCalculator.Calculate(testCase.Log); if (actualResult != testCase.ExpectedResult) { sb.Append(" ").Append(testCase.Name).Append(": expected ").Append(testCase.ExpectedResult) .Append(" but got ").Append(actualResult).AppendLine(); } } sb.Length.Should().Be(0, "failed test cases:\n" + sb.ToString()); }
public LogProcessedEventArgs(ExceptionalConditions exceptionalConditions) { ExceptionalConditions = exceptionalConditions; }
private static void RaiseLogProcessed(ExceptionalConditions conditions) { LogProcessed?.Invoke(Instance, new LogProcessedEventArgs(conditions)); }