Ejemplo n.º 1
0
        public void FindPackageMirrors()
        {
            var repo = new DataServicePackageRepository(new Uri(ServerUrl + "api/odata/"));

            var result = repo.FindPackage("Nuget.Core", new SemanticVersion("2.8.1"));

            Assert.That(result, Is.Not.Null, "Should mirror package from origin.");
            Assert.That(luceneRepository.LucenePackages.Count(), Is.EqualTo(1));
        }
        private DownloadResourceResult DownloadFromIdentity(
            PackageIdentity identity,
            IPackageRepository repository,
            NuGet.Common.ILogger logger,
            CancellationToken token)
        {
            var version         = SemanticVersion.Parse(identity.Version.ToString());
            var dataServiceRepo = repository as DataServicePackageRepository;

            if (dataServiceRepo != null)
            {
                // Clone the repo to allow for concurrent calls
                var sourceUri = UriUtility.CreateSourceUri(dataServiceRepo.Source);
                dataServiceRepo = new DataServicePackageRepository(sourceUri);

                var package            = dataServiceRepo.FindPackage(identity.Id, version);
                var dataServicePackage = package as DataServicePackage;

                if (dataServicePackage != null)
                {
                    token.ThrowIfCancellationRequested();

                    // For online sources get the url and retrieve it with cancel support
                    var url = dataServicePackage.DownloadUrl;

                    var downloadedPackage = DownloadToMachineCache(
                        MachineCache.Default,
                        identity,
                        dataServiceRepo,
                        url,
                        logger,
                        token);

                    if (downloadedPackage != null)
                    {
                        return(new DownloadResourceResult(downloadedPackage.GetStream()));
                    }
                }
            }
            else
            {
                var package = repository.FindPackage(identity.Id, version);

                if (package != null)
                {
                    // Use a folder reader for unzipped repos
                    if (repository is UnzippedPackageRepository)
                    {
                        var packagePath   = Path.Combine(repository.Source, identity.Id + "." + version);
                        var directoryInfo = new DirectoryInfo(packagePath);
                        if (directoryInfo.Exists)
                        {
                            return(new DownloadResourceResult(
                                       package.GetStream(),
                                       new PackageFolderReader(directoryInfo)));
                        }
                    }

                    return(new DownloadResourceResult(package.GetStream()));
                }
            }

            return(new DownloadResourceResult(DownloadResourceResultStatus.NotFound));
        }
 public Task <IPackage> GetLatestPackage(string id, bool prerelease)
 {
     return(Task.Run(() => _repository.FindPackage(id, (IVersionSpec)null, prerelease, false)));
 }