예제 #1
0
 GetRequstingPackageBaseAddressModel(
     this INugetServerProvider provider,
     HttpContext context)
 => new PackageBaseAddressInputModel(
     context.GetBaseUrl(), context.Request.Path,
     provider.GetResourceUrlPath(
         NugetServerResourceType.PackageBaseAddress));
예제 #2
0
        ParseResource(this INugetServerProvider provider,
                      HttpContext context)
        {
            var resources = provider
                            ?.NugetServerOptions
                            ?.Resources
                            ?.Select(r => r.Key);

            if (resources == null)
            {
                yield break;
            }

            var baseUrl = context.GetBaseUrl();

            foreach (var resource in resources)
            {
                var model = new ServerIndexResourceModel
                {
                    Type = resource.GetText(),
                    Id   = baseUrl + provider
                           .GetResourceUrlPath(resource)
                };;
                yield return(model);
            }
        }
예제 #3
0
        private static async Task RespondRegistrationIndexAsync(
            this INugetServerProvider provider,
            HttpContext context,
            RegistrationInputModel registrationInput,
            IEnumerable <Nuspec> nuspecs,
            bool useGzip = false)
        {
            var nuspecList = nuspecs
                             .Select(x => new { Nuspec = x, Version = (NuGetVersionString)x.Metadata.Version })
                             .OrderBy(x => x.Version)
                             .Select(x => x.Nuspec)
                             .ToList();

            var lowest             = nuspecList.First().Metadata;
            var uppest             = nuspecList.Last().Metadata;
            var parent             = registrationInput.BaseUrl + registrationInput.Path;
            var lowestVersion      = SemanticVersion.Parse(lowest.Version).ToFullString();
            var uppestVersion      = SemanticVersion.Parse(uppest.Version).ToFullString();
            var packageContentBase = registrationInput.BaseUrl +
                                     provider.GetResourceUrlPath(NugetServerResourceType.PackageBaseAddress);
            var model = new RegistrationIndexOutputModel
            {
                Count = nuspecList.Count
            };

            foreach (var nuspec in nuspecList)
            {
                var publishTime = new DateTimeOffset(new FileInfo(nuspec.FilePath).LastWriteTimeUtc);
                var metadata    = nuspec.Metadata;
                var modelItem   = new RegistrationPageOutputModel()
                {
                    Id    = $"{registrationInput.BaseUrl}{registrationInput.Path}#page/{metadata.Version}/{metadata.Version}",
                    Count = nuspecList.Count,
                    Lower = lowestVersion,
                    Upper = uppestVersion,
                };
                // If present Items, MUST also present Parent,Id need NOT be used.
                modelItem.Parent = parent;
                modelItem.Items  = new List <RegistrationLeafOutputModel>()
                {
                    new RegistrationLeafOutputModel
                    {
                        Id = registrationInput.BaseUrl +
                             registrationInput.PathBase +
                             $"/{metadata.Version}.json",
                        PackageContent = packageContentBase +
                                         $"/{metadata.Id.ToLowerInvariant()}" +
                                         $"/{metadata.Version.ToLowerInvariant()}" +
                                         $"/{metadata.Id.ToLowerInvariant()}" +
                                         $".{metadata.Version.ToLowerInvariant()}.nupkg",
                        Registration = registrationInput.BaseUrl +
                                       registrationInput.Path,
                        CatalogEntry = new RegistrationCatalogEntryOutputModel
                        {
                            Id_alias = registrationInput.BaseUrl +
                                       registrationInput.PathBase +
                                       $"/{metadata.Version}.json",
                            Id          = metadata.Id,
                            Authors     = metadata.Authors,
                            Description = metadata.Description,
                            ProjectUrl  = metadata.ProjectUrl,
                            IconUrl     = metadata.IconUrl,
                            Summary     = metadata.ReleaseNotes ?? metadata.Description,
                            Tags        = metadata.Tags?.Split(
                                new[] { ',' },
                                StringSplitOptions.RemoveEmptyEntries)
                                          ?.ToList() ?? new List <string>(0),
                            Title      = metadata.Id,
                            Version    = metadata.Version,
                            LicenseUrl = metadata.LicenseUrl,
                            Listed     = !provider.PackageStatusProvider.IsDeleted(metadata.Id, metadata.Version),
                            RequireLicenseAcceptance = metadata.RequireLicenseAcceptance,
                            PackageContent           = packageContentBase +
                                                       $"/{metadata.Id.ToLowerInvariant()}" +
                                                       $"/{metadata.Version.ToLowerInvariant()}" +
                                                       $"/{metadata.Id.ToLowerInvariant()}" +
                                                       $".{metadata.Version.ToLowerInvariant()}.nupkg",
                            Published        = publishTime,
                            DependencyGroups = metadata.Dependencies
                                               .Select(deps =>
                                                       new RegistrationDependencyGroupOutputModel
                            {
                                //Id_alias = ""
                                TargetFramework = deps.TargetFramework,
                                Dependencies    = deps.Dependency.Select(dep =>
                                                                         new RegistrationDependencyOutputModel
                                {
                                    Id = dep.Id,
                                    //Id_Alias = "",
                                    Range        = dep.Version,
                                    Registration = registrationInput.BaseUrl +
                                                   registrationInput.Path
                                }).ToList()
                            }).ToList()
                        }
                    }
                };
                model.Items.Add(modelItem);
            }
            await provider.WriteJsonResponseAsync(context, model, useGzip : useGzip);
        }
