public static Task <bool> UploadPackageAsync(
     this NuGetClient client,
     string packageId,
     string version,
     string apiKey,
     IPackageStorageService storageService,
     CancellationToken cancellationToken = default)
 {
     return(client.UploadPackageAsync(packageId, NuGetVersion.Parse(version), apiKey, storageService, cancellationToken));
 }
        public static async Task <bool> UploadPackageAsync(
            this NuGetClient client,
            string packageId,
            NuGetVersion version,
            string apiKey,
            IPackageStorageService storageService,
            CancellationToken cancellationToken = default)
        {
            using var stream = await storageService.GetPackageStreamAsync(packageId, version, cancellationToken);

            if (stream == Stream.Null || cancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            return(await client.UploadPackageAsync(packageId, version, apiKey, stream, cancellationToken));
        }
        public async Task <IActionResult> PushLatest(string groupName, [FromForm] PackageGroupAssociation groupAssociation,
                                                     [FromServices] IPackageStorageService packageStorage, [FromServices] ISymbolStorageService symbolStorage)
        {
            if (groupName != groupAssociation.Group)
            {
                return(PackageGroups());
            }

            var group = await _dbContext.PackageGroups
                        .Include(x => x.Members)
                        .Include(x => x.Syndications)
                        .ThenInclude(x => x.PublishTarget)
                        .FirstOrDefaultAsync(x => x.Name == groupName);

            if (group is null)
            {
                return(PackageGroups());
            }

            var targets = group.Syndications.Select(x => x.PublishTarget);

            foreach (var package in group.Members)
            {
                var nugetPackage = await _context.Packages.Where(x => x.Id == package.PackageId && x.Listed == true)
                                   .OrderByDescending(x => x.Version)
                                   .FirstOrDefaultAsync();

                if (nugetPackage is null)
                {
                    continue;
                }

                foreach (var targetFeed in targets)
                {
                    var client = new NuGetClient(targetFeed.PublishEndpoint.ToString());
                    await client.UploadPackageAsync(nugetPackage.Id, nugetPackage.Version, targetFeed.ApiToken, packageStorage);

                    await client.UploadSymbolsPackageAsync(nugetPackage.Id, nugetPackage.Version, targetFeed.ApiToken, symbolStorage);
                }
            }

            // TODO: Add Success Page
            return(PackageGroups());
        }
示例#4
0
        private async Task <bool> PushPackageToSource(string packageId, NuGetVersion packageVersion, PublishTarget target)
        {
            var client = new NuGetClient(target.PublishEndpoint.ToString());

            return(await client.UploadPackageAsync(packageId, packageVersion, target.ApiToken, _packageStorageService));
        }