コード例 #1
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)
                {
                    _telemetryLogger.TrackEvent(CommandName + "-Help");
                    HelpForTemplateResolution.ShowUsageHelp(_commandInput);
                }
                else
                {
                    Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunHelpForInformationAboutAcceptedParameters, CommandName).Bold().Red());
                }

                return(CreationResultStatus.InvalidParamValues);
            }

            if (_commandInput.ToInstallList != null && _commandInput.ToInstallList.Count > 0 && _commandInput.ToInstallList[0] != null)
            {
                Installer.InstallPackages(_commandInput.ToInstallList.Select(x => x.Split(new[] { "::" }, StringSplitOptions.None)[0]));
            }

            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"
            HelpForTemplateResolution.ShowUsageHelp(_commandInput);
            TemplateListResolutionResult templateResolutionResult = QueryForTemplateMatches();

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

            return(CreationResultStatus.Success);
        }
コード例 #2
0
        private bool SyncOptionalWorkloads()
        {
            bool isHiveUpdated = false;
            bool isCustomHive  = _commandInput.HasDebuggingFlag("--debug:ephemeral-hive") || _commandInput.HasDebuggingFlag("--debug:custom-hive");

            if (!isCustomHive)
            {
                string sdkVersion = EnvironmentSettings.Host.Version.Substring(1); // Host.Version (from SDK) has a leading "v" that need to remove.

                try
                {
                    List <InstallationRequest>  owInstallationRequests   = new List <InstallationRequest>();
                    Dictionary <string, string> owInstalledPkgs          = new Dictionary <string, string>(); // packageId -> packageVersion
                    HashSet <string>            owSyncRequestsPackageIds = new HashSet <string>();
                    TemplateLocator             optionalWorkloadLocator  = new TemplateLocator();
                    string dotnetPath = Path.GetDirectoryName(Path.GetDirectoryName(_paths.Global.BaseDir));

                    IReadOnlyCollection <IOptionalSdkTemplatePackageInfo> owPkgsToSync = optionalWorkloadLocator.GetDotnetSdkTemplatePackages(sdkVersion, dotnetPath);

                    foreach (IInstallUnitDescriptor descriptor in _settingsLoader.InstallUnitDescriptorCache.Descriptors.Values)
                    {
                        if (descriptor.IsPartOfAnOptionalWorkload)
                        {
                            if (!descriptor.Details.TryGetValue("Version", out string pkgVersion))
                            {
                                pkgVersion = string.Empty;
                            }
                            owInstalledPkgs.Add(descriptor.Identifier, pkgVersion);
                        }
                    }

                    foreach (IOptionalSdkTemplatePackageInfo packageInfo in owPkgsToSync)
                    {
                        owSyncRequestsPackageIds.Add(packageInfo.TemplatePackageId);

                        if (!owInstalledPkgs.TryGetValue(packageInfo.TemplatePackageId, out string version) ||
                            version != packageInfo.TemplateVersion)
                        {
                            isHiveUpdated = true;
                            owInstallationRequests.Add(new InstallationRequest(packageInfo.Path, isPartOfAnOptionalWorkload: true));
                        }
                    }

                    if (owInstallationRequests.Count != 0)
                    {
                        Installer.InstallPackages(owInstallationRequests);
                    }

                    // remove uninstalled Optional SDK Workload packages
                    List <string> owRemovalRequestsPackageIds = new List <string>();
                    foreach (string descriptorIdentifier in owInstalledPkgs.Keys)
                    {
                        if (!owSyncRequestsPackageIds.Contains(descriptorIdentifier))
                        {
                            owRemovalRequestsPackageIds.Add(descriptorIdentifier);
                        }
                    }

                    if (owRemovalRequestsPackageIds.Count != 0)
                    {
                        isHiveUpdated = true;
                        IEnumerable <string> failures = Installer.Uninstall(owRemovalRequestsPackageIds);
                        foreach (string failure in failures)
                        {
                            Reporter.Output.WriteLine(string.Format(LocalizableStrings.CouldntUninstall, failure));
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new HiveSynchronizationException(LocalizableStrings.OptionalWorkloadsSyncFailed, sdkVersion, ex);
                }
            }

            return(isHiveUpdated);
        }
コード例 #3
0
ファイル: New3Command.cs プロジェクト: leonwa/templating
        // 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 (KeyValuePair <Guid, string> entry in _settingsLoader.InstallUnitDescriptorCache.InstalledItems)
                    {
                        Console.WriteLine($"  {entry.Value}");

                        if (_settingsLoader.InstallUnitDescriptorCache.Descriptors.TryGetValue(entry.Value, out IInstallUnitDescriptor descriptor))
                        {
                            if (descriptor.Details != null && descriptor.Details.TryGetValue("Version", out string versionValue))
                            {
                                Console.WriteLine($"    {LocalizableStrings.Version} {versionValue}");
                            }
                        }

                        HashSet <string> displayStrings = new HashSet <string>(StringComparer.Ordinal);

                        foreach (TemplateInfo info in _settingsLoader.UserTemplateCache.TemplateInfo.Where(x => x.ConfigMountPointId == entry.Key))
                        {
                            string str = $"      {info.Name} ({info.ShortName})";

                            if (info.Tags != null && info.Tags.TryGetValue("language", out ICacheTag languageTag))
                            {
                                str += " " + string.Join(", ", languageTag.ChoicesAndDescriptions.Select(x => x.Key));
                            }

                            displayStrings.Add(str);
                        }

                        if (displayStrings.Count > 0)
                        {
                            Console.WriteLine($"    {LocalizableStrings.Templates}:");

                            foreach (string displayString in displayStrings)
                            {
                                Console.WriteLine(displayString);
                            }
                        }
                    }

                    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);
        }
