Exemplo n.º 1
0
        public async Task <string> InstallPackageAsync(PackageId packageId, NuGetVersion packageVersion)
        {
            var cancellationToken = CancellationToken.None;
            var cache             = new SourceCacheContext()
            {
                DirectDownload = true, NoCache = true
            };
            var source = Repository.Factory.GetCoreV3(sourceUrl);
            var findPackageByIdResource = await source.GetResourceAsync <FindPackageByIdResource>();

            var nupkgPath = Path.Combine(_packageInstallDir, packageId.ToString(), packageVersion.ToNormalizedString(), $"{packageId}.{packageVersion.ToNormalizedString()}.nupkg");

            Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath));
            using var destinationStream = File.Create(nupkgPath);
            var success = await findPackageByIdResource.CopyNupkgToStreamAsync(
                id : packageId.ToString(),
                version : packageVersion,
                destination : destinationStream,
                cacheContext : cache,
                logger : _logger,
                cancellationToken : cancellationToken);

            if (!success)
            {
                throw new Exception($"Downloading {packageId} version {packageVersion.ToNormalizedString()} failed.");
            }

            return(nupkgPath);
        }
Exemplo n.º 2
0
        private LoadedAssemblies LoadV3Assemblies(NuGetVersion version)
        {
            var versioningIdentity = new PackageIdentity(_versioningId, version);

            _packageLoader.LoadPackageAssemblies(
                version.ToNormalizedString(),
                _framework,
                versioningIdentity);

            var frameworksIdentity = new PackageIdentity(_frameworksId, version);
            var context            = _packageLoader.LoadPackageAssemblies(
                version.ToNormalizedString(),
                _framework,
                frameworksIdentity);

            var versioningAssemblyName = context.LoadedAssemblies.GetByName(_versioningId);
            var frameworksAssemblyName = context.LoadedAssemblies.GetByName(_frameworksId);

            var loaded = new LoadedAssemblies
            {
                Context      = context,
                Framework    = frameworksAssemblyName,
                Version      = versioningAssemblyName,
                VersionRange = versioningAssemblyName,
            };

            return(loaded);
        }
Exemplo n.º 3
0
        public async Task Install(IReadOnlyList <SourceRepository> remoteRepositories, InstalledPackagesCache installedPackages, NuGetPackageManager packageManager)
        {
            if (_versionMatch == null)
            {
                return;
            }
            IReadOnlyList <SourceRepository> sourceRepositories = GetSourceRepositories(remoteRepositories);

            using (Trace.WithIndent().Verbose($"Installing package {_packageId} {_versionMatch.ToNormalizedString()}"))
            {
                // Check if this package was already installed in a previous run
                PackageIdentity packageIdentity = new PackageIdentity(_packageId, _versionMatch);
                if (installedPackages.VerifyPackage(packageIdentity, packageManager))
                {
                    Trace.Verbose($"Package {_packageId} {_versionMatch.ToNormalizedString()} was already installed");
                    return;
                }

                // If not, go ahead and install it
                using (installedPackages.AddPackage(packageIdentity, _currentFramework))
                {
                    ResolutionContext resolutionContext = new ResolutionContext(
                        DependencyBehavior.Lowest, _allowPrereleaseVersions, _allowUnlisted, VersionConstraints.None);
                    INuGetProjectContext projectContext = new NuGetProjectContext();
                    await packageManager.InstallPackageAsync(packageManager.PackagesFolderNuGetProject,
                                                             packageIdentity, resolutionContext, projectContext,
                                                             sourceRepositories, Array.Empty <SourceRepository>(), CancellationToken.None);

                    Trace.Verbose($"Installed package {_packageId} {_versionMatch.ToNormalizedString()}");
                }
            }
        }
Exemplo n.º 4
0
        public void WhenRunWithPackageIdItShouldUpdateFromManifestFile()
        {
            _toolRestoreCommand.Execute();
            _mockFeed.Packages[0].Version = _packageNewVersionA.ToNormalizedString();

            _defaultToolUpdateLocalCommand.Execute().Should().Be(0);

            AssertUpdateSuccess();
        }
        public VersionForDisplay(
            NuGetVersion version,
            string additionalInfo)
        {
            Version         = version;
            _additionalInfo = additionalInfo;

            _toString = string.IsNullOrEmpty(_additionalInfo) ?
                        Version.ToNormalizedString() :
                        _additionalInfo + " " + Version.ToNormalizedString();
        }
