Пример #1
0
        private static void QueryForUnambiguousTemplateGroup(IReadOnlyList <ITemplateInfo> templateInfo, IHostSpecificDataLoader hostDataLoader, INewCommandInput commandInput, TemplateListResolutionResult matchResults, string defaultLanguage, bool anyExactCoreMatches)
        {
            if (!anyExactCoreMatches || matchResults.CoreMatchedTemplates == null || matchResults.CoreMatchedTemplates.Count == 0)
            {
                return;
            }

            if (matchResults.CoreMatchedTemplates.Count == 1)
            {
                matchResults.UnambiguousTemplateGroupToUse = matchResults.CoreMatchedTemplates;
                return;
            }

            if (string.IsNullOrEmpty(commandInput.Language) && !string.IsNullOrEmpty(defaultLanguage))
            {
                IReadOnlyList <IFilteredTemplateInfo> languageMatchedTemplates = FindTemplatesExplicitlyMatchingLanguage(matchResults.CoreMatchedTemplates, defaultLanguage);
                if (languageMatchedTemplates.Count == 1)
                {
                    matchResults.UnambiguousTemplateGroupToUse = languageMatchedTemplates;
                    return;
                }
            }

            UseSecondaryCriteriaToDisambiguateTemplateMatches(hostDataLoader, matchResults, commandInput, defaultLanguage);
        }
Пример #2
0
        // coordinates filtering templates based on the parameters & language
        private static void UseSecondaryCriteriaToDisambiguateTemplateMatches(IHostSpecificDataLoader hostDataLoader, TemplateListResolutionResult matchResults, INewCommandInput commandInput, string defaultLanguage)
        {
            if (string.IsNullOrEmpty(commandInput.TemplateName))
            {
                return;
            }

            matchResults.MatchedTemplatesWithSecondaryMatchInfo = FilterTemplatesOnParameters(matchResults.CoreMatchedTemplates, hostDataLoader, commandInput).Where(x => x.IsMatch).ToList();

            IReadOnlyList <IFilteredTemplateInfo> matchesAfterParameterChecks = matchResults.MatchedTemplatesWithSecondaryMatchInfo.Where(x => x.IsParameterMatch).ToList();

            if (matchResults.MatchedTemplatesWithSecondaryMatchInfo.Any(x => x.HasAmbiguousParameterMatch))
            {
                matchesAfterParameterChecks = matchResults.MatchedTemplatesWithSecondaryMatchInfo;
            }

            if (matchesAfterParameterChecks.Count == 0)
            {   // no param matches, continue additional matching with the list from before param checking (but with the param match dispositions)
                matchesAfterParameterChecks = matchResults.MatchedTemplatesWithSecondaryMatchInfo;
            }

            if (matchesAfterParameterChecks.Count == 1)
            {
                matchResults.UnambiguousTemplateGroupToUse = matchesAfterParameterChecks;
                return;
            }
            else if (string.IsNullOrEmpty(commandInput.Language) && !string.IsNullOrEmpty(defaultLanguage))
            {
                IReadOnlyList <IFilteredTemplateInfo> languageFiltered = FindTemplatesExplicitlyMatchingLanguage(matchesAfterParameterChecks, defaultLanguage);

                if (languageFiltered.Count == 1)
                {
                    matchResults.UnambiguousTemplateGroupToUse = languageFiltered;
                    return;
                }
                else if (AreAllTemplatesSameGroupIdentity(languageFiltered))
                {
                    IReadOnlyList <IFilteredTemplateInfo> languageFilteredMatchesAfterParameterChecks = languageFiltered.Where(x => x.IsParameterMatch).ToList();
                    if (languageFilteredMatchesAfterParameterChecks.Count > 0 && !languageFiltered.Any(x => x.HasAmbiguousParameterMatch))
                    {
                        matchResults.UnambiguousTemplateGroupToUse = languageFilteredMatchesAfterParameterChecks;
                        return;
                    }

                    matchResults.UnambiguousTemplateGroupToUse = languageFiltered;
                    return;
                }
            }
            else if (AreAllTemplatesSameGroupIdentity(matchesAfterParameterChecks))
            {
                matchResults.UnambiguousTemplateGroupToUse = matchesAfterParameterChecks;
                return;
            }
        }
Пример #3
0
        // TODO: make sure help / usage works right in these cases.
        private CreationResultStatus EnterMaintenanceFlow()
        {
            if (!TemplateListResolver.ValidateRemainingParameters(_commandInput, out IReadOnlyList <string> invalidParams))
            {
                HelpForTemplateResolution.DisplayInvalidParameters(invalidParams);
                if (_commandInput.IsHelpFlagSpecified)
                {
                    // this code path doesn't go through the full help & usage stack, so needs it's own call to ShowUsageHelp().
                    HelpForTemplateResolution.ShowUsageHelp(_commandInput, _telemetryLogger);
                }
                else
                {
                    Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red());
                }

                return(CreationResultStatus.InvalidParamValues);
            }

            if (_commandInput.ToUninstallList != null)
            {
                if (_commandInput.ToUninstallList.Count > 0 && _commandInput.ToUninstallList[0] != null)
                {
                    IEnumerable <string> failures = Installer.Uninstall(_commandInput.ToUninstallList);

                    foreach (string failure in failures)
                    {
                        Console.WriteLine(LocalizableStrings.CouldntUninstall, failure);
                    }
                }
                else
                {
                    Console.WriteLine(LocalizableStrings.CommandDescription);
                    Console.WriteLine();
                    Console.WriteLine(LocalizableStrings.InstalledItems);

                    foreach (string value in _settingsLoader.InstallUnitDescriptorCache.InstalledItems.Values)
                    {
                        Console.WriteLine($" {value}");
                    }

                    return(CreationResultStatus.Success);
                }
            }

            if (_commandInput.ToInstallList != null && _commandInput.ToInstallList.Count > 0 && _commandInput.ToInstallList[0] != null)
            {
                CreationResultStatus installResult = EnterInstallFlow();

                if (installResult == CreationResultStatus.Success)
                {
                    _settingsLoader.Reload();
                    TemplateListResolutionResult resolutionResult = QueryForTemplateMatches();
                    HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(resolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage);
                }

                return(installResult);
            }

            //No other cases specified, we've fallen through to "Usage help + List"
            TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches();

            HelpForTemplateResolution.CoordinateHelpAndUsageDisplay(templateResolutionResult, EnvironmentSettings, _commandInput, _hostDataLoader, _telemetryLogger, _templateCreator, _defaultLanguage);

            return(CreationResultStatus.Success);
        }