Exemplo n.º 1
0
        public static void GetPackageAndDependencies( string packageId, string packageVersion, string sourceServer, string targetFolder, bool overwriteExistingFiles, bool includePrerelease, bool allowUnlisted, DependencyVersionTypeToDownload depVersionToDownload)
        {
            log.Trace( $"Entered GetPackageAndDependencies(packageId='{packageId}', packageVersion='{packageVersion}', sourceServer='{sourceServer}', targetFolder='{targetFolder}', overwriteExistingFiles={overwriteExistingFiles}, includePrerelease={includePrerelease}, allowUnlisted={allowUnlisted}, depVersionToDownload={depVersionToDownload})" );

            var repo = PackageRepositoryFactory.Default.CreateRepository( sourceServer );
            var package = repo.FindPackage( packageId, packageVersion==null?null:new SemanticVersion(packageVersion),NullConstraintProvider.Instance, includePrerelease, allowUnlisted ) as DataServicePackage;

            if( package == null ) {
                log.Warn( $"Package '{packageId} {packageVersion}' could not be found in the repository '{sourceServer}', or it could be converted as DataServicePackage" );

                return;
            }

            var finalPackagePath = Path.Combine( targetFolder, $"{package.Id}.{package.Version}.nupkg" );

            if( File.Exists( finalPackagePath ) && !overwriteExistingFiles ) {
                log.Info( $"Skipping '{finalPackagePath}'" );
                return;
            }

            if( !Directory.Exists( targetFolder ) ) {
                Directory.CreateDirectory( targetFolder );
            }

            using( var fs = File.Open( finalPackagePath, FileMode.Create ) ) {
                log.Debug($"Downloading package '{package.Id}' from '{package.DownloadUrl}' ... ");
                var downloader = new PackageDownloader();
                downloader.DownloadPackage( package.DownloadUrl, package, fs );
                log.Info($"Package {package.Id} downloaded!");
            }

            foreach( var dset in package.DependencySets.Where( dset => dset.Dependencies.Count > 0 ) ) {
                log.Debug( $"Processing dependency set: {dset.TargetFramework?.ToString() ?? "<default set>"} " );

                foreach( var dep in dset.Dependencies ) {
                    log.Debug( $"Processing dependency '{dep.Id}'" );
                    var dependencyVersion = depVersionToDownload == DependencyVersionTypeToDownload.Max
                                                ? dep.VersionSpec?.MaxVersion?.ToString()
                                                : dep.VersionSpec?.MinVersion?.ToString();
                    GetPackageAndDependencies( dep.Id, dependencyVersion, sourceServer, targetFolder, overwriteExistingFiles, includePrerelease, allowUnlisted, depVersionToDownload );
                }
            }
            log.Trace( "Exiting GetPackageAndDependencies" );
        }
Exemplo n.º 2
0
        public static void GetPackageAndDependencies(string packageId, string packageVersion, string sourceServer, string targetFolder, bool overwriteExistingFiles, bool includePrerelease, bool allowUnlisted, DependencyVersionTypeToDownload depVersionToDownload)
        {
            log.Trace($"Entered GetPackageAndDependencies(packageId='{packageId}', packageVersion='{packageVersion}', sourceServer='{sourceServer}', targetFolder='{targetFolder}', overwriteExistingFiles={overwriteExistingFiles}, includePrerelease={includePrerelease}, allowUnlisted={allowUnlisted}, depVersionToDownload={depVersionToDownload})");

            var repo    = PackageRepositoryFactory.Default.CreateRepository(sourceServer);
            var package = repo.FindPackage(packageId, packageVersion == null?null:new SemanticVersion(packageVersion), NullConstraintProvider.Instance, includePrerelease, allowUnlisted) as DataServicePackage;

            if (package == null)
            {
                log.Warn($"Package '{packageId} {packageVersion}' could not be found in the repository '{sourceServer}', or it could be converted as DataServicePackage");

                return;
            }

            var finalPackagePath = Path.Combine(targetFolder, $"{package.Id}.{package.Version}.nupkg");

            if (File.Exists(finalPackagePath) && !overwriteExistingFiles)
            {
                log.Info($"Skipping '{finalPackagePath}'");
                return;
            }

            if (!Directory.Exists(targetFolder))
            {
                Directory.CreateDirectory(targetFolder);
            }

            using (var fs = File.Open(finalPackagePath, FileMode.Create)) {
                log.Debug($"Downloading package '{package.Id}' from '{package.DownloadUrl}' ... ");
                var downloader = new PackageDownloader();
                downloader.DownloadPackage(package.DownloadUrl, package, fs);
                log.Info($"Package {package.Id} downloaded!");
            }

            foreach (var dset in package.DependencySets.Where(dset => dset.Dependencies.Count > 0))
            {
                log.Debug($"Processing dependency set: {dset.TargetFramework?.ToString() ?? "<default set>"} ");

                foreach (var dep in dset.Dependencies)
                {
                    log.Debug($"Processing dependency '{dep.Id}'");
                    var dependencyVersion = depVersionToDownload == DependencyVersionTypeToDownload.Max
                                                ? dep.VersionSpec?.MaxVersion?.ToString()
                                                : dep.VersionSpec?.MinVersion?.ToString();
                    GetPackageAndDependencies(dep.Id, dependencyVersion, sourceServer, targetFolder, overwriteExistingFiles, includePrerelease, allowUnlisted, depVersionToDownload);
                }
            }
            log.Trace("Exiting GetPackageAndDependencies");
        }