internal static async Task <TelemetryEvent> ToTelemetryAsync(Data data, SourceRepository sourceRepository, string parentId, string actionName) { if (data.Resources.Count == 0) { return(null); } FeedType feedType = await sourceRepository.GetFeedType(CancellationToken.None); TelemetryEvent telemetry; lock (data._lock) { telemetry = new TelemetryEvent(EventName, new Dictionary <string, object>() { { PropertyNames.ParentId, parentId }, { PropertyNames.Action, actionName } }); AddSourceProperties(telemetry, sourceRepository, feedType); telemetry[PropertyNames.Duration.Total] = data.Resources.Values.Sum(r => r.duration.TotalMilliseconds); telemetry[PropertyNames.Nupkgs.Copied] = data.NupkgCount; telemetry[PropertyNames.Nupkgs.Bytes] = data.NupkgSize; AddResourceProperties(telemetry, data.Resources); if (data.Http.Requests > 0) { AddHttpProperties(telemetry, data.Http); } } return(telemetry); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { IPackageRegistrationMetadataResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { resource = new PackageRegistrationMetadataResourceDatabase(_queryService); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { FindLocalPackagesResource curResource = null; if (await source.GetFeedType(token) == FeedType.FileSystemV3) { curResource = new FindLocalPackagesResourceV3(source.PackageSource.Source); } return(new Tuple <bool, INuGetResource>(curResource != null, curResource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { PackageTimestampMetadataResourceV2 resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { resource = new PackageTimestampMetadataResourceV2( source.PackageSource.Source, _loggerFactory.CreateLogger <PackageTimestampMetadataResourceV2>()); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { INuGetResource resource = null; var feedType = await source.GetFeedType(token); if (feedType == FeedType.FileSystemV2 || feedType == FeedType.FileSystemUnzipped) { resource = new LocalV2FindPackageByIdResource(source.PackageSource); } return(Tuple.Create(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { INuGetResource resource = null; var feedType = await source.GetFeedType(token); // Default to v3 if the type is unknown if (feedType == FeedType.FileSystemV3 || feedType == FeedType.FileSystemUnknown) { resource = new LocalV3FindPackageByIdResource(source.PackageSource); } return(Tuple.Create(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { PackageMetadataResourceV2Feed resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { var httpSourceResource = await source.GetResourceAsync <HttpSourceResource>(token); var serviceDocument = await source.GetResourceAsync <ODataServiceDocumentResourceV2>(token); resource = new PackageMetadataResourceV2Feed(httpSourceResource, serviceDocument.BaseAddress, source.PackageSource); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { IPackageRegistrationMetadataResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV3) { var registration = await source.GetResourceAsync <RegistrationResourceV3>(token); var httpSourceResource = await source.GetResourceAsync <HttpSourceResource>(token); resource = new PackageRegistrationMetadataResourceV3(registration, httpSourceResource.HttpSource); } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token) { ListResource resource = null; if (await source.GetFeedType(token) == FeedType.HttpV2) { var httpSource = await source.GetResourceAsync <HttpSourceResource>(token); var serviceDocument = await source.GetResourceAsync <ODataServiceDocumentResourceV2>(token); if (serviceDocument != null) { var parser = new V2FeedParser(httpSource.HttpSource, serviceDocument.BaseAddress, source.PackageSource.Source); var feedCapabilityResource = new LegacyFeedCapabilityResourceV2Feed(parser, serviceDocument.BaseAddress); resource = new V2FeedListResource(parser, feedCapabilityResource, serviceDocument.BaseAddress); } } return(new Tuple <bool, INuGetResource>(resource != null, resource)); }
private async Task <int> Run() { var source = _source.HasValue() ? _source.Value().TrimEnd('/') : "https://api.nuget.org/v3/index.json"; if (_output.HasValue() && _update.HasValue()) { await Error.WriteLineAsync("'--output' and '--update' options must not be used together."); return(1); } var inputPath = Path.Combine(Directory.GetCurrentDirectory(), "Baseline.xml"); var input = XDocument.Load(inputPath); var packageSource = new PackageSource(source); var providers = Repository.Provider.GetCoreV3(); // Get v2 and v3 API support var sourceRepository = new SourceRepository(packageSource, providers); if (_update.HasValue()) { var updateResult = await RunUpdateAsync(inputPath, input, sourceRepository); if (updateResult != 0) { return(updateResult); } } var feedType = await sourceRepository.GetFeedType(CancellationToken.None); var feedV3 = feedType == FeedType.HttpV3; var packageBase = source + "/package"; if (feedV3) { var resources = await sourceRepository.GetResourceAsync <ServiceIndexResourceV3>(); packageBase = resources.GetServiceEntryUri(ServiceTypes.PackageBaseAddress).ToString().TrimEnd('/'); } var output = _output.HasValue() ? _output.Value() : Path.Combine(Directory.GetCurrentDirectory(), "Baseline.Designer.props"); var packageCache = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); var tempDir = Path.Combine(Directory.GetCurrentDirectory(), "obj", "tmp"); Directory.CreateDirectory(tempDir); var baselineVersion = input.Root.Attribute("Version").Value; var doc = new XDocument( new XComment(" Auto generated. Do not edit manually, use eng/tools/BaselineGenerator/ to recreate. "), new XElement("Project", new XElement("PropertyGroup", new XElement("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)"), new XElement("AspNetCoreBaselineVersion", baselineVersion)))); var client = new HttpClient(); foreach (var pkg in input.Root.Descendants("Package")) { var id = pkg.Attribute("Id").Value; var version = pkg.Attribute("Version").Value; var packageFileName = $"{id}.{version}.nupkg"; var nupkgPath = Path.Combine(packageCache, id.ToLowerInvariant(), version, packageFileName); if (!File.Exists(nupkgPath)) { nupkgPath = Path.Combine(tempDir, packageFileName); } if (!File.Exists(nupkgPath)) { var url = feedV3 ? $"{packageBase}/{id.ToLowerInvariant()}/{version}/{id.ToLowerInvariant()}.{version}.nupkg" : $"{packageBase}/{id}/{version}"; Console.WriteLine($"Downloading {url}"); using (var response = await client.GetStreamAsync(url)) { using (var file = File.Create(nupkgPath)) { await response.CopyToAsync(file); } } } using (var reader = new PackageArchiveReader(nupkgPath)) { doc.Root.Add(new XComment($" Package: {id}")); var propertyGroup = new XElement( "PropertyGroup", new XAttribute("Condition", $" '$(PackageId)' == '{id}' "), new XElement("BaselinePackageVersion", version)); doc.Root.Add(propertyGroup); foreach (var group in reader.NuspecReader.GetDependencyGroups()) { var itemGroup = new XElement("ItemGroup", new XAttribute("Condition", $" '$(PackageId)' == '{id}' AND '$(TargetFramework)' == '{group.TargetFramework.GetShortFolderName()}' ")); doc.Root.Add(itemGroup); foreach (var dependency in group.Packages) { itemGroup.Add(new XElement("BaselinePackageReference", new XAttribute("Include", dependency.Id), new XAttribute("Version", dependency.VersionRange.ToString()))); } } } } var settings = new XmlWriterSettings { OmitXmlDeclaration = true, Encoding = Encoding.UTF8, Indent = true, }; using (var writer = XmlWriter.Create(output, settings)) { doc.Save(writer); } Console.WriteLine($"Generated file in {output}"); return(0); }