예제 #4
0
        RespondSearchQueryServiceAsync(
            this INugetServerProvider provider,
            HttpContext context)
        {
            var registrationsBaseUrl = context.GetBaseUrl() +
                                       provider.GetResourceUrlPath(
                NugetServerResourceType.RegistrationsBaseUrl);

            var searchInputModel = context.FromQueryString
                                   <SearchInputModel>();
            var searchOutputModel = new SearchOutputModel();

            var metadata_versions =
                provider.NuspecProvider
                .GetAll()
                .Where(nuspec => nuspec.Metadata != null)
                .Select(nuspec => new
            {
                nuspec.Metadata,
                Version = (NuGetVersionString)
                          nuspec.Metadata.Version
            })
                .Where(mv =>
                       searchInputModel.SemVerLevel?.Major != 1
                    ? true
                    : !mv.Version.IsSemVer2)
                .Where(mv =>
                       searchInputModel.PreRelease
                    ? true
                    : !mv.Version.IsPrerelease)
                .OrderBy(mv => mv.Metadata.Id)
                .GroupBy(mv => mv.Metadata.Id)
                .Where(mv => string.IsNullOrWhiteSpace(
                           searchInputModel.Q) ||
                       mv.Key.ToLowerInvariant()
                       .Contains(searchInputModel.Q
                                 .ToLowerInvariant()))
                .ToList();
            var takes = metadata_versions
                        .Skip(searchInputModel.Skip)
                        .Take(searchInputModel.Take)
                        .ToList();

            searchOutputModel.TotalHits =
                metadata_versions.Count;

            foreach (var path_metadata in takes)
            {
                var packageId = path_metadata.Key;
                var packageIdLowerInvariant =
                    packageId.ToLowerInvariant();

                var metadatas = path_metadata
                                .Select(x => x.Metadata)
                                .OrderBy(x => x.Version)
                                .ToList();

                var latest = metadatas.Last();
                searchOutputModel.Data.Add(new SearchResultModel
                {
                    Id      = latest.Id,
                    Authors = latest.Authors?.Split(
                        new[] { ',' },
                        StringSplitOptions.RemoveEmptyEntries)
                              ?.ToList() ?? new List <string>(0),
                    Description = latest.Description,
                    Owners      = latest.Owners?.Split(
                        new[] { ',' },
                        StringSplitOptions.RemoveEmptyEntries)
                                  ?.ToList() ?? new List <string>(0),
                    ProjectUrl   = latest.ProjectUrl,
                    IconUrl      = latest.IconUrl,
                    Registration = $"{registrationsBaseUrl}/{packageIdLowerInvariant}/index.json",
                    Id_alias     = $"{registrationsBaseUrl}/{packageIdLowerInvariant}/index.json",
                    Summary      = latest.ReleaseNotes
                                   ?? latest.Description,
                    Tags = latest.Tags?.Split(
                        new[] { ',' },
                        StringSplitOptions.RemoveEmptyEntries)
                           ?.ToList() ?? new List <string>(0),
                    Title      = latest.Id,
                    Version    = (NuGetVersionString)latest.Version,
                    LicenseUrl = latest.LicenseUrl,
                    Versions   = metadatas.Select(m => new
                                                  SearchResultPackageVersionModel
                    {
                        Id      = $"{registrationsBaseUrl}/{packageIdLowerInvariant}/{m.Version}.json",
                        Version = (NuGetVersionString)m.Version
                    }).ToList(),
                });
            }
            await provider
            .WriteJsonResponseAsync(
                context, searchOutputModel);
        }