コード例 #1
0
        public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceRepository source, CancellationToken token)
        {
            UIMetadataResourceV3 curResource = null;

            if (await source.GetResourceAsync<ServiceIndexResourceV3>(token) != null)
            {
                var regResource = await source.GetResourceAsync<RegistrationResourceV3>();
                var reportAbuseResource = await source.GetResourceAsync<ReportAbuseResourceV3>();

                // construct a new resource
                curResource = new UIMetadataResourceV3(_client, regResource, reportAbuseResource);
            }

            return new Tuple<bool, INuGetResource>(curResource != null, curResource);
        }
コード例 #2
0
        public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            UIMetadataResourceV3 curResource = null;

            if (await source.GetResourceAsync <ServiceIndexResourceV3>(token) != null)
            {
                var regResource = await source.GetResourceAsync <RegistrationResourceV3>();

                var reportAbuseResource = await source.GetResourceAsync <ReportAbuseResourceV3>();

                // construct a new resource
                curResource = new UIMetadataResourceV3(_client, regResource, reportAbuseResource);
            }

            return(new Tuple <bool, INuGetResource>(curResource != null, curResource));
        }
コード例 #3
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);
        }