public IEnumerable<PackageOperationResult> AddSystemPackage(PackageRequest packageToAdd,
     IEnumerable<IPackageRepository> sourceRepositories,
     IPackageRepository systemRepository,
     PackageAddOptions options = PackageAddOptions.Default)
 {
     return CopyPackageCore(sourceRepositories, new[] { systemRepository }, ToDescriptor(packageToAdd, options), x => true);
 }
Example #2
0
        public IPackageAddResult AddProjectPackage(PackageRequest packageToAdd, IEnumerable<IPackageRepository> sourceRepositories, IPackageDescriptor projectDescriptor, IPackageRepository projectRepository, PackageAddOptions options = PackageAddOptions.Default)
        {
            Check.NotNull(packageToAdd, "packageToAdd");
            Check.NoNullElements(sourceRepositories, "sourceRepositories");
            Check.NotNull(projectDescriptor, "projectDescriptor");
            Check.NotNull(projectRepository, "projectRepository");

            return new PackageAddResultIterator(AddProjectPackageCore(packageToAdd, sourceRepositories, projectDescriptor, projectRepository, options));
        }
Example #3
0
        public IPackageAddResult AddSystemPackage(PackageRequest packageToAdd,
                                                  IEnumerable <IPackageRepository> sourceRepositories,
                                                  IPackageRepository systemRepository,
                                                  PackageAddOptions options = PackageAddOptions.Default)
        {
            Check.NotNull(packageToAdd, "packageToAdd");
            Check.NoNullElements(sourceRepositories, "sourceRepositories");
            Check.NotNull(systemRepository, "systemRepository");

            var returnValue = AddSystemPackageCore(sourceRepositories, systemRepository, packageToAdd, options);

            if ((options & PackageAddOptions.Hooks) == PackageAddOptions.Hooks && _hooks != null)
            {
                returnValue = WrapWithHooks(returnValue, ToDescriptor(packageToAdd, options), systemRepository, "system");
            }
            return(new PackageAddResultIterator(returnValue));
        }
        public IPackageAddResult AddProjectPackage(PackageRequest packageToAdd,
                                                   IEnumerable <IPackageRepository> sourceRepositories,
                                                   IPackageDescriptor projectDescriptor,
                                                   IPackageRepository projectRepository,
                                                   PackageAddOptions options = PackageAddOptions.Default)
        {
            Check.NotNull(packageToAdd, "packageToAdd");
            Check.NoNullElements(sourceRepositories, "sourceRepositories");
            Check.NotNull(projectDescriptor, "projectDescriptor");
            Check.NotNull(projectRepository, "projectRepository");

            var result = AddProjectPackageCore(packageToAdd, sourceRepositories, projectDescriptor, projectRepository, options);

            if ((options & PackageAddOptions.Hooks) == PackageAddOptions.Hooks && _hooks != null)
            {
                result = WrapWithHooks(result, projectDescriptor, projectRepository, "project");
            }
            return(new PackageAddResultIterator(result));
        }
        public IPackageRemoveResult RemoveProjectPackage(PackageRequest packageToRemove,
                                                         IPackageDescriptor packageDescriptor,
                                                         IPackageRepository projectRepository,
                                                         PackageRemoveOptions options = PackageRemoveOptions.Default)
        {
            if (packageToRemove == null)
            {
                throw new ArgumentNullException("packageToRemove");
            }
            if (packageDescriptor == null)
            {
                throw new ArgumentNullException("packageDescriptor");
            }
            if (projectRepository == null)
            {
                throw new ArgumentNullException("projectRepository");
            }

            return(new PackageRemoveResultIterator(RemoveProjectPackageCore(packageToRemove, packageDescriptor, projectRepository, options)));
        }
        static IEnumerable <VersionVertex> ToVersionVertices(PackageRequest packageToRequest)
        {
            var vertices = new List <VersionVertex>();

            if (packageToRequest.ExactVersion != null)
            {
                vertices.Add(new EqualVersionVertex(packageToRequest.ExactVersion));
            }
            if (packageToRequest.MinVersion != null)
            {
                vertices.Add(new GreaterThanOrEqualVersionVertex(packageToRequest.MinVersion));
            }
            if (packageToRequest.MaxVersion != null)
            {
                vertices.Add(new LessThanVersionVertex(packageToRequest.MaxVersion));
            }
            if (packageToRequest.ExactVersion == null && packageToRequest.MinVersion == null && packageToRequest.MaxVersion == null)
            {
                vertices.Add(new AnyVersionVertex());
            }
            return(vertices);
        }
