Esempio n. 1
0
    private static async Task GeneratePackageIndexAsync(string packageListPath, string packagesPath, string indexPackagesPath, string frameworksPath)
    {
        var frameworkLocators = new FrameworkLocator[]
        {
            new ArchivedFrameworkLocator(frameworksPath),
            new PackBasedFrameworkLocator(frameworksPath),
            new PclFrameworkLocator(frameworksPath)
        };

        Directory.CreateDirectory(packagesPath);
        Directory.CreateDirectory(indexPackagesPath);

        var nugetFeed      = new NuGetFeed(NuGetFeeds.NuGetOrg);
        var nugetStore     = new NuGetStore(nugetFeed, packagesPath);
        var packageIndexer = new PackageIndexer(nugetStore, frameworkLocators);

        var retryIndexed  = false;
        var retryDisabled = false;
        var retryFailed   = false;

        var document = XDocument.Load(packageListPath);

        Directory.CreateDirectory(packagesPath);

        var packages = document.Root !.Elements("package")
                       .Select(e => (Id: e.Attribute("id") !.Value, Version: e.Attribute("version") !.Value))
                       .ToArray();

        foreach (var(id, version) in packages.OrderBy(t => t.Id))
        {
            var path              = Path.Join(indexPackagesPath, $"{id}-{version}.xml");
            var disabledPath      = Path.Join(indexPackagesPath, $"{id}-all.disabled");
            var failedVersionPath = Path.Join(indexPackagesPath, $"{id}-{version}.failed");

            var alreadyIndexed = !retryIndexed && File.Exists(path) ||
                                 !retryDisabled && File.Exists(disabledPath) ||
                                 !retryFailed && File.Exists(failedVersionPath);

            if (alreadyIndexed)
            {
                if (File.Exists(path))
                {
                    Console.WriteLine($"Package {id} {version} already indexed.");
                }

                if (File.Exists(disabledPath))
                {
                    nugetStore.DeleteFromCache(id, version);
                }
            }
            else
            {
                Console.WriteLine($"Indexing {id} {version}...");
                try
                {
                    var packageEntry = await packageIndexer.Index(id, version);

                    if (packageEntry == null)
                    {
                        Console.WriteLine($"Not a library package.");
                        File.WriteAllText(disabledPath, string.Empty);
                        nugetStore.DeleteFromCache(id, version);
                    }
                    else
                    {
                        using (var stream = File.Create(path))
                            packageEntry.Write(stream);

                        File.Delete(disabledPath);
                        File.Delete(failedVersionPath);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed: " + ex.Message);
                    File.Delete(disabledPath);
                    File.Delete(path);
                    File.WriteAllText(failedVersionPath, ex.ToString());
                }
            }
        }
    }
Esempio n. 2
0
 public PackageIndexer(NuGetStore store, IEnumerable <FrameworkLocator> frameworkLocators)
 {
     _store             = store;
     _frameworkLocators = frameworkLocators.ToArray();
 }