Ejemplo n.º 1
0
        private static TemplateDiscoveryMetadata CreateSearchMetadata(PackSourceCheckResult packSourceCheckResults)
        {
            List <ITemplateInfo> templateCache = packSourceCheckResults.PackCheckData.Where(r => r.AnyTemplates)
                                                 .SelectMany(r => r.FoundTemplates)
                                                 .Distinct(new TemplateIdentityEqualityComparer())
                                                 .ToList();

            Dictionary <string, PackToTemplateEntry> packToTemplateMap = packSourceCheckResults.PackCheckData
                                                                         .Where(r => r.AnyTemplates)
                                                                         .ToDictionary(
                r => r.PackInfo.Id,
                r =>
            {
                PackToTemplateEntry packToTemplateEntry = new PackToTemplateEntry(
                    r.PackInfo.Version,
                    r.FoundTemplates.Select(t => new TemplateIdentificationEntry(t.Identity, t.GroupIdentity)).ToList());

                if (r.PackInfo is NugetPackInfo npi)
                {
                    packToTemplateEntry.TotalDownloads = npi.TotalDownloads;
                }
                return(packToTemplateEntry);
            });

            Dictionary <string, object> additionalData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            foreach (IAdditionalDataProducer dataProducer in packSourceCheckResults.AdditionalDataProducers)
            {
                additionalData[dataProducer.DataUniqueName] = dataProducer.Data;
            }

            return(new TemplateDiscoveryMetadata(TemplateInfo.CurrentVersion, templateCache, packToTemplateMap, additionalData));
        }
Ejemplo n.º 2
0
        private static TemplateDiscoveryMetadata CreateLegacySearchMetadata(PackSourceCheckResult packSourceCheckResults)
        {
            List <ITemplateInfo> templateCache = packSourceCheckResults.SearchCache.TemplatePackages.SelectMany(p => p.Templates)
                                                 .Distinct(new TemplateIdentityEqualityComparer())
                                                 .Select(t => (ITemplateInfo) new LegacyBlobTemplateInfo(t))
                                                 .ToList();

            Dictionary <string, PackToTemplateEntry> packToTemplateMap = packSourceCheckResults.SearchCache.TemplatePackages
                                                                         .ToDictionary(
                r => r.Name,
                r =>
            {
                PackToTemplateEntry packToTemplateEntry = new PackToTemplateEntry(
                    r.Version ?? "",
                    r.Templates.Select(t => new TemplateIdentificationEntry(t.Identity, t.GroupIdentity)).ToList());
                packToTemplateEntry.TotalDownloads = r.TotalDownloads;
                packToTemplateEntry.Owners         = r.Owners;
                packToTemplateEntry.Verified       = r.Verified;
                return(packToTemplateEntry);
            });

            Dictionary <string, object> additionalData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            foreach (IAdditionalDataProducer dataProducer in packSourceCheckResults.AdditionalDataProducers)
            {
                if (dataProducer.Data != null)
                {
                    additionalData[dataProducer.DataUniqueName] = dataProducer.Data;
                }
            }

            return(new TemplateDiscoveryMetadata("1.0.0.3", templateCache, packToTemplateMap, additionalData));
        }