Exemplo n.º 1
0
        public static void EnableOrDisableSource(PackageSourceProvider sourceProvider, string name, bool enabled, Func <ILogger> getLogger)
        {
            var packageSource = sourceProvider.GetPackageSourceByName(name);

            if (packageSource == null)
            {
                throw new CommandException(Strings.SourcesCommandNoMatchingSourcesFound, name);
            }

            // Use casing consistent with existing source.
            name = packageSource.Name;

            if (enabled && !packageSource.IsEnabled)
            {
                sourceProvider.EnablePackageSource(name);
            }
            else if (!enabled && packageSource.IsEnabled)
            {
                sourceProvider.DisablePackageSource(name);
            }

            if (enabled)
            {
                getLogger().LogMinimal(string.Format(CultureInfo.CurrentCulture,
                                                     Strings.SourcesCommandSourceEnabledSuccessfully, name));
            }
            else
            {
                getLogger().LogMinimal(string.Format(CultureInfo.CurrentCulture,
                                                     Strings.SourcesCommandSourceDisabledSuccessfully, name));
            }
        }