예제 #1
0
 public UISearchMetadata(PackageIdentity identity, string title, string summary, Uri iconUrl, IEnumerable <VersionInfo> versions, UIPackageMetadata latestPackageMetadata)
 {
     Identity = identity;
     Title    = title;
     Summary  = summary;
     IconUrl  = iconUrl;
     Versions = versions;
     LatestPackageMetadata = latestPackageMetadata;
 }
 public UISearchMetadata(PackageIdentity identity, string title, string summary, Uri iconUrl, IEnumerable<VersionInfo> versions, UIPackageMetadata latestPackageMetadata)
 {
     Identity = identity;
     Title = title;
     Summary = summary;
     IconUrl = iconUrl;
     Versions = versions;
     LatestPackageMetadata = latestPackageMetadata;
 }
예제 #3
0
        private async Task <UISearchMetadata> GetSearchResult(JObject jObject, bool includePrerelease, CancellationToken token)
        {
            var id      = jObject.GetString(Properties.PackageId);
            var version = NuGetVersion.Parse(jObject.GetString(Properties.Version));

            var topPackage = new PackageIdentity(id, version);
            var iconUrl    = jObject.GetUri(Properties.IconUrl);
            var summary    = jObject.GetString(Properties.Summary);

            if (string.IsNullOrWhiteSpace(summary))
            {
                // summary is empty. Use its description instead.
                summary = jObject.GetString(Properties.Description);
            }

            var title = jObject.GetString(Properties.Title);

            if (string.IsNullOrEmpty(title))
            {
                // Use the id instead of the title when no title exists.
                title = id;
            }

            // get other versions
            var versionList = GetLazyVersionList(jObject, includePrerelease, version);

            // retrieve metadata for the top package
            UIPackageMetadata metadata = null;

            var v3MetadataResult = _metadataResource as UIMetadataResourceV3;

            // for v3 just parse the data from the search results
            if (v3MetadataResult != null)
            {
                metadata = v3MetadataResult.ParseMetadata(jObject);
            }

            // if we do not have a v3 metadata resource, request it using whatever is available
            if (metadata == null)
            {
                metadata = await _metadataResource.GetMetadata(topPackage, token);
            }

            var searchResult = new UISearchMetadata(topPackage, title, summary, iconUrl, versionList, metadata);

            return(searchResult);
        }
 public DetailedPackageMetadata(UIPackageMetadata serverData, int downloadCount)
 {
     Version = serverData.Identity.Version;
     Summary = serverData.Summary;
     Description = serverData.Description;
     Authors = serverData.Authors;
     Owners = serverData.Owners;
     IconUrl = serverData.IconUrl;
     LicenseUrl = serverData.LicenseUrl;
     ProjectUrl = serverData.ProjectUrl;
     ReportAbuseUrl = serverData.ReportAbuseUrl;
     Tags = serverData.Tags;
     DownloadCount = downloadCount;
     Published = serverData.Published;
     DependencySets = serverData.DependencySets.Select(e => new PackageDependencySetMetadata(e));
     HasDependencies = DependencySets.Any(
         dependencySet => dependencySet.Dependencies != null && dependencySet.Dependencies.Count > 0);
 }
예제 #5
0
        private async Task <UISearchMetadata> GetVisualStudioUISearchResult(JObject package, bool includePrerelease, CancellationToken token)
        {
            string          id         = package.Value <string>(Properties.PackageId);
            NuGetVersion    version    = NuGetVersion.Parse(package.Value <string>(Properties.Version));
            PackageIdentity topPackage = new PackageIdentity(id, version);
            Uri             iconUrl    = GetUri(package, Properties.IconUrl);
            string          summary    = package.Value <string>(Properties.Summary);

            if (string.IsNullOrWhiteSpace(summary))
            {
                // summary is empty. Use its description instead.
                summary = package.Value <string>(Properties.Description);
            }

            string title = package.Value <string>(Properties.Title);

            if (String.IsNullOrEmpty(title))
            {
                // Use the id instead of the title when no title exists.
                title = id;
            }

            // get other versions
            var versionList = new List <VersionInfo>();
            var versions    = package.Value <JArray>(Properties.Versions);

            if (versions != null)
            {
                foreach (var v in versions)
                {
                    var nugetVersion = NuGetVersion.Parse(v.Value <string>("version"));
                    var count        = v.Value <int>("downloads");
                    versionList.Add(new VersionInfo(nugetVersion, count));
                }
            }

            // TODO: in v2, we only have download count for all versions, not per version.
            // To be consistent, in v3, we also use total download count for now.
            int?totalDownloadCount = versionList.Select(v => v.DownloadCount).Sum();

            versionList = versionList.Select(v => new VersionInfo(v.Version, totalDownloadCount))
                          .ToList();

            if (!includePrerelease)
            {
                // remove prerelease version if includePrelease is false
                versionList.RemoveAll(v => v.Version.IsPrerelease);
            }

            if (!versionList.Select(v => v.Version).Contains(version))
            {
                versionList.Add(new VersionInfo(version, 0));
            }

            // retrieve metadata for the top package
            UIPackageMetadata    metadata      = null;
            UIMetadataResourceV3 v3metadataRes = _metadataResource as UIMetadataResourceV3;

            // for v3 just parse the data from the search results
            if (v3metadataRes != null)
            {
                metadata = v3metadataRes.ParseMetadata(package);
            }

            // if we do not have a v3 metadata resource, request it using whatever is available
            if (metadata == null)
            {
                metadata = await _metadataResource.GetMetadata(topPackage, token);
            }

            UISearchMetadata searchResult = new UISearchMetadata(topPackage, title, summary, iconUrl, versionList, metadata);

            return(searchResult);
        }