public bool Unregister(PackageSource source) { if (source == null) { throw new ArgumentNullException("source"); } if (ShouldProcess(FormatMessageString(Constants.Messages.TargetPackageSource, source.Name, source.Location, source.ProviderName), FormatMessageString(Constants.Messages.ActionUnregisterPackageSource)).Result) { source.Provider.RemovePackageSource(source.Name, this).Wait(); return true; } return false; }
private void UpdatePackageSource(PackageSource source) { if (WhatIf) { var p = new PSObject(source); if (!string.IsNullOrWhiteSpace(NewName)) { p.Properties.Remove("Name"); p.Properties.Add( new PSNoteProperty("Name",NewName)); } if (!string.IsNullOrWhiteSpace(NewLocation)) { p.Properties.Remove("Location"); p.Properties.Add(new PSNoteProperty("Location", NewLocation)); } if (Trusted.IsPresent) { p.Properties.Remove("Trusted"); p.Properties.Add(new PSNoteProperty("Trusted", Trusted.ToBool())); } WriteObject(p); return; } if (string.IsNullOrWhiteSpace(NewName)) { // this is a replacement of an existing package source, we're *not* changing the name. (easy) foreach (var src in source.Provider.AddPackageSource(string.IsNullOrWhiteSpace(NewName) ? source.Name : NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted, UpdatePackageSourceRequest)) { WriteObject(src); } } else { // we're renaming a source. // a bit more messy at this point // create a new package source first bool removed = false; foreach (var src in source.Provider.AddPackageSource(NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted.IsPresent ? Trusted.ToBool() : source.IsTrusted, this)) { WriteObject(src); if (!removed) { // if we are able to successfully add a source, then we remove the original source that was supposed to be replace. // This will only happen once (as there is only one original source) source.Provider.RemovePackageSource(source.Name, this); removed = true; } } } }
private void UpdatePackageSource(PackageSource source) { if (WhatIf) { var p = new PSObject(source); if (!string.IsNullOrWhiteSpace(NewName)) { p.Properties.Remove("Name"); p.Properties.Add( new PSNoteProperty("Name",NewName)); } if (!string.IsNullOrWhiteSpace(NewLocation)) { p.Properties.Remove("Location"); p.Properties.Add(new PSNoteProperty("Location", NewLocation)); } if (Trusted.IsPresent) { p.Properties.Remove("Trusted"); p.Properties.Add(new PSNoteProperty("Trusted", Trusted.ToBool())); } WriteObject(p); return; } if (string.IsNullOrWhiteSpace(NewName)) { // this is a replacement of an existing package source, we're *not* changing the name. (easy) foreach (var src in source.Provider.AddPackageSource(string.IsNullOrWhiteSpace(NewName) ? source.Name : NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted, UpdatePackageSourceRequest)) { WriteObject(src); } } else { // we're renaming a source. // a bit more messy at this point // create a new package source first foreach (var src in source.Provider.AddPackageSource(NewName, string.IsNullOrWhiteSpace(NewLocation) ? source.Location : NewLocation, Trusted.IsPresent ? Trusted.ToBool() : source.IsTrusted, this)) { WriteObject(src); } // remove the old one. source.Provider.RemovePackageSource(source.Name, this).Wait(); } }