public void AddReferenceDatabase_DuplicateMerging() { int defaultArdbMemberCount, addedDefaultSampleDataMemberCount; AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current); PackageDatabase db = PackageDatabaseTests.BuildDefaultSample(); defaultArdbMemberCount = ardb.DeclaredMembers.Count; // Add the database once ardb.AddUniqueMembers(db); int memberCount = ardb.DeclaredMembers.Count; addedDefaultSampleDataMemberCount = (ardb.DeclaredMembers.Count - defaultArdbMemberCount); db = PackageDatabaseTests.BuildDefaultSample(Guid.NewGuid().ToString()); // Change only the package name. We should see no change // in member count, since all package contents are duped. memberCount = ardb.DeclaredMembers.Count; ardb.AddUniqueMembers(db); Assert.AreEqual(memberCount, ardb.DeclaredMembers.Count); db = PackageDatabaseTests.BuildDefaultSample(Guid.NewGuid().ToString()); // Add allowing duplicates should add the same number of // new members as fresh construction of the sample data // + 2 (to account for a duplicated type and for // an added assembly node). memberCount = ardb.DeclaredMembers.Count + addedDefaultSampleDataMemberCount; ardb.AddReferenceAssemblyTypes(db); Assert.AreEqual(memberCount + 2, ardb.DeclaredMembers.Count); // Write the ARDB tree [debuggability] string result = Write.ToString(ardb.WriteText); Trace.WriteLine(result); }
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"); } } }