public async Task RegisterPackageAsync(RegisteredPackage package, CancellationToken cancellationToken) { var fileOps = await this.agent.GetServiceAsync <IFileOperationsExecuter>().ConfigureAwait(false); var packages = await GetInstalledPackagesAsync(fileOps, this.RegistryRoot).ConfigureAwait(false); packages.RemoveAll(p => RegisteredPackage.NameAndGroupEquals(p, package)); packages.Add(package); await WriteInstalledPackagesAsync(fileOps, this.RegistryRoot, packages).ConfigureAwait(false); }
public static bool NameAndGroupEquals(RegisteredPackage p1, RegisteredPackage p2) { if (ReferenceEquals(p1, p2)) { return(true); } if (ReferenceEquals(p1, null) | ReferenceEquals(p2, null)) { return(false); } return(string.Equals(p1.Group ?? string.Empty, p2.Group ?? string.Empty, StringComparison.OrdinalIgnoreCase) && string.Equals(p1.Name, p2.Name, StringComparison.OrdinalIgnoreCase)); }