Example #7
0
        IEnumerable <PackageOperationResult> AddProjectPackageCore(PackageRequest packageToAdd,
                                                                   IEnumerable <IPackageRepository> sourceRepositories,
                                                                   IPackageDescriptor projectDescriptor,
                                                                   IPackageRepository projectRepository,
                                                                   PackageAddOptions options)
        {
            if (projectDescriptor.Dependencies.Where(x => x.Name.EqualsNoCase(packageToAdd.Name)).Any())
            {
                yield return(new PackageDependencyAlreadyExists(packageToAdd.Name));

                yield break;
            }

            var dependency = ToDependency(packageToAdd, options);

            projectDescriptor.Dependencies.Add(dependency);
            yield return(new PackageDependencyAddedResult(dependency));

            foreach (var m in CopyPackageCore(sourceRepositories, new[] { projectRepository }, projectDescriptor, x => x.EqualsNoCase(packageToAdd.Name)))
            {
                yield return(m);
            }
        }
        public IEnumerable<PackageOperationResult> RemoveProjectPackage(PackageRequest packageToRemove,
            PackageDescriptor packageDescriptor,
            IPackageRepository projectRepository,
            PackageRemoveOptions options = PackageRemoveOptions.Default)
        {
            if (packageToRemove == null) throw new ArgumentNullException("packageToRemove");
            if (packageDescriptor == null) throw new ArgumentNullException("packageDescriptor");
            if (projectRepository == null) throw new ArgumentNullException("projectRepository");

            return (packageToRemove.ExactVersion == null && !packageToRemove.LastVersion)
                           ? RemoveFromDescriptor(packageToRemove, packageDescriptor, projectRepository, options)
                           : RemovePackageFilesFromProjectRepo(packageToRemove, projectRepository);
        }
 PackageDescriptor ToDescriptor(PackageRequest package, PackageAddOptions options)
 {
     return new PackageDescriptor
     {
         Dependencies =
                     {
                             new PackageDependencyBuilder(package.Name)
                                 .Content((options & PackageAddOptions.Content) == PackageAddOptions.Content)
                                 .Anchored((options & PackageAddOptions.Anchor) == PackageAddOptions.Anchor)
                                 .SetVersionVertices(ToVersionVertices(package))
                     }
     };
 }
 PackageDependency ToDependency(PackageRequest packageToAdd, PackageAddOptions options)
 {
     return new PackageDependencyBuilder(packageToAdd.Name)
             .SetVersionVertices(ToVersionVertices(packageToAdd))
             .Anchored((options & PackageAddOptions.Anchor) == PackageAddOptions.Anchor)
             .Content((options & PackageAddOptions.Content) == PackageAddOptions.Content);
 }
 IEnumerable<PackageOperationResult> RemoveFromDescriptor(PackageRequest packageToRemove, PackageDescriptor packageDescriptor, IPackageRepository projectRepository, PackageRemoveOptions options)
 {
     var dependency = packageDescriptor.Dependencies.FirstOrDefault(x => x.Name.EqualsNoCase(packageToRemove.Name));
     if (dependency == null)
     {
         yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.DependencyNotFound);
         yield break;
     }
     packageDescriptor.Dependencies.Remove(dependency);
     if ((options & PackageRemoveOptions.Clean) == PackageRemoveOptions.Clean)
         foreach (var cleaned in CleanProjectPackages(packageDescriptor, projectRepository, packageToRemove.Name))
             yield return cleaned;
 }
        IEnumerable<PackageOperationResult> AddProjectPackageCore(PackageRequest packageToAdd, IEnumerable<IPackageRepository> sourceRepositories, PackageDescriptor projectDescriptor, IPackageRepository projectRepository, PackageAddOptions options)
        {
            var finalDescriptor = (options & PackageAddOptions.UpdateDescriptor) == PackageAddOptions.UpdateDescriptor
                                          ? projectDescriptor
                                          : new PackageDescriptor(projectDescriptor);
            var existingEntries = finalDescriptor.Dependencies.Where(x => x.Name.EqualsNoCase(packageToAdd.Name)).ToList();
            if (existingEntries.Count > 0)
            {
                finalDescriptor.Dependencies.RemoveRange(existingEntries);
                yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.Updated);
            }
            else
            {
                yield return new PackageDescriptorUpdateResult(PackageDescriptorDependencyUpdate.Added);
            }

            finalDescriptor.Dependencies.Add(ToDependency(packageToAdd, options));

            foreach (var m in CopyPackageCore(sourceRepositories, new[] { projectRepository }, finalDescriptor, x => true))
                yield return m;
        }
 static ICollection<VersionVertex> ToVersionVertices(PackageRequest packageToRequest)
 {
     var vertices = new List<VersionVertex>();
     if (packageToRequest.ExactVersion != null)
         vertices.Add(new ExactVersionVertex(packageToRequest.ExactVersion));
     if (packageToRequest.MinVersion != null)
         vertices.Add(new GreaterThenOrEqualVersionVertex(packageToRequest.MinVersion));
     if (packageToRequest.MaxVersion != null)
         vertices.Add(new LessThanVersionVertex(packageToRequest.MaxVersion));
     if (packageToRequest.ExactVersion == null && packageToRequest.MinVersion == null && packageToRequest.MaxVersion == null)
         vertices.Add(new AnyVersionVertex());
     return vertices;
 }
 static IEnumerable<PackageOperationResult> RemovePackageFromRepository(PackageRequest packageToRemove, IPackageRepository repository)
 {
     var versionToRemove = packageToRemove.LastVersion
                                   ? repository.PackagesByName[packageToRemove.Name].Select(x => x.Version)
                                             .OrderByDescending(_ => _)
                                             .FirstOrDefault()
                                   : packageToRemove.ExactVersion;
     var packagesToKeep = from package in repository.PackagesByName.SelectMany(_ => _)
                          let matchesName = package.Name.EqualsNoCase(packageToRemove.Name)
                          let matchesVersion = versionToRemove == null ? true : package.Version == versionToRemove
                          where !(matchesName && matchesVersion)
                          select package;
     return ((ISupportCleaning)repository).Clean(packagesToKeep).Cast<PackageOperationResult>();
 }
 static IEnumerable<PackageOperationResult> RemovePackageFilesFromProjectRepo(PackageRequest packageToRemove, IPackageRepository projectRepository)
 {
     return RemovePackageFromRepository(packageToRemove, projectRepository);
 }
 public IEnumerable<PackageOperationResult> RemoveSystemPackage(PackageRequest packageToRemove, IPackageRepository systemRepository, PackageRemoveOptions options = PackageRemoveOptions.Default)
 {
     if (packageToRemove == null) throw new ArgumentNullException("packageToRemove");
     if (systemRepository == null) throw new ArgumentNullException("systemRepository");
     return RemovePackageFromRepository(packageToRemove, systemRepository);
 }
 IEnumerable <PackageOperationResult> RemoveSystemPackageCore(PackageRequest packageToRemove, IPackageRepository systemRepository)
 {
     return(RemovePackageFromRepository(packageToRemove, systemRepository));
 }
Example #18
0
 RemoveSystemPackageCore(PackageRequest packageToRemove, IPackageRepository systemRepository)
 {
     return(RemovePackageFromRepository(packageToRemove, systemRepository));
 }
Example #19
0
 static IEnumerable <PackageOperationResult> RemovePackageFilesFromProjectRepo(PackageRequest packageToRemove, IPackageRepository projectRepository)
 {
     return(RemovePackageFromRepository(packageToRemove, projectRepository));
 }