private List<PackageViewModel> GeneratePackages(IEnumerable<string> packageFiles) { var packages = new List<PackageViewModel>(); var feedContext = new FeedContext_x0060_1(new Uri("http://nuget.org/api/v2/")) { IgnoreMissingProperties = true }; foreach (var file in packageFiles) { var packagesConfig = XDocument.Load(file); foreach (var package in packagesConfig.Descendants("package")) { var id = package.Attribute("id").Value; var version = package.Attribute("version").Value; var remotePackage = feedContext.Packages.Where(x => x.Id == id && x.IsLatestVersion && !x.IsPrerelease).FirstOrDefault(); if (remotePackage == null) continue; if (packages.Any(p => p.NugetId == id && p.LocalVersion == version)) continue; packages.Add(new PackageViewModel { RemoteVersion = remotePackage.Version, LocalVersion = version, NugetId = id, Id = Guid.NewGuid().ToString(), Dependencies = remotePackage.Dependencies.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).Select(x => { var strings = x.Split(new[] {':'}); return new DependencyViewModel {NugetId = strings[0], Version = strings[1]}; }).ToArray() }); } } return packages; }
private List<PackageViewModel> GeneratePackages(string file) { var packages = new List<PackageViewModel>(); var feedContext = new FeedContext_x0060_1(new Uri(RepositoryUrl)) { IgnoreMissingProperties = true }; ApplyCredentials(feedContext); var packagesConfig = XDocument.Load(file); var dependencies = new List<DependencyViewModel>(); foreach (var package in packagesConfig.Descendants("package")) { var id = package.Attribute("id").Value; var version = package.Attribute("version").Value; // ReSharper disable ReplaceWithSingleCallToFirstOrDefault var remotePackage = feedContext .Packages .OrderByDescending(x => x.Version) .Where(x => x.Id == id && x.IsLatestVersion && !x.IsPrerelease) .FirstOrDefault(); // ReSharper restore ReplaceWithSingleCallToFirstOrDefault dependencies.Add(new DependencyViewModel { NugetId = id, Version = version }); if (remotePackage == null) continue; if (packages.Any(p => p.NugetId == id && p.LocalVersion == version)) continue; packages.Add(new PackageViewModel { RemoteVersion = remotePackage.Version, LocalVersion = version, NugetId = id, Id = Guid.NewGuid().ToString(), Dependencies = remotePackage.Dependencies.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).Select(x => { var strings = x.Split(new[] { ':' }); return new DependencyViewModel { NugetId = strings[0], Version = strings[1] }; }).ToArray() }); foreach ( var pack in packages .Last() .Dependencies .Select(dependency => dependencies .FirstOrDefault(x => x.NugetId == dependency.NugetId && x.Version == dependency.Version)) .Where(pack => pack != null)) { dependencies.Remove(pack); } } packages.Add( new PackageViewModel { RemoteVersion = "", LocalVersion = "", NugetId = Path.GetFileName(Path.GetDirectoryName(file)), Id = Guid.NewGuid().ToString(), Dependencies = dependencies.ToArray() }); return packages; }