public Task <IReadOnlyList <ITemplateNameSearchResult> > CheckForTemplateNameMatchesAsync(string searchName)
        {
            if (SearchCache == null)
            {
                throw new Exception("Search Source is not configured");
            }

            IReadOnlyList <ITemplateInfo>          templateMatches    = SearchCache.GetNameMatchedTemplates(searchName);
            IReadOnlyList <string>                 templateIdentities = templateMatches.Select(t => t.Identity).ToList();
            IReadOnlyDictionary <string, PackInfo> templateToPackMap  = SearchCache.GetTemplateToPackMapForTemplateIdentities(templateIdentities);

            List <ITemplateNameSearchResult> resultList = new List <ITemplateNameSearchResult>();

            foreach (ITemplateInfo candidateTemplateInfo in templateMatches)
            {
                if (!templateToPackMap.TryGetValue(candidateTemplateInfo.Identity, out PackInfo candidatePackInfo))
                {
                    // The pack was not found for the template. This can't realistically occur.
                    // The continue safeguards against the possibility that somehow the map got messed up.
                    continue;
                }

                if (_packFilter.ShouldPackBeFiltered(candidatePackInfo.Name, candidatePackInfo.Version))
                {
                    // something already installed says this should be filtered.
                    continue;
                }

                ITemplateNameSearchResult result = CreateNameSearchResult(candidateTemplateInfo, candidatePackInfo);

                resultList.Add(result);
            }

            return(Task.FromResult((IReadOnlyList <ITemplateNameSearchResult>)resultList));
        }
Beispiel #2
0
        public Task <IReadOnlyList <ITemplateNameSearchResult> > CheckForTemplateNameMatchesAsync(string templateName)
        {
            List <ITemplateNameSearchResult> matches = new List <ITemplateNameSearchResult>();

            IReadOnlyList <ITemplateNameSearchResult> possibleSearchResults = GetPossibleResultsOrDefaultForId(_id);

            foreach (ITemplateNameSearchResult candidate in possibleSearchResults)
            {
                if (candidate.Template.Name.Contains(templateName) || candidate.Template.ShortNameList.Any(shortName => shortName.Contains(templateName)))
                {
                    if (!_packFilter.ShouldPackBeFiltered(candidate.Template.Name, candidate.PackInfo.Version))
                    {
                        matches.Add(candidate);
                    }
                }
            }

            IReadOnlyList <ITemplateNameSearchResult> returnResults = matches;

            return(Task.FromResult(returnResults));
        }