示例#1
0
        //// args[0] = Dump path
        //// args[1] = Number of packages to fetch
        //// args[2] = Dump partition size
        static void Main(string[] args)
        {
            var repo              = Repository.Factory.GetCoreV3(NugetODataFeedUrl);
            var httpSource        = HttpSource.Create(repo);
            var reader            = new NugetFeedReader(httpSource, NugetODataFeedUrl);
            var logger            = NullLogger.Instance;
            var totalPackageCount = reader.GetCountAsync(logger, CancellationToken.None).Result;

            var dumpPath         = args.Length > 0 && !string.IsNullOrEmpty(args[0]) ? args[0] : NuSearchConfiguration.PackagePath;
            var numberOfPackages = args.Length > 1 && int.TryParse(args[1], out int n) ? n : totalPackageCount;
            var partitionSize    = args.Length > 2 && int.TryParse(args[2], out int p) ? p : 1000;

            Console.WriteLine($"Downloading packages from {NugetODataFeedUrl} to {dumpPath}");

            var startTime     = DateTime.Now;
            var take          = Math.Min(100, numberOfPackages);
            var numberOfPages = (int)Math.Ceiling((double)numberOfPackages / take);

            Console.WriteLine($"Total {numberOfPages} pages to download");

            var sync = new object();
            var packages = new List <FeedPackage>(partitionSize);
            int page = 0, partition = 0;
            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = 4
            };
            var searchFilter = new SearchFilter(true, null)
            {
                OrderBy = SearchOrderBy.Id
            };

            Parallel.For(0, numberOfPages, parallelOptions, (i, state) =>
            {
                var foundPackages = reader.GetPackagesAsync(null, searchFilter, i * take, take, logger, CancellationToken.None).Result;

                lock (sync)
                {
                    packages.AddRange(foundPackages);
                    if (packages.Count >= partitionSize)
                    {
                        WritePackages(packages, dumpPath, partition);
                        partition++;
                        packages = new List <FeedPackage>(partitionSize);
                    }
                }
                Interlocked.Increment(ref page);
                Console.WriteLine($"Downloaded {page}/{numberOfPages} pages, written {partition} files");
            });

            if (packages.Count > 0)
            {
                WritePackages(packages, dumpPath, partition);
                partition++;
                Console.WriteLine($"Downloaded {page}/{numberOfPages} pages, written {partition} files");
            }

            var span = DateTime.Now - startTime;

            Console.WriteLine($"Harvesting completed in: {span}");
            Console.WriteLine("Press Enter to continue");
            Console.Read();
        }
示例#2
0
        public IActionResult ListUpdates(string nugetFeed, string[] projectFilter = null, string searchFilter = null)
        {
            projectFilter = projectFilter ?? new string[0];
            searchFilter  = (searchFilter ?? "").ToLowerInvariant();
            if (ViewBag.HasConfig = BaseProvider.ConfigProvider.HasConfig())
            {
                var nugetFeedTask = Task.Run(() =>
                {
                    var nugetReader = new NugetFeedReader(nugetFeed);
                    nugetReader.FetchPackages();
                    nugetReader.FilterToLatestPackages();
                    return(nugetReader.GetCurrentCollection().ToArray());
                });

                Task <Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]> > > FetchAllNugetDependencies(IProjectSource projectSource, IProjectReference project)
                {
                    return(Task.Run(() =>
                    {
                        try
                        {
                            var nugetDep = projectSource.GetAllNugetDependencies(project, false);
                            return new Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]> >(project, nugetDep);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Failed for project: " + project.GetName(), ex);
                        }
                    }));
                }

                BaseProvider.InitializeProjectSource();
                var source      = BaseProvider.ProjectSource;
                var projectTask = Task.Run(() =>
                {
                    var projects = source.GetAllProjects(false);
                    if (!string.IsNullOrWhiteSpace(searchFilter))
                    {
                        projects = projects.Where(x => x.GetName().ToLowerInvariant().Contains(searchFilter)).ToArray();
                    }
                    if (projectFilter.Length > 0)
                    {
                        projects = projects.Where(x => projectFilter.Contains(x.GetName())).ToArray();
                    }
                    var tasks = projects.Select(project => FetchAllNugetDependencies(source, project)).ToList();
                    Task.WhenAll(tasks).Wait();
                    return(tasks.Select(x => x.Result).ToArray());
                });
                nugetFeedTask.Wait();
                projectTask.Wait();
                var resultString = new StringBuilder();
                foreach (var project in projectTask.Result)
                {
                    var projectReference = project.Item1;
                    var projectString    = new StringBuilder();
                    foreach (var nugetDependencies in project.Item2)
                    {
                        var csprojString = new StringBuilder();
                        foreach (var nugetDependency in nugetDependencies.Value)
                        {
                            var nugetFeedPackage = nugetFeedTask.Result.SingleOrDefault(nfp => nfp.Id == nugetDependency.Id);
                            if (nugetFeedPackage == null)
                            {
                                continue;
                            }

                            /*var projects = source.GetAllProjects(false);
                             * foreach (var reference in projects)
                             * {
                             *  var definitions = source.GetAllNugetDefinitions(reference, false);
                             *  foreach (var keyValuePair in definitions)
                             *  {
                             *      keyValuePair.Value.Id ==
                             *  }
                             * }*/
                            NugetVersion dependencyVersion;
                            try
                            {
                                dependencyVersion = NugetVersion.FromString(nugetDependency.Version);
                            }
                            catch (FormatException)
                            {
                                csprojString.AppendLine($":{nugetDependency.Id} ERROR: Invalid format [dependency] {nugetDependency.Version}");
                                continue;
                            }

                            NugetVersion nugetFeedPackageVersion;
                            try
                            {
                                nugetFeedPackageVersion = NugetVersion.FromString(nugetFeedPackage.Version);
                            }
                            catch (FormatException)
                            {
                                csprojString.AppendLine($":{nugetDependency.Id} ERROR: Invalid format [nugetFeed] {nugetFeedPackage.Version}");
                                continue;
                            }

                            if (dependencyVersion.Prerelease || dependencyVersion != nugetFeedPackageVersion)
                            {
                                csprojString.AppendLine($"{nugetDependency.Id} {nugetDependency.Version} => {nugetFeedPackage.Version}" + (dependencyVersion.Prerelease ? " [PRERELEASE]" : ""));
                                LookThroughDependencies(nugetFeedPackage, csprojString, nugetFeedTask.Result, "    - ");
                            }
                        }

                        if (csprojString.Length > 0)
                        {
                            projectString.AppendLine("Csproj: " + nugetDependencies.Key.Item2.CsprojFilePath);
                            projectString.AppendLine("    " + csprojString.ToString().Replace("\n", "\n    ").TrimEnd());
                        }
                    }

                    var str = projectString.ToString();
                    if (str.Length > 0)
                    {
                        resultString.AppendLine(projectReference.GetName());
                        resultString.AppendLine("    " + projectString.ToString().Replace("\n", "\n    ").TrimEnd());
                        resultString.AppendLine();
                    }
                }

                return(Content(resultString.ToString()));
            }

            return(Content("Missing config/setup"));
        }