private void EnableOrDisableSource(bool enabled) { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired")); } var packageSource = SourceProvider.GetPackageSourceByName(Name); if (packageSource == null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name); } if (enabled && !packageSource.IsEnabled) { SourceProvider.EnablePackageSource(Name); } else if (!enabled && packageSource.IsEnabled) { SourceProvider.DisablePackageSource(Name); } Console.WriteLine( enabled ? LocalizedResourceManager.GetString("SourcesCommandSourceEnabledSuccessfully") : LocalizedResourceManager.GetString("SourcesCommandSourceDisabledSuccessfully"), Name); }
private void UpdatePackageSource() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired")); } var existingSource = SourceProvider.GetPackageSourceByName(Name); if (existingSource == null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name); } if (!string.IsNullOrEmpty(Source) && !existingSource.Source.Equals(Source, StringComparison.OrdinalIgnoreCase)) { if (!PathValidator.IsValidSource(Source)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource")); } // If the user is updating the source, verify we don't have a duplicate. var duplicateSource = SourceProvider.GetPackageSourceBySource(Source); if (duplicateSource != null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource")); } existingSource = new Configuration.PackageSource(Source, existingSource.Name); } ValidateCredentials(); if (!string.IsNullOrEmpty(Username)) { var hasExistingAuthTypes = existingSource.Credentials?.ValidAuthenticationTypes.Any() ?? false; if (hasExistingAuthTypes && string.IsNullOrEmpty(ValidAuthenticationTypes)) { Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandClearingExistingAuthTypes"), Name); } var credentials = Configuration.PackageSourceCredential.FromUserInput( Name, Username, Password, StorePasswordInClearText, ValidAuthenticationTypes); existingSource.Credentials = credentials; } SourceProvider.UpdatePackageSource(existingSource, updateCredentials: existingSource.Credentials != null, updateEnabled: false); Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandUpdateSuccessful"), Name); }
private void AddNewSource() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired")); } if (string.Equals(Name, LocalizedResourceManager.GetString("ReservedPackageNameAll"))) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandAllNameIsReserved")); } if (string.IsNullOrEmpty(Source)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandSourceRequired")); } // Make sure that the Source given is a valid one. if (!PathValidator.IsValidSource(Source)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandInvalidSource")); } ValidateCredentials(); // Check to see if we already have a registered source with the same name or source var existingSourceWithName = SourceProvider.GetPackageSourceByName(Name); if (existingSourceWithName != null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueName")); } var existingSourceWithSource = SourceProvider.GetPackageSourceBySource(Source); if (existingSourceWithSource != null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandUniqueSource")); } var newPackageSource = new Configuration.PackageSource(Source, Name); if (!string.IsNullOrEmpty(Username)) { var credentials = Configuration.PackageSourceCredential.FromUserInput( Name, Username, Password, StorePasswordInClearText, ValidAuthenticationTypes); newPackageSource.Credentials = credentials; } SourceProvider.AddPackageSource(newPackageSource); Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceAddedSuccessfully"), Name); }
private void RemoveSource() { if (string.IsNullOrEmpty(Name)) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNameRequired")); } // Check to see if we already have a registered source with the same name or source var sourceList = SourceProvider.LoadPackageSources().ToList(); var source = SourceProvider.GetPackageSourceByName(Name); if (source == null) { throw new CommandLineException(LocalizedResourceManager.GetString("SourcesCommandNoMatchingSourcesFound"), Name); } SourceProvider.RemovePackageSource(Name); Console.WriteLine(LocalizedResourceManager.GetString("SourcesCommandSourceRemovedSuccessfully"), Name); }