示例#1
0
        /// <summary>
        /// Generates the list of template groups for table display.
        /// Except where noted, the values are taken from the highest-precedence template in the group. The info could vary among the templates in the group, but shouldn't. (There is no check that the info doesn't vary.)
        /// - Template Name
        /// - Short Name: displays the first short name from the highest precedence template in the group.
        /// - Language: All languages supported by any template in the group are displayed, with the default language in brackets, e.g.: [C#]
        /// - Tags
        /// - Author
        /// - Type.
        /// </summary>
        /// <param name="templateList">list of templates to be displayed.</param>
        /// <param name="language">language from the command input.</param>
        /// <param name="defaultLanguage">default language.</param>
        /// <param name="environment"><see cref="IEnvironment"/> settings to use.</param>
        /// <returns></returns>
        internal static IReadOnlyList <TemplateGroupTableRow> GetTemplateGroupsForListDisplay(
            IEnumerable <ITemplateInfo> templateList,
            string?language,
            string?defaultLanguage,
            IEnvironment environment)
        {
            List <TemplateGroupTableRow> templateGroupsForDisplay = new List <TemplateGroupTableRow>();
            IEnumerable <IGrouping <string?, ITemplateInfo> > groupedTemplateList = templateList.GroupBy(x => x.GroupIdentity, x => !string.IsNullOrEmpty(x.GroupIdentity), StringComparer.OrdinalIgnoreCase);

            foreach (IGrouping <string?, ITemplateInfo> templateGroup in groupedTemplateList)
            {
                ITemplateInfo highestPrecedenceTemplate = templateGroup.OrderByDescending(x => x.Precedence).First();
                string        shortNames = string.Join(",", templateGroup.SelectMany(t => t.ShortNameList).Distinct(StringComparer.OrdinalIgnoreCase));

                TemplateGroupTableRow groupDisplayInfo = new TemplateGroupTableRow
                {
                    Name            = highestPrecedenceTemplate.Name,
                    ShortNames      = shortNames,
                    Languages       = GetLanguagesToDisplay(templateGroup, language, defaultLanguage, environment),
                    Classifications = GetClassificationsToDisplay(templateGroup, environment),
                    Author          = GetAuthorsToDisplay(templateGroup, environment),
                    Type            = GetTypesToDisplay(templateGroup, environment),
                };
                templateGroupsForDisplay.Add(groupDisplayInfo);
            }

            return(templateGroupsForDisplay);
        }
示例#2
0
        /// <summary>
        /// Generates the list of template groups for table display.
        /// Except where noted, the values are taken from the highest-precedence template in the group. The info could vary among the templates in the group, but shouldn't. (There is no check that the info doesn't vary.)
        /// - Template Name
        /// - Short Name: displays the first short name from the highest precedence template in the group.
        /// - Language: All languages supported by any template in the group are displayed, with the default language in brackets, e.g.: [C#]
        /// - Tags
        /// - Author
        /// - Type.
        /// </summary>
        /// <param name="templateGroupList">list of template groups to be displayed.</param>
        /// <param name="language">language from the command input.</param>
        /// <param name="defaultLanguage">default language.</param>
        /// <param name="environment"><see cref="IEnvironment"/> settings to use.</param>
        /// <returns></returns>
        private static IReadOnlyList <TemplateGroupTableRow> GetTemplateGroupsForListDisplay(
            IEnumerable <TemplateGroup> templateGroupList,
            string?language,
            string?defaultLanguage,
            IEnvironment environment)
        {
            List <TemplateGroupTableRow> templateGroupsForDisplay = new List <TemplateGroupTableRow>();

            foreach (TemplateGroup templateGroup in templateGroupList)
            {
                ITemplateInfo         highestPrecedenceTemplate = templateGroup.Templates.OrderByDescending(x => x.Precedence).First();
                TemplateGroupTableRow groupDisplayInfo          = new TemplateGroupTableRow
                {
                    Name            = highestPrecedenceTemplate.Name,
                    ShortNames      = string.Join(",", templateGroup.ShortNames),
                    Languages       = GetLanguagesToDisplay(templateGroup.Templates, language, defaultLanguage, environment),
                    Classifications = GetClassificationsToDisplay(templateGroup.Templates, environment),
                    Author          = GetAuthorsToDisplay(templateGroup.Templates, environment),
                    Type            = GetTypesToDisplay(templateGroup.Templates, environment),
                };
                templateGroupsForDisplay.Add(groupDisplayInfo);
            }
            return(templateGroupsForDisplay);
        }