/// <summary> /// Verifies if the object should be picked, based on the filter passed as argument. /// </summary> /// <param name="container">Object to be analyzed.</param> /// <param name="description">Optional description to be searched.</param> /// <param name="filter">Filter to be applied.</param> /// <returns>True if any string in the filter is present in any text field of the object.</returns> /// <remarks>It analyzes the Name, the Description and eventual Text properties. /// <para>The search is case-insensitive.</para></remarks> public static bool Filter(this IPropertiesContainer container, string description, [Required] string filter) { var name = container.ToString(); var result = (!string.IsNullOrWhiteSpace(name) && name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) || (!string.IsNullOrWhiteSpace(description) && description.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0); if (!result) { var properties = container.Properties?.ToArray(); if (properties?.Any() ?? false) { foreach (var property in properties) { var stringValue = property.StringValue; if ((!string.IsNullOrWhiteSpace(stringValue) && stringValue.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)) { result = true; break; } } } } return(result); }
private void AddItem([NotNull] IQualityAnalyzer analyzer, [NotNull] IPropertiesContainer container, [NotNull] IPropertyType propertyType) { var property = container.GetProperty(propertyType) as IPropertyJsonSerializableObject; if (property != null) { var list = property.Value as FalsePositiveList; var finding = list?.FalsePositives.FirstOrDefault(x => string.CompareOrdinal(x.QualityInitializerId, analyzer.GetExtensionId()) == 0); if (finding != null) { _falsePositives.PrimaryGrid.Rows.Add(new GridRow(container.ToString(), finding.Reason, finding.Author, finding.Timestamp) { Tag = container }); } } if (container is IThreatEventsContainer threatEventsContainer) { var threatEvents = threatEventsContainer.ThreatEvents?.ToArray(); if (threatEvents?.Any() ?? false) { foreach (var te in threatEvents) { AddItem(analyzer, te, propertyType); } } } }