public void Add(PackageDatabase source) { long ardbBytesBefore = _addReferenceDB.Bytes; DatabaseAddResult result = _addReferenceDB.AddUniqueMembers(source); PopularityDetails details = new PopularityDetails(); details.PackageName = source.Identity.PackageName; details.DownloadCount = source.Identity.DownloadCount; details.TotalMemberCount = source.Count; details.PublicTypeCount = result.PublicTypeCount; details.MergedTypeCount = result.MergedTypeCount; details.AddReferenceAddedBytes = _addReferenceDB.Bytes - ardbBytesBefore; _results.Add(details); _downloadTotal += details.DownloadCount; }
public static void Merge(MergerOptions options) { string individualLogs = options.PathToMerge + "Logs"; if (Directory.Exists(individualLogs)) { Directory.Delete(individualLogs, true); } if (options.WithPackageOutcomes) { Directory.CreateDirectory(individualLogs); } using (new TraceWatch("Filtering '{0}' covering {1:p0} of downloads to Public Types Only...", options.PathToMerge, options.DownloadPercentage)) { AddReferenceDatabase ardb = new AddReferenceDatabase(options.Version); ardb.DatabaseVersion = options.DatabaseVersion; // Determine indexes to include (up to popularity cutoff) List <string> indexesToInclude = null; if (Directory.Exists(options.PathToMerge)) { indexesToInclude = IndexesByPopularityToCutoff(Directory.EnumerateFiles(options.PathToMerge, "*.idx", SearchOption.AllDirectories), options.DownloadPercentage); if (indexesToInclude.Count == 0) { Trace.WriteLine("No indexes found to include. Stopping."); return; } } else if (File.Exists(options.PathToMerge)) { // Text file listing IDS files passed indexesToInclude = new List <string>(File.ReadAllLines(options.PathToMerge)); } else { throw new ArgumentException(String.Format("Merge doesn't know how to crawl passed path, '{0}'.", options.PathToMerge)); } HashSet <string> excludedPackageNames = ParsePackageNames(options.ExcludedPackageNames); HashSet <string> filteringDisabledPackageNames = ParsePackageNames(options.DisableDuplicateFilteringPackageNames); // Load individual package databases in approximate download count order (prefix of name is scale of download count) ProgressWriter p = new ProgressWriter(indexesToInclude.Count); foreach (PackageDatabase db in BinarySerializableExtensions.LoadEach <PackageDatabase>(indexesToInclude, true)) { if (!String.IsNullOrEmpty(db.Identity.PackageName) && excludedPackageNames.Contains(db.Identity.PackageName)) { Trace.WriteLine(String.Format("Excluded Package {0}", db.Identity.PackageName)); } else { if (filteringDisabledPackageNames.Contains(db.Identity.PackageName)) { ardb.AddReferenceAssemblyTypes(db); } else { DatabaseAddResult result = null; ardb.AddUniqueMembers(db); if (options.WithPackageOutcomes) { string log = Path.Combine(individualLogs, db.Identity.IndexFileName + ".log"); using (StreamWriter writer = new StreamWriter(log, false)) { result.WriteMemberResults(writer); } } } } p.IncrementProgress(); } // Include the percentage included in the name string outputFilePath = Path.Combine(options.OutputPath, Path.GetFileName(Path.GetFullPath(options.PathToMerge)) + "." + (options.DownloadPercentage * 100).ToString("g0")); // Write the merged tree, if requested (debuggability) if (options.WithMergedTreeLog) { string uniqueTreePath = options.PathToMerge + ".MergedTree.log"; using (new TraceWatch("Writing Unique Global Namespace tree to '{0}'...", uniqueTreePath)) { using (StreamWriter writer = new StreamWriter(uniqueTreePath, false)) { ardb.GetMergedMembers().WriteMergedTree(writer); } } } // Write the binary and text forms of the ARDB using (new TraceWatch("Writing AddReferenceDatabase '{0}'...", outputFilePath)) { ardb.FileWrite(outputFilePath + ".ardb"); CreateZip(outputFilePath + ".ardb"); Write.ToFile(ardb.WriteText, outputFilePath + ".ardb.txt"); CreateZip(outputFilePath + ".ardb.txt"); } } }