상속: IHttpClientEvents
        public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _httpClient = client;
            _httpClient.AcceptCompression = true;
            
            _packageDownloader = packageDownloader;

            if (EnvironmentUtility.RunningFromCommandLine || EnvironmentUtility.IsMonoRuntime)
            {
                _packageDownloader.SendingRequest += OnPackageDownloaderSendingRequest;
            }
            else
            {
                // weak event pattern            
                SendingRequestEventManager.AddListener(_packageDownloader, this);
            }
        }
예제 #2
0
        public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _httpClient = client;
            _httpClient.AcceptCompression = true;

            _packageDownloader = packageDownloader;

            if (EnvironmentUtility.RunningFromCommandLine)
            {
                _packageDownloader.SendingRequest += OnPackageDownloaderSendingRequest;
            }
            else
            {
                // weak event pattern
                SendingRequestEventManager.AddListener(_packageDownloader, this);
            }
        }
        public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _httpClient = client;
            _httpClient.AcceptCompression = true;

            _packageDownloader = packageDownloader;
        }
        public void Download(IPackage package)
        {
            try
            {
                NuGet.PackageDownloader downloader = new NuGet.PackageDownloader();

                var filename = String.Format("{0}.{1}.nupkg", package.Id, package.Version);
                var path     = Path.Combine(_downloadfolder, filename);
                var stream   = new System.IO.FileStream(path, FileMode.Create);

                downloader.DownloadPackage(_uri, package, stream);
                downloader.ProgressAvailable += handler;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Download package {0} version {1} failed", package.Id, package.Version), ex);
            }
        }
        public void Download(IPackage package)
        {
            try
              {
            NuGet.PackageDownloader downloader = new NuGet.PackageDownloader();

            var filename = String.Format("{0}.{1}.nupkg", package.Id, package.Version);
            var path = Path.Combine(_downloadfolder, filename);
            var stream = new System.IO.FileStream(path, FileMode.Create);

            downloader.DownloadPackage(_uri, package, stream);
            downloader.ProgressAvailable += handler;
              }
              catch (Exception ex)
              {
            throw new Exception(string.Format("Download package {0} version {1} failed", package.Id, package.Version),ex);
              }
        }
예제 #6
0
파일: Utils.cs 프로젝트: vijaysg/NuFetch
        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" );
        }
예제 #7
0
        void DownloadPackage(IPackage package, string fullPathToDownloadTo, NuGet.PackageDownloader directDownloader)
        {
            Log.VerboseFormat("Found package {0} version {1}", package.Id, package.Version);
            Log.Verbose("Downloading to: " + fullPathToDownloadTo);

            var dsp = package as DataServicePackage;

            if (dsp != null && directDownloader != null)
            {
                Log.Verbose("A direct download is possible; bypassing the NuGet machine cache");
                using (var targetFile = new FileStream(fullPathToDownloadTo, FileMode.CreateNew))
                    directDownloader.DownloadPackage(dsp.DownloadUrl, dsp, targetFile);
                return;
            }

            var physical = new PhysicalFileSystem(Path.GetDirectoryName(fullPathToDownloadTo));
            var local    = new LocalPackageRepository(new FixedFilePathResolver(package.Id, fullPathToDownloadTo), physical);

            local.AddPackage(package);
        }
        public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _httpClient = client;
            _httpClient.AcceptCompression = true;

            _packageDownloader = packageDownloader;

            SendingRequest += (sender, e) =>
            {
                if (!String.IsNullOrEmpty(CurrentOperation))
                {
                    e.Request.Headers[RepositoryOperationNames.OperationHeaderName] = CurrentOperation;
                }
            };
        }
예제 #9
0
        public DataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (packageDownloader == null)
            {
                throw new ArgumentNullException("packageDownloader");
            }

            _httpClient = client;
            _httpClient.AcceptCompression = true;

            _packageDownloader = packageDownloader;

            SendingRequest += (sender, e) =>
            {
                if (!String.IsNullOrEmpty(CurrentOperation))
                {
                    e.Request.Headers[RepositoryOperationNames.OperationHeaderName] = CurrentOperation;
                }
            };
        }
예제 #10
0
        IPackage FindPackage(int attempt, string packageId, string packageVersion, string feed, out NuGet.PackageDownloader downloader)
        {
            Log.VerboseFormat("Finding package (attempt {0} of {1})", attempt, NumberOfTimesToAttemptToDownloadPackage);

            var remoteRepository = packageRepositoryFactory.CreateRepository(feed);

            var dspr = remoteRepository as DataServicePackageRepository;

            downloader = dspr != null ? dspr.PackageDownloader : null;

            var requiredVersion = new SemanticVersion(packageVersion);
            var package         = remoteRepository.FindPackage(packageId, requiredVersion, true, true);

            if (package == null)
            {
                throw new Exception(string.Format("Could not find package {0} {1} in feed: '{2}'", packageId, packageVersion, feed));
            }

            if (!requiredVersion.Equals(package.Version))
            {
                var message = string.Format("The package version '{0}' returned from the package repository doesn't match the requested package version '{1}'.", package.Version, requiredVersion);
                throw new Exception(message);
            }

            return(package);
        }
		public ExtendedDataServicePackageRepository(IHttpClient client, PackageDownloader packageDownloader) : base(client, packageDownloader) {}