public bool SavePackageSource(string name, string source, bool isEnabled = true, bool isOfficial = true) { Argument.IsNotNullOrWhitespace(() => name); Argument.IsNotNullOrWhitespace(() => source); try { var verificationResult = _feedVerificationService.VerifyFeed(source, false); if (verificationResult == FeedVerificationResult.Invalid || verificationResult == FeedVerificationResult.Unknown) { return(false); } var packageSources = _packageSourceProvider.LoadPackageSources().ToList(); var existedSource = packageSources.FirstOrDefault(x => string.Equals(x.Name, name)); if (existedSource == null) { existedSource = new PackageSource(source, name); packageSources.Add(existedSource); } existedSource.IsEnabled = isEnabled; existedSource.IsOfficial = isOfficial; _packageSourceProvider.SavePackageSources(packageSources); } catch { return(false); } return(true); }
private async Task VerifyPackageSourceAsync(EditablePackageSource packageSource, bool force = false) { if (packageSource == null || packageSource.IsValid == null) { return; } if (!force && string.Equals(packageSource.Source, packageSource.PreviousSourceValue)) { return; } packageSource.IsValid = null; string feedToValidate; string nameToValidate; bool isValidUrl; bool isValidName; do { feedToValidate = packageSource.Source; nameToValidate = packageSource.Name; var namesCount = EditablePackageSources.Count(x => string.Equals(nameToValidate, x.Name)); isValidName = !string.IsNullOrWhiteSpace(nameToValidate) && namesCount == 1; var validate = feedToValidate; var feedVerificationResult = await TaskHelper.Run(() => _nuGetFeedVerificationService.VerifyFeed(validate, true), true); packageSource.FeedVerificationResult = feedVerificationResult; isValidUrl = feedVerificationResult != FeedVerificationResult.Invalid && feedVerificationResult != FeedVerificationResult.Unknown; } while (!string.Equals(feedToValidate, packageSource.Source) && !string.Equals(nameToValidate, packageSource.Name)); packageSource.PreviousSourceValue = packageSource.Source; packageSource.IsValidSource = isValidUrl; packageSource.IsValidName = isValidName; Validate(true); }
private async Task OnVerifyFeedExecute() { await TaskHelper.Run(() => _feedVerificationService.VerifyFeed(PackageSourceUrl), true); }