// Lists all the templates, filtered only by the context (item, project, etc) - and the host file. public static IReadOnlyCollection <ITemplateMatchInfo> PerformAllTemplatesInContextQuery(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, string context) { // If there is a context match, it must be exact. Other dispositions are irrelevant. Func <ITemplateMatchInfo, bool> contextFilter = x => x.MatchDisposition.All(d => d.Location != MatchLocation.Context || d.Kind == MatchKind.Exact); IReadOnlyCollection <ITemplateMatchInfo> templates = TemplateListFilter.GetTemplateMatchInfo ( templateInfo, contextFilter, WellKnownSearchFilters.ContextFilter(context), WellKnownSearchFilters.NameFilter(string.Empty) ) .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); return(templates); }
/// <summary> /// Performs filtering of provided template list for --search option. Filters applied: template name filter, --search option filters, template parameters filter. /// Only templates that exactly match the filters are returned. /// </summary> /// <param name="templateInfo">the list of templates to be filtered</param> /// <param name="hostDataLoader">data of the host</param> /// <param name="commandInput">new command data used in CLI</param> /// <returns>filtered list of templates</returns> public static IReadOnlyCollection<ITemplateMatchInfo> PerformCoreTemplateQueryForSearch(IEnumerable<ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput) { IReadOnlyList<FilterableTemplateInfo> filterableTemplateInfo = SetupFilterableTemplateInfoFromTemplateInfo(templateInfo.ToList()); List<Func<ITemplateInfo, MatchInfo?>> searchFilters = new List<Func<ITemplateInfo, MatchInfo?>>() { WellKnownSearchFilters.NameFilter(commandInput.TemplateName), }; searchFilters.AddRange(SupportedFilterOptions.SupportedSearchFilters .OfType<TemplateFilterOption>() .Select(filter => filter.TemplateMatchFilter(commandInput))); IReadOnlyCollection<ITemplateMatchInfo> matchedTemplates = TemplateListFilter.GetTemplateMatchInfo(filterableTemplateInfo, TemplateListFilter.ExactMatchFilter, searchFilters.ToArray()); AddParameterMatchingToTemplates(matchedTemplates, hostDataLoader, commandInput); return matchedTemplates.Where(t => t.IsInvokableMatch()).ToList(); }
internal static IReadOnlyCollection <ITemplateMatchInfo> PerformAllTemplatesQuery(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader) { IReadOnlyList <ITemplateInfo> filterableTemplateInfo = SetupTemplateInfoWithGroupShortNames(templateInfo); // once template resolution refactoring is complete we would no longer use this method, but use GetTemplatesAsync instead as overriding group names should not be needed #pragma warning disable CS0618 // Type or member is obsolete IReadOnlyCollection <ITemplateMatchInfo> templates = TemplateListFilter.GetTemplateMatchInfo( filterableTemplateInfo, WellKnownSearchFilters.MatchesAtLeastOneCriteria, CliNameFilter(string.Empty) ) #pragma warning restore CS0618 // Type or member is obsolete .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); return(templates); }
// Query for template matches, filtered by everything available: name, language, context, parameters, and the host file. // this method is not used for list and help public static IReadOnlyCollection<ITemplateMatchInfo> PerformCoreTemplateQuery(IReadOnlyList<ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, string defaultLanguage) { IReadOnlyList<FilterableTemplateInfo> filterableTemplateInfo = SetupFilterableTemplateInfoFromTemplateInfo(templateInfo); IReadOnlyCollection<ITemplateMatchInfo> templates = TemplateListFilter.GetTemplateMatchInfo ( filterableTemplateInfo, TemplateListFilter.PartialMatchFilter, WellKnownSearchFilters.NameFilter(commandInput.TemplateName), WellKnownSearchFilters.ClassificationsFilter(commandInput.TemplateName), WellKnownSearchFilters.LanguageFilter(commandInput.Language), WellKnownSearchFilters.ContextFilter(commandInput.TypeFilter), WellKnownSearchFilters.BaselineFilter(commandInput.BaselineName) ) .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); IReadOnlyList<ITemplateMatchInfo> coreMatchedTemplates = templates.Where(x => x.IsMatch).ToList(); if (coreMatchedTemplates.Count == 0) { // No exact matches, take the partial matches and be done. coreMatchedTemplates = templates.Where(x => x.IsPartialMatch).ToList(); } else { IReadOnlyList<ITemplateMatchInfo> matchesWithExactDispositionsInNameFields = coreMatchedTemplates.Where(x => x.MatchDisposition.Any(y => NameFields.Contains(y.Location) && y.Kind == MatchKind.Exact)).ToList(); if (matchesWithExactDispositionsInNameFields.Count > 0) { // Start with the exact name matches, if there are any. coreMatchedTemplates = matchesWithExactDispositionsInNameFields; } } if (string.IsNullOrEmpty(commandInput.Language) && !string.IsNullOrEmpty(defaultLanguage)) { // default language matching only makes sense if the user didn't specify a language. AddDefaultLanguageMatchingToTemplates(coreMatchedTemplates, defaultLanguage); } AddParameterMatchingToTemplates(coreMatchedTemplates, hostDataLoader, commandInput); return coreMatchedTemplates; }
internal static IReadOnlyCollection <ITemplateMatchInfo> PerformCoreTemplateQueryForSearch(IEnumerable <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput) { IReadOnlyList <ITemplateInfo> filterableTemplateInfo = SetupTemplateInfoWithGroupShortNames(templateInfo.ToList()); List <Func <ITemplateInfo, MatchInfo?> > searchFilters = new List <Func <ITemplateInfo, MatchInfo?> >() { CliNameFilter(commandInput.TemplateName), }; searchFilters.AddRange(SupportedFilterOptions.SupportedSearchFilters .OfType <TemplateFilterOption>() .Select(filter => filter.TemplateMatchFilter(commandInput))); // once template resolution refactoring is complete we would no longer use this method, but use GetTemplatesAsync instead as overriding group names should not be needed #pragma warning disable CS0618 // Type or member is obsolete IReadOnlyCollection <ITemplateMatchInfo> matchedTemplates = TemplateListFilter.GetTemplateMatchInfo(filterableTemplateInfo, WellKnownSearchFilters.MatchesAllCriteria, searchFilters.ToArray()); #pragma warning restore CS0618 // Type or member is obsolete AddParameterMatchingToTemplates(matchedTemplates, hostDataLoader, commandInput); return(matchedTemplates.Where(t => t.IsInvokableMatch()).ToList()); }
// Query for template matches, filtered by everything available: name, language, context, parameters, and the host file. public static TemplateListResolutionResult PerformCoreTemplateQuery(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, string defaultLanguage) { IReadOnlyCollection <IFilteredTemplateInfo> templates = TemplateListFilter.FilterTemplates ( templateInfo, false, WellKnownSearchFilters.NameFilter(commandInput.TemplateName), WellKnownSearchFilters.ClassificationsFilter(commandInput.TemplateName), WellKnownSearchFilters.LanguageFilter(commandInput.Language), WellKnownSearchFilters.ContextFilter(commandInput.TypeFilter?.ToLowerInvariant()), WellKnownSearchFilters.BaselineFilter(commandInput.BaselineName) ) .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); IReadOnlyList <IFilteredTemplateInfo> coreMatchedTemplates = templates.Where(x => x.IsMatch).ToList(); bool anyExactCoreMatches; if (coreMatchedTemplates.Count == 0) { coreMatchedTemplates = templates.Where(x => x.IsPartialMatch).ToList(); anyExactCoreMatches = false; } else { anyExactCoreMatches = true; IReadOnlyList <IFilteredTemplateInfo> matchesWithExactDispositionsInNameFields = coreMatchedTemplates.Where(x => x.MatchDisposition.Any(y => NameFields.Contains(y.Location) && y.Kind == MatchKind.Exact)).ToList(); if (matchesWithExactDispositionsInNameFields.Count > 0) { coreMatchedTemplates = matchesWithExactDispositionsInNameFields; } } TemplateListResolutionResult matchResults = new TemplateListResolutionResult() { CoreMatchedTemplates = coreMatchedTemplates }; QueryForUnambiguousTemplateGroup(templateInfo, hostDataLoader, commandInput, matchResults, defaultLanguage, anyExactCoreMatches); return(matchResults); }
public static IReadOnlyCollection <ITemplateMatchInfo> PerformCoreTemplateQueryForList(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, string defaultLanguage) { IReadOnlyList <FilterableTemplateInfo> filterableTemplateInfo = SetupFilterableTemplateInfoFromTemplateInfo(templateInfo); // for list we also try to get match on template name in classification (tags). These matches only will be used if short name and name has a mismatch. // filter below only sets the exact or partial match if name matches the tag. If name doesn't match the tag, no match disposition is added to collection. IReadOnlyList <ITemplateMatchInfo> coreMatchedTemplates = TemplateListFilter.GetTemplateMatchInfo ( filterableTemplateInfo, TemplateListFilter.PartialMatchFilter, WellKnownSearchFilters.NameFilter(commandInput.TemplateName), WellKnownSearchFilters.ClassificationsFilter(commandInput.TemplateName), WellKnownSearchFilters.LanguageFilter(commandInput.Language), WellKnownSearchFilters.ContextFilter(commandInput.TypeFilter), WellKnownSearchFilters.BaselineFilter(commandInput.BaselineName) ) .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); AddParameterMatchingToTemplates(coreMatchedTemplates, hostDataLoader, commandInput); return(coreMatchedTemplates); }
/// <summary> /// Performs the filtering of installed templates for template instantiated. /// Filters applied: template name filter; language, type, classification and baseline filters. Only templates that match the filters are returned, no partial matches allowed. /// In case any templates in match above are matching name or short name exactly, only they are returned. /// The matches for default language and template specific parameters are added to the result. /// </summary> /// <param name="templateInfo">the list of templates to be filtered</param> /// <param name="hostDataLoader">data of the host</param> /// <param name="commandInput">new command data used in CLI</param> /// <param name="defaultLanguage"></param> /// <returns>the collection of the templates with their match dispositions (<seealso cref="ITemplateMatchInfo"/>). The templates that do not match are not added to the collection</returns> public static IReadOnlyCollection <ITemplateMatchInfo> PerformCoreTemplateQuery(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, string defaultLanguage) { IReadOnlyList <FilterableTemplateInfo> filterableTemplateInfo = SetupFilterableTemplateInfoFromTemplateInfo(templateInfo); IReadOnlyCollection <ITemplateMatchInfo> templates = TemplateListFilter.GetTemplateMatchInfo ( filterableTemplateInfo, TemplateListFilter.ExactMatchFilter, WellKnownSearchFilters.NameFilter(commandInput.TemplateName), //WellKnownSearchFilters.ClassificationsFilter(commandInput.TemplateName), WellKnownSearchFilters.LanguageFilter(commandInput.Language), WellKnownSearchFilters.ContextFilter(commandInput.TypeFilter), WellKnownSearchFilters.BaselineFilter(commandInput.BaselineName) ) .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); //select only the templates which do not have mismatches //if any template has exact match for name - use those; otherwise partial name matches are also considered when resolving templates IReadOnlyList <ITemplateMatchInfo> matchesWithExactDispositionsInNameFields = templates.Where(x => x.MatchDisposition.Any(y => NameFields.Contains(y.Location) && y.Kind == MatchKind.Exact)).ToList(); if (matchesWithExactDispositionsInNameFields.Count > 0) { templates = matchesWithExactDispositionsInNameFields; } if (string.IsNullOrEmpty(commandInput.Language) && !string.IsNullOrEmpty(defaultLanguage)) { // add default language matches to the list // default language matching only makes sense if the user didn't specify a language. AddDefaultLanguageMatchingToTemplates(templates, defaultLanguage); } //add specific template parameters matches to the list AddParameterMatchingToTemplates(templates, hostDataLoader, commandInput); return(templates); }
internal static IReadOnlyCollection <ITemplateMatchInfo> PerformCoreTemplateQuery(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, string?defaultLanguage) { IReadOnlyList <ITemplateInfo> filterableTemplateInfo = SetupTemplateInfoWithGroupShortNames(templateInfo); #pragma warning disable CS0618 // Type or member is obsolete IReadOnlyCollection <ITemplateMatchInfo> templates = TemplateListFilter.GetTemplateMatchInfo( filterableTemplateInfo, WellKnownSearchFilters.MatchesAllCriteria, CliNameFilter(commandInput.TemplateName), WellKnownSearchFilters.LanguageFilter(commandInput.Language), WellKnownSearchFilters.TypeFilter(commandInput.TypeFilter), WellKnownSearchFilters.BaselineFilter(commandInput.BaselineName), CliDefaultLanguageFilter(defaultLanguage) ) #pragma warning restore CS0618 // Type or member is obsolete .Where(x => !IsTemplateHiddenByHostFile(x.Info, hostDataLoader)).ToList(); //select only the templates which do not have mismatches //if any template has exact match for name - use those; otherwise partial name matches are also considered when resolving templates IReadOnlyList <ITemplateMatchInfo> matchesWithExactDispositionsInNameFields = templates.Where( x => x.MatchDisposition.Any( y => (y.Name == MatchInfo.BuiltIn.Name || y.Name == MatchInfo.BuiltIn.ShortName) && y.Kind == MatchKind.Exact)).ToList(); if (matchesWithExactDispositionsInNameFields.Count > 0) { templates = matchesWithExactDispositionsInNameFields; } //add specific template parameters matches to the list AddParameterMatchingToTemplates(templates, hostDataLoader, commandInput); return(templates); }
public IReadOnlyCollection <IFilteredTemplateInfo> ListTemplates(bool exactMatchesOnly, params Func <ITemplateInfo, MatchInfo?>[] filters) { EnsureInitialized(); return(TemplateListFilter.FilterTemplates(((SettingsLoader)EnvironmentSettings.SettingsLoader).UserTemplateCache.TemplateInfo, exactMatchesOnly, filters)); }
// This method is getting obsolted soon. It's getting replaced by TemplateListFilter.FilterTemplates, which does the same thing, // except that the template list to act on is passed in. public IReadOnlyCollection <IFilteredTemplateInfo> List(bool exactMatchesOnly, params Func <ITemplateInfo, MatchInfo?>[] filters) { return(TemplateListFilter.FilterTemplates(TemplateInfo, exactMatchesOnly, filters)); }