Beispiel #1
0
        /// <summary>
        /// Remove the specified error from the Error List.
        /// </summary>
        /// <param name="errorToRemove">
        /// The error to remove from the Error List.
        /// </param>
        public void RemoveError(SarifErrorListItem errorToRemove)
        {
            using (this.tableEntriesLock.EnterWriteLock())
            {
                // Find the dictionary entry for the one log file that contains the error to be
                // removed. Any given error object can appear in at most one log file, even if
                // multiple log files report the "same" error.
                List <SarifResultTableEntry> tableEntryListWithSpecifiedError =
                    this.logFileToTableEntries.Values
                    .SingleOrDefault(tableEntryList => tableEntryList.Select(tableEntry => tableEntry.Error).Contains(errorToRemove));

                if (tableEntryListWithSpecifiedError != null)
                {
                    // Any give error object can appear at most once in any log file, even if the
                    // log file reports the "same" error multiple times. And we've already seen
                    // that this error object does appear in this log file, so calling Single is
                    // just fine.
                    SarifResultTableEntry entryToRemove = tableEntryListWithSpecifiedError.Single(tableEntry => tableEntry.Error == errorToRemove);

                    this.CallSinks(sink => sink.RemoveEntries(new[] { entryToRemove }));

                    tableEntryListWithSpecifiedError.Remove(entryToRemove);

                    entryToRemove.Dispose();
                }
            }
        }
Beispiel #2
0
        public void ClearErrorsForLogFiles(IEnumerable <string> logFiles)
        {
            IImmutableList <SarifResultTableEntry> entriesToRemove;

            using (this.tableEntriesLock.EnterWriteLock())
            {
                IEnumerable <KeyValuePair <string, List <SarifResultTableEntry> > > logFileToTableEntriesToRemove = this.logFileToTableEntries.
                                                                                                                    Where((logFileToTableEntry) => logFiles.Contains(logFileToTableEntry.Key)).ToList();

                entriesToRemove = logFileToTableEntriesToRemove.SelectMany((logFileToTableEntry) => logFileToTableEntry.Value).
                                  ToImmutableList();

                foreach (KeyValuePair <string, List <SarifResultTableEntry> > logFilesToRemove in logFileToTableEntriesToRemove)
                {
                    this.logFileToTableEntries.Remove(logFilesToRemove.Key);
                }

                // checking if logFiles exists in any analysis
                if (this.logFileToTableEntries.Any(log => log.Value.Any(error => logFiles.Contains(error.Error.FileName))))
                {
                    KeyValuePair <string, List <SarifResultTableEntry> > kvp = this.logFileToTableEntries
                                                                               .First(log => log.Value.Any(error => logFiles.Contains(error.Error.FileName)));
                    SarifResultTableEntry sarifResult = kvp.Value.First(result => logFiles.Contains(result.Error.FileName));
                    kvp.Value.Remove(sarifResult);
                    this.logFileToTableEntries[kvp.Key] = kvp.Value;

                    entriesToRemove.Add(sarifResult);
                }
            }

            this.CallSinks(sink => sink.RemoveEntries(entriesToRemove));

            foreach (SarifResultTableEntry entryToRemove in entriesToRemove)
            {
                entryToRemove.Dispose();
            }
        }