Exemplo n.º 6
0
        public void WhenRunWithPackageIdItShouldShowSuccessMessage()
        {
            var toolInstallLocalCommand = GetDefaultTestToolInstallLocalCommand();

            toolInstallLocalCommand.Execute().Should().Be(0);

            _reporter.Lines[0].Should()
            .Contain(
                string.Format(LocalizableStrings.LocalToolInstallationSucceeded,
                              _toolCommandNameA.ToString(),
                              _packageIdA,
                              _packageVersionA.ToNormalizedString(),
                              _manifestFilePath).Green());
        }
Exemplo n.º 7
0
        public void Add(
            FilePath to,
            PackageId packageId,
            NuGetVersion nuGetVersion,
            ToolCommandName[] toolCommandNames)
        {
            SerializableLocalToolsManifest deserializedManifest =
                DeserializeLocalToolsManifest(to);

            List <ToolManifestPackage> toolManifestPackages =
                GetToolManifestPackageFromOneManifestFile(deserializedManifest, to, to.GetDirectoryPath());

            var existing = toolManifestPackages.Where(t => t.PackageId.Equals(packageId)).ToArray();

            if (existing.Any())
            {
                var existingPackage = existing.Single();

                if (existingPackage.PackageId.Equals(packageId) &&
                    existingPackage.Version == nuGetVersion &&
                    CommandNamesEqual(existingPackage.CommandNames, toolCommandNames))
                {
                    return;
                }

                throw new ToolManifestException(string.Format(
                                                    LocalizableStrings.ManifestPackageIdCollision,
                                                    existingPackage.Version.ToNormalizedString(),
                                                    existingPackage.PackageId.ToString(),
                                                    to.Value,
                                                    nuGetVersion.ToNormalizedString()));
            }

            if (deserializedManifest.Tools == null)
            {
                deserializedManifest.Tools = new Dictionary <string, SerializableLocalToolSinglePackage>();
            }

            deserializedManifest.Tools.Add(
                packageId.ToString(),
                new SerializableLocalToolSinglePackage
            {
                Version  = nuGetVersion.ToNormalizedString(),
                Commands = toolCommandNames.Select(c => c.Value).ToArray()
            });

            _fileSystem.File.WriteAllText(to.Value, deserializedManifest.ToJson());
        }
Exemplo n.º 8
0
        public void VersionLength(string version)
        {
            // Arrange & Act
            var semVer = new NuGetVersion(version);

            Assert.Equal("2.0.0", semVer.ToNormalizedString());
        }
        private async Task <Stream> GetStreamAsync(
            string id,
            NuGetVersion version,
            Func <string, string, string> pathFunc,
            CancellationToken cancellationToken)
        {
            var lowercasedId = id.ToLowerInvariant();
            var lowercasedNormalizedVersion = version.ToNormalizedString().ToLowerInvariant();
            var path = pathFunc(lowercasedId, lowercasedNormalizedVersion);

            try
            {
                return(await _storage.GetAsync(path, cancellationToken));
            }
            catch (DirectoryNotFoundException)
            {
                // The "packages" prefix was lowercased, which was a breaking change
                // on filesystems that are case sensitive. Handle this case to help
                // users migrate to the latest version of BaGet.
                // See https://github.com/loic-sharma/BaGet/issues/298
                _logger.LogError(
                    $"Unable to find the '{PackagesPathPrefix}' folder. " +
                    "If you've recently upgraded BaGet, please make sure this folder starts with a lowercased letter. " +
                    "For more information, please see https://github.com/loic-sharma/BaGet/issues/298");
                throw;
            }
        }
Exemplo n.º 10
0
        public void TrackHandlerFailedToProcessPackage(IPackagesContainerHandler handler, string packageId, NuGetVersion packageVersion)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (string.IsNullOrEmpty(packageId))
            {
                throw new ArgumentException($"The package id parameter is required", nameof(packageId));
            }

            if (packageVersion == null)
            {
                throw new ArgumentNullException(nameof(packageVersion));
            }

            _telemetryClient.TrackMetric(
                TelemetryConstants.HandlerFailedToProcessPackage,
                1,
                new Dictionary <string, string>
            {
                { TelemetryConstants.Handler, handler.GetType().Name },
                { TelemetryConstants.Id, packageId },
                { TelemetryConstants.Version, packageVersion.ToNormalizedString() }
            });
        }