コード例 #4
0
        private CreationResultStatus EnterUninstallFlow()
        {
            if (_commandInput.ToUninstallList.Count > 0 && _commandInput.ToUninstallList[0] != null)
            {
                IEnumerable <string> failures = Installer.Uninstall(_commandInput.ToUninstallList);

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

                foreach (IInstallUnitDescriptor descriptor in _settingsLoader.InstallUnitDescriptorCache.Descriptors.Values)
                {
                    Reporter.Output.WriteLine($"  {descriptor.Identifier}");

                    bool wroteHeader = false;

                    foreach (string detailKey in descriptor.DetailKeysDisplayOrder)
                    {
                        WriteDescriptorDetail(descriptor, detailKey, ref wroteHeader);
                    }

                    HashSet <string> standardDetails = new HashSet <string>(descriptor.DetailKeysDisplayOrder, StringComparer.OrdinalIgnoreCase);

                    foreach (string detailKey in descriptor.Details.Keys.OrderBy(x => x))
                    {
                        if (standardDetails.Contains(detailKey))
                        {
                            continue;
                        }

                        WriteDescriptorDetail(descriptor, detailKey, ref wroteHeader);
                    }

                    // template info
                    HashSet <string> templateDisplayStrings = new HashSet <string>(StringComparer.Ordinal);

                    foreach (TemplateInfo info in _settingsLoader.UserTemplateCache.TemplateInfo.Where(x => x.ConfigMountPointId == descriptor.MountPointId))
                    {
                        string str = $"      {info.Name} ({info.ShortName})";

                        string templateLanguage = info.GetLanguage();
                        if (!string.IsNullOrWhiteSpace(templateLanguage))
                        {
                            str += " " + templateLanguage;
                        }

                        templateDisplayStrings.Add(str);
                    }

                    if (templateDisplayStrings.Count > 0)
                    {
                        Reporter.Output.WriteLine($"    {LocalizableStrings.Templates}:");

                        foreach (string displayString in templateDisplayStrings)
                        {
                            Reporter.Output.WriteLine(displayString);
                        }
                    }

                    // uninstall command:
                    Reporter.Output.WriteLine($"    {LocalizableStrings.UninstallListUninstallCommand}");
                    Reporter.Output.WriteLine(string.Format("      dotnet {0} -u {1}", _commandInput.CommandName, descriptor.UninstallString));

                    Reporter.Output.WriteLine();
                }
            }

            return(CreationResultStatus.Success);
        }