コード例 #1
0
 public static IEnumerable <string> GetInvalidDependencyIds(XDocument nuspec)
 {
     foreach (var dependency in GetDependencies(nuspec))
     {
         if (!StrictPackageIdValidator.IsValid(dependency.Id))
         {
             yield return(dependency.Id);
         }
     }
 }
コード例 #2
0
        public bool IsMatch(XDocument nuspec)
        {
            var id = NuspecUtility.GetOriginalId(nuspec);

            return(!StrictPackageIdValidator.IsValid(id));
        }
コード例 #3
0
        public async Task AddDependenciesAsync(IReadOnlyList <PackageDependencyGroups> packages)
        {
            // Fetch the package entities.
            var identities = packages
                             .Select(x => x.Identity)
                             .ToList();
            var identityToPackage = await GetIdentityToPackage(identities);

            // Fetch the framework entities.
            var parsedFrameworks = packages
                                   .SelectMany(x => x
                                               .DependencyGroups
                                               .Groups
                                               .Select(y => new ParsedFramework(y.TargetFramework, y.ParsedTargetFramework?.GetShortFolderName())))
                                   .Where(x => x.OriginalValue != null && x.Value != null)
                                   .ToList();
            var originalValueToFramework = await AddOrUpdateFrameworksAsync(parsedFrameworks);

            // Fetch the package registration entities.
            var ids = Enumerable
                      .Empty <string>()
                      .Concat(packages.SelectMany(x => x.DependencyGroups.Dependencies.Select(y => y.Id)))
                      .Concat(packages.SelectMany(x => x.DependencyGroups.Groups.SelectMany(y => y.Dependencies.Select(z => z.Id))))
                      .Where(x => StrictPackageIdValidator.IsValid(x))
                      .Distinct(StringComparer.OrdinalIgnoreCase)
                      .ToList();
            var idToPackageRegistration = await _packageService.AddPackageRegistrationsAsync(ids, includePackages : false);

            using (var entityContext = new EntityContext())
            {
                foreach (var dependencyGroups in packages)
                {
                    var package    = identityToPackage[dependencyGroups.Identity.Value];
                    var packageKey = package.PackageKey;

                    if (package.PackageDependencies == null)
                    {
                        package.PackageDependencies = new List <PackageDependencyEntity>();
                    }

                    var existingDependencies = SortEntities(package.PackageDependencies);

                    var latestDependencies = SortEntities(InitializePackageDependencies(
                                                              dependencyGroups,
                                                              packageKey,
                                                              originalValueToFramework,
                                                              idToPackageRegistration));

                    latestDependencies = SortEntities(latestDependencies);

                    for (var i = 0; i < latestDependencies.Count; i++)
                    {
                        var latest = latestDependencies[i];

                        if (existingDependencies.Count <= i)
                        {
                            // New dependency added to the end.
                            existingDependencies.Add(latest);
                            entityContext.PackageDependencies.Add(latest);
                        }
                        else
                        {
                            // Existing dependency.
                            var existing = existingDependencies[i];
                            entityContext.PackageDependencies.Attach(existing);
                            existing.DependencyPackageRegistrationKey = latest.DependencyPackageRegistrationKey;
                            existing.FrameworkKey         = latest.FrameworkKey;
                            existing.OriginalVersionRange = latest.OriginalVersionRange;
                            existing.VersionRange         = latest.VersionRange;
                        }
                    }

                    for (var i = existingDependencies.Count - 1; i >= latestDependencies.Count; i--)
                    {
                        // Dependencies removed from the end.
                        var existing = existingDependencies[i];
                        existingDependencies.RemoveAt(i);
                        entityContext.PackageDependencies.Attach(existing);
                        entityContext.PackageDependencies.Remove(existing);
                    }
                }

                var commitStopwatch = Stopwatch.StartNew();
                var changes         = await entityContext.SaveChangesAsync();

                _logger.LogInformation(
                    "Committed package dependency {Changes} changes. {ElapsedMilliseconds}ms",
                    changes,
                    commitStopwatch.ElapsedMilliseconds);
            }
        }