Exemplo n.º 11
0
        public void GivenManifestFileWhenAddingTheSamePackageIdToolItThrows()
        {
            string manifestFile = Path.Combine(_testDirectoryRoot, _manifestFilename);

            _fileSystem.File.WriteAllText(manifestFile, _jsonContent);

            var toolManifestFileEditor = new ToolManifestEditor(_fileSystem);

            PackageId    packageId    = new PackageId("dotnetsay");
            NuGetVersion nuGetVersion = NuGetVersion.Parse("3.0.0");
            Action       a            = () => toolManifestFileEditor.Add(new FilePath(manifestFile),
                                                                         packageId,
                                                                         nuGetVersion,
                                                                         new[] { new ToolCommandName("dotnetsay") });


            var expectedString = string.Format(
                LocalizableStrings.ManifestPackageIdCollision,
                packageId.ToString(),
                nuGetVersion.ToNormalizedString(),
                manifestFile,
                packageId.ToString(),
                "2.1.4");

            a.ShouldThrow <ToolManifestException>()
            .And.Message.Should().Contain(expectedString);

            _fileSystem.File.ReadAllText(manifestFile).Should().Be(_jsonContent);
        }
Exemplo n.º 12
0
        protected override void ExecuteCore()
        {
            NuGetVersion currentPackageVersion = new NuGetVersion(PackageVersion);
            NuGetVersion version = null;

            foreach (string nugetFeed in NugetFeeds)
            {
                SourceRepository           repository = Repository.Factory.GetCoreV3(nugetFeed);
                FindPackageByIdResource    resource   = repository.GetResource <FindPackageByIdResource>();
                SourceCacheContext         cache      = new SourceCacheContext();
                IEnumerable <NuGetVersion> versions   = resource.GetAllVersionsAsync(PackageId, cache, NullLogger.Instance, CancellationToken.None).Result;

                NuGetVersion packageVersion = versions?.Where(t => !t.IsPrerelease && t != currentPackageVersion).OrderByDescending(t => t.Version).FirstOrDefault();

                if (packageVersion != null)
                {
                    if ((version == null || packageVersion > version) && packageVersion.Version < currentPackageVersion.Version)
                    {
                        version = packageVersion;
                    }
                }
            }

            if (version == null)
            {
                throw new Exception(string.Format(Resources.BaselinePackageNotFound, PackageId, Environment.NewLine + string.Join(Environment.NewLine + " - ", NugetFeeds)));
            }

            LastStableVersion = version?.ToNormalizedString();
        }
Exemplo n.º 13
0
        public void Edit(
            FilePath manifest,
            PackageId packageId,
            NuGetVersion newNuGetVersion,
            ToolCommandName[] newToolCommandNames)
        {
            SerializableLocalToolsManifest deserializedManifest =
                DeserializeLocalToolsManifest(manifest);

            List <ToolManifestPackage> toolManifestPackages =
                GetToolManifestPackageFromOneManifestFile(deserializedManifest, manifest, manifest.GetDirectoryPath());

            var existing = toolManifestPackages.Where(t => t.PackageId.Equals(packageId)).ToArray();

            if (existing.Any())
            {
                var existingPackage = existing.Single();

                if (existingPackage.PackageId.Equals(packageId))
                {
                    var toEdit = deserializedManifest.Tools.Single(t => new PackageId(t.PackageId).Equals(packageId));

                    toEdit.Version  = newNuGetVersion.ToNormalizedString();
                    toEdit.Commands = newToolCommandNames.Select(c => c.Value).ToArray();
                }
            }
            else
            {
                throw new ArgumentException($"Manifest {manifest.Value} does not contain package id '{packageId}'.");
            }

            _fileSystem.File.WriteAllText(manifest.Value, deserializedManifest.ToJson());
        }
Exemplo n.º 14
0
        public LocalPackageInfo FindPackage(string packageId, NuGetVersion version)
        {
            var package = FindPackagesById(packageId)
                          .FirstOrDefault(localPackage => localPackage.Version == version);

            if (package == null)
            {
                return(null);
            }

            // Check for an exact match on casing
            if (StringComparer.Ordinal.Equals(packageId, package.Id) &&
                StringComparer.Ordinal.Equals(version.ToNormalizedString(), package.Version.ToNormalizedString()))
            {
                return(package);
            }

            // nuspec
            var nuspec = _nuspecCache.GetOrAdd(package.ExpandedPath, new Lazy <NuspecReader>(() => GetNuspec(package.ManifestPath, package.ExpandedPath)));

            // Create a new info to match the given id/version
            return(new LocalPackageInfo(
                       packageId,
                       version,
                       package.ExpandedPath,
                       package.ManifestPath,
                       package.ZipPath,
                       nuspec));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Process RegistrationIndex
        /// </summary>
        /// <param name="httpSource">Httpsource instance.</param>
        /// <param name="rangeUri">Paged registration index url address.</param>
        /// <param name="packageId">PackageId for package we're checking.</param>
        /// <param name="lower">Lower bound of nuget package.</param>
        /// <param name="upper">Upper bound of nuget package.</param>
        /// <param name="httpSourceCacheContext">SourceCacheContext for cache.</param>
        /// <param name="log">Logger Instance.</param>
        /// <param name="token">Cancellation token.</param>
        /// <returns></returns>
        private Task <RegistrationPage> GetRegistratioIndexPageAsync(
            HttpSource httpSource,
            string rangeUri,
            string packageId,
            NuGetVersion lower,
            NuGetVersion upper,
            HttpSourceCacheContext httpSourceCacheContext,
            ILogger log,
            CancellationToken token)
        {
            var packageIdLowerCase = packageId.ToLowerInvariant();
            var registrationPage   = httpSource.GetAsync(
                new HttpSourceCachedRequest(
                    rangeUri,
                    $"list_{packageIdLowerCase}_range_{lower.ToNormalizedString()}-{upper.ToNormalizedString()}",
                    httpSourceCacheContext)
            {
                IgnoreNotFounds = true,
            },
                httpSourceResult => DeserializeStreamDataAsync <RegistrationPage>(httpSourceResult.Stream, token),
                log,
                token);

            return(registrationPage);
        }
Exemplo n.º 16
0
        public string GetPackageManifestDownloadUrl(string id, NuGetVersion version)
        {
            var packageId      = id.ToLowerInvariant();
            var packageVersion = version.ToNormalizedString().ToLowerInvariant();

            return($"https://api.nuget.org/v3-flatcontainer/{packageId}/{packageVersion}/{packageId}.{packageVersion}.nuspec");
        }
Exemplo n.º 17
0
        public async Task <Package> FindOrNullAsync(
            string id,
            NuGetVersion version,
            bool includeUnlisted,
            CancellationToken cancellationToken)
        {
            var operation = TableOperation.Retrieve <PackageEntity>(
                id.ToLowerInvariant(),
                version.ToNormalizedString().ToLowerInvariant());

            var result = await _table.ExecuteAsync(operation, cancellationToken);

            var entity = result.Result as PackageEntity;

            if (entity == null)
            {
                return(null);
            }

            // Filter out the package if it's unlisted.
            if (!includeUnlisted && !entity.Listed)
            {
                return(null);
            }

            return(AsPackage(entity));
        }
        private string GetOutputPath(PackageBuilder builder, bool symbols = false, NuGetVersion nugetVersion = null)
        {
            string version;

            if (nugetVersion != null)
            {
                version = nugetVersion.ToNormalizedString();
            }
            else
            {
                version = String.IsNullOrEmpty(_packArgs.Version) ? builder.Version.ToNormalizedString() : _packArgs.Version;
            }

            // Output file is {id}.{version}
            string outputFile = builder.Id + "." + version;

            // If this is a source package then add .symbols.nupkg to the package file name
            if (symbols)
            {
                outputFile += SymbolsExtension;
            }
            else
            {
                outputFile += NuGetConstants.PackageExtension;
            }

            string outputDirectory = _packArgs.OutputDirectory ?? _packArgs.CurrentDirectory;

            return(Path.Combine(outputDirectory, outputFile));
        }
Exemplo n.º 19
0
        public void VersionLength(string version)
        {
            // Arrange & Act
            var semVer = new NuGetVersion(version);

            Assert.Equal("2.0.0", semVer.ToNormalizedString());
        }
Exemplo n.º 20
0
        private Stream GetFileStream(string id, NuGetVersion version, Func <string, string, string> pathFunc)
        {
            var versionString = version.ToNormalizedString().ToLowerInvariant();
            var path          = pathFunc(id.ToLowerInvariant(), versionString);

            return(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read));
        }
Exemplo n.º 21
0
 public static string PackageRegistration(this IUrlHelper url, string id, NuGetVersion version)
 => url.AbsoluteRouteUrl(
     Routes.RegistrationLeafRouteName,
     new {
     Id      = id.ToLowerInvariant(),
     Version = version.ToNormalizedString().ToLowerInvariant()
 });
Exemplo n.º 22
0
        public ToolInstallLocalCommandTests()
        {
            _packageVersionA = NuGetVersion.Parse("1.0.4");

            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _nugetGlobalPackagesFolder = new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _temporaryDirectory        = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlacePackages       = Path.Combine(_temporaryDirectory, "pathToPlacePackage");
            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore         = toolPackageStoreMock;
            _toolPackageInstallerMock = new ToolPackageInstallerMock(
                _fileSystem,
                _toolPackageStore,
                new ProjectRestorerMock(
                    _fileSystem,
                    _reporter,
                    new[]
            {
                new MockFeed
                {
                    Type     = MockFeedType.ImplicitAdditionalFeed,
                    Packages = new List <MockFeedPackage>
                    {
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdA.ToString(),
                            Version         = _packageVersionA.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameA.ToString()
                        }
                    }
                }
            }));

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);

            _manifestFilePath = Path.Combine(_temporaryDirectory, "dotnet-tools.json");
            _fileSystem.File.WriteAllText(Path.Combine(_temporaryDirectory, _manifestFilePath), _jsonContent);
            _toolManifestFinder = new ToolManifestFinder(new DirectoryPath(_temporaryDirectory), _fileSystem);
            _toolManifestEditor = new ToolManifestEditor(_fileSystem);

            ParseResult result = Parser.Instance.Parse($"dotnet tool install {_packageIdA.ToString()}");

            _appliedCommand = result["dotnet"]["tool"]["install"];
            Cli.CommandLine.Parser parser = Parser.Instance;
            _parseResult = parser.ParseFrom("dotnet tool", new[] { "install", _packageIdA.ToString() });

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);
        }
Exemplo n.º 23
0
        public ToolRestoreCommandTests()
        {
            _packageVersionA = NuGetVersion.Parse("1.0.4");
            _packageVersionWithCommandNameCollisionWithA = NuGetVersion.Parse("1.0.9");
            _packageVersionB = NuGetVersion.Parse("1.0.4");

            _reporter   = new BufferedReporter();
            _fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
            _nugetGlobalPackagesFolder = new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _temporaryDirectory        = _fileSystem.Directory.CreateTemporaryDirectory().DirectoryPath;
            _pathToPlacePackages       = Path.Combine(_temporaryDirectory, "pathToPlacePackage");
            ToolPackageStoreMock toolPackageStoreMock =
                new ToolPackageStoreMock(new DirectoryPath(_pathToPlacePackages), _fileSystem);

            _toolPackageStore         = toolPackageStoreMock;
            _toolPackageInstallerMock = new ToolPackageInstallerMock(
                _fileSystem,
                _toolPackageStore,
                new ProjectRestorerMock(
                    _fileSystem,
                    _reporter,
                    new List <MockFeed>
            {
                new MockFeed
                {
                    Type     = MockFeedType.ImplicitAdditionalFeed,
                    Packages = new List <MockFeedPackage>
                    {
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdA.ToString(),
                            Version         = _packageVersionA.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameA.ToString()
                        },
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdB.ToString(),
                            Version         = _packageVersionB.ToNormalizedString(),
                            ToolCommandName = _toolCommandNameB.ToString()
                        },
                        new MockFeedPackage
                        {
                            PackageId       = _packageIdWithCommandNameCollisionWithA.ToString(),
                            Version         = _packageVersionWithCommandNameCollisionWithA.ToNormalizedString(),
                            ToolCommandName = "A"
                        }
                    }
                }
            }),
                installCallback: () => _installCalledCount++);

            _parseResult = Parser.Instance.Parse("dotnet tool restore");

            _localToolsResolverCache
                = new LocalToolsResolverCache(
                      _fileSystem,
                      new DirectoryPath(Path.Combine(_temporaryDirectory, "cache")),
                      1);
        }
Exemplo n.º 24
0
        public async Task <string> DownloadPackageAsync(PackageId packageId,
                                                        NuGetVersion packageVersion = null,
                                                        PackageSourceLocation packageSourceLocation = null,
                                                        bool includePreview          = false,
                                                        DirectoryPath?downloadFolder = null)
        {
            CancellationToken cancellationToken = CancellationToken.None;

            if (_restoreActionConfig.Interactive)
            {
                DefaultCredentialServiceUtility.SetupDefaultCredentialService(_verboseLogger,
                                                                              _restoreActionConfig.Interactive);
            }

            (var source, var resolvedPackageVersion) = await GetPackageSourceAndVerion(packageId, packageVersion,
                                                                                       packageSourceLocation, includePreview);

            FindPackageByIdResource resource   = null;
            SourceRepository        repository = Repository.Factory.GetCoreV3(source);

            resource = await repository.GetResourceAsync <FindPackageByIdResource>(cancellationToken)
                       .ConfigureAwait(false);

            if (resource == null)
            {
                throw new NuGetPackageNotFoundException(
                          string.Format(LocalizableStrings.FailedToLoadNuGetSource, source.Source));
            }

            string nupkgPath = downloadFolder == null || !downloadFolder.HasValue
                ? Path.Combine(_packageInstallDir.Value, packageId.ToString(),
                               resolvedPackageVersion.ToNormalizedString(),
                               $"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg")
                : Path.Combine(downloadFolder.Value.Value,
                               $"{packageId}.{resolvedPackageVersion.ToNormalizedString()}.nupkg");

            Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath));
            using FileStream destinationStream = File.Create(nupkgPath);
            bool success = await resource.CopyNupkgToStreamAsync(
                packageId.ToString(),
                resolvedPackageVersion,
                destinationStream,
                _cacheSettings,
                _verboseLogger,
                cancellationToken);

            destinationStream.Close();

            if (!success)
            {
                throw new NuGetPackageInstallerException(
                          string.Format("Downloading {0} version {1} failed", packageId,
                                        packageVersion.ToNormalizedString()));
            }

            VerifySigning(nupkgPath);

            return(nupkgPath);
        }
Exemplo n.º 25
0
        public string GetRegistrationLeafUrl(string id, NuGetVersion version)
        {
            var packageMetadataUrl = GetPackageMetadataResourceUrl();
            var packageId          = id.ToLowerInvariant();
            var packageVersion     = version.ToNormalizedString().ToLowerInvariant();

            return($"{packageMetadataUrl}/{packageId}/{packageVersion}.json");
        }
        public static Uri GetPackageRegistrationUri(Uri registrationBaseUri, string id, NuGetVersion version)
        {
            var idFixed      = id.ToLowerInvariant();
            var versionFixed = version.ToNormalizedString().ToLowerInvariant();
            var baseUrl      = EnsureNoTrailingSlash(registrationBaseUri);

            return(new Uri($"{baseUrl}/{idFixed}/{versionFixed}.json"));
        }
        public static Uri GetNupkgUri(Uri packageBaseAddress, string id, NuGetVersion version)
        {
            var idFixed      = id.ToLowerInvariant();
            var versionFixed = version.ToNormalizedString().ToLowerInvariant();
            var baseUrl      = EnsureNoTrailingSlash(packageBaseAddress);

            return(new Uri($"{baseUrl}/{idFixed}/{versionFixed}/{idFixed}.{versionFixed}.nupkg"));
        }
Exemplo n.º 28
0
        public string GetPackageManifestDownloadUrl(string id, NuGetVersion version)
        {
            var packageContentUrl = GetPackageContentResourceUrl();
            var packageId         = id.ToLowerInvariant();
            var packageVersion    = version.ToNormalizedString().ToLowerInvariant();

            return($"{packageContentUrl}/{packageId}/{packageVersion}/{packageId}.nuspec");
        }
Exemplo n.º 29
0
 public async Task <bool> ExistsAsync(string id, NuGetVersion version, CancellationToken cancellationToken)
 {
     return(await _context
            .Packages
            .Where(p => p.Id == id)
            .Where(p => p.NormalizedVersionString == version.ToNormalizedString())
            .AnyAsync(cancellationToken));
 }
Exemplo n.º 30
0
        public override async Task <JObject> GetPackageMetadata(string id, NuGetVersion version)
        {
            var data = await GetPackageMetadataById(id);

            return(data.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(
                                           p["version"].ToString(),
                                           version.ToNormalizedString())));
        }
        /// <summary>
        /// Gets a URL for reporting package abuse. The URL will not be verified to exist.
        /// </summary>
        /// <param name="id">The package id (natural casing)</param>
        /// <param name="version">The package version</param>
        /// <returns>The first URL from the resource, with the URI template applied.</returns>
        public Uri GetReportAbuseUrl(string id, NuGetVersion version)
        {
            var uriString = _uriTemplate
                            .Replace("{id}", id)
                            .Replace("{version}", version.ToNormalizedString());

            return(new Uri(uriString));
        }