Exemple #1
0
        public static IEnumerable <IPackage> FilterOnName(IEnumerable <IPackage> pkgs, string searchTerm, bool useWildCard)
        {
            if (useWildCard)
            {
                // Applying the wildcard pattern matching
                const SMA.WildcardOptions wildcardOptions = SMA.WildcardOptions.CultureInvariant | SMA.WildcardOptions.IgnoreCase;
                var wildcardPattern = new SMA.WildcardPattern(searchTerm, wildcardOptions);

                return(pkgs.Where(p => wildcardPattern.IsMatch(p.Id)));
            }
            else
            {
                return(pkgs.Where(each => each.Id.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1));
            }
        }
Exemple #2
0
        public static bool IsValidByName(PackageEntryInfo packageEntry, NuGetSearchContext searchContext)
        {
            NuGetSearchTerm originalPsTerm = searchContext.SearchTerms == null ?
                                             null : searchContext.SearchTerms.Where(st => st.Term == NuGetSearchTerm.NuGetSearchTermType.OriginalPSPattern).FirstOrDefault();
            bool valid = true;

            if (originalPsTerm != null)
            {
                if (!String.IsNullOrWhiteSpace(originalPsTerm.Text) && SMA.WildcardPattern.ContainsWildcardCharacters(originalPsTerm.Text))
                {
                    // Applying the wildcard pattern matching
                    const SMA.WildcardOptions wildcardOptions = SMA.WildcardOptions.CultureInvariant | SMA.WildcardOptions.IgnoreCase;
                    var wildcardPattern = new SMA.WildcardPattern(originalPsTerm.Text, wildcardOptions);

                    valid = wildcardPattern.IsMatch(packageEntry.Id);
                }
                else if (!String.IsNullOrWhiteSpace(originalPsTerm.Text))
                {
                    valid = packageEntry.Id.IndexOf(originalPsTerm.Text, StringComparison.OrdinalIgnoreCase) > -1;
                }
            }

            return(valid);
        }