コード例 #1
0
 private void EnumerateFilesFlatStyle()
 {
     try
     {
         Stopwatch timer = new Stopwatch();
         timer.Start();
         var             inputFiles = Directory.EnumerateFiles(_inputPath).ToArray();
         long            count      = 0;
         long            errorCount = 0;
         var             logger     = new CommandOutputLogger(NuGet.Common.LogLevel.Information);
         ParallelOptions ops        = new ParallelOptions {
             MaxDegreeOfParallelism = _maxThreadCount
         };
         Parallel.ForEach(inputFiles, ops, file =>
         {
             count++;
             if (count % 10000 == 0)
             {
                 DisplayStats(count, errorCount, inputFiles.Length, timer);
             }
             try
             {
                 //ProcessArchiveForNuGetAPIsUsedInScripts(file);
             }
             catch (Exception ex)
             {
                 errorCount++;
                 Console.WriteLine("Exception while parsing " + file);
                 Console.WriteLine(ex.Message);
                 var curroptFilePath = Path.Combine(@"f:\CurroptPackages", Path.GetFileName(file));
                 File.Move(file, curroptFilePath);
             }
         });
         Console.WriteLine("Done with all the " + count + " packages");
     }
     catch (AggregateException ae)
     {
         // This is where you can choose which exceptions to handle.
         foreach (var ex in ae.InnerExceptions)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
コード例 #2
0
        private void EnumerateFilesV3Style(bool onlyLatest)
        {
            try
            {
                Stopwatch timer = new Stopwatch();
                timer.Start();
                var             packageDirectories = Directory.EnumerateDirectories(_inputPath).ToArray();
                long            count      = 0;
                long            errorCount = 0;
                var             logger     = new CommandOutputLogger(NuGet.Common.LogLevel.Information);
                ParallelOptions ops        = new ParallelOptions {
                    MaxDegreeOfParallelism = _maxThreadCount
                };
                Parallel.ForEach(packageDirectories, ops, packageDirectory =>
                {
                    count++;
                    if (count % 10000 == 0)
                    {
                        DisplayStats(count, errorCount, packageDirectories.Length, timer);
                    }
                    try
                    {
                        var id         = Path.GetFileName(packageDirectory);
                        var idPackages = LocalFolderUtility.GetPackagesV3(_inputPath, id, logger);

                        if (onlyLatest)
                        {
                            var package = idPackages
                                          .OrderByDescending(e => e.Identity.Version)
                                          .Max();

                            ProcessArchiveForNuGetAPIsUsedInScripts(package);
                        }
                        else
                        {
                            foreach (var package in idPackages)
                            {
                                ProcessArchiveForNuGetAPIsUsedInScripts(package);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        errorCount++;
                        logger.LogInformation("Exception while parsing " + packageDirectory);
                        logger.LogInformation(ex.Message);
                        var curroptFilePath = Path.Combine(@"f:\CurroptPackages", Path.GetFileName(packageDirectory));
                        File.Move(packageDirectory, curroptFilePath);
                    }
                });
                logger.LogInformation("Done with all the " + count + " packages");
            }
            catch (AggregateException ae)
            {
                // This is where you can choose which exceptions to handle.
                foreach (var ex in ae.InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }