Exemple #1
0
        public void AddReferenceDatabase_BinaryWrongVersionLoading()
        {
            AddReferenceDatabase db = new AddReferenceDatabase(ArdbVersion.Current);

            db.AddUniqueMembers(PackageDatabaseTests.BuildDefaultSample());

            // Overwrite version with '9' and verify binary format won't load
            Verify.RoundTrip(db, new AddReferenceDatabase(), (w) => w.Write(9));
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public void AddReferenceDatabase_PackagePrereleaseVersion()
        {
            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);
            // Build and add the sample PackageDatabase
            PackageDatabase source = PackageDatabaseTests.BuildPreleaseSample();

            ardb.AddUniqueMembers(source);
            ardb.ConvertToImmutable();

            MemberQuery           query   = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false);
            PartialArray <Symbol> results = new PartialArray <Symbol>(10);

            query.TryFindMembers(ardb, ref results);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(PackageDatabaseTests.PRERELEASE_VERSION, ardb.GetPackageVersion(results[0].Index).ToString());
        }
        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;
        }
Exemple #5
0
        public void AddReferenceDatabase_PackageReleaseVersion()
        {
            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);
            // Build and add the sample PackageDatabase
            PackageDatabase source = PackageDatabaseTests.BuildDefaultSample();

            ardb.AddUniqueMembers(source);
            ardb.ConvertToImmutable();

            MemberQuery           query   = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false);
            PartialArray <Symbol> results = new PartialArray <Symbol>(10);

            query.TryFindMembers(ardb, ref results);
            Assert.AreEqual(1, results.Count);

            // We shouldn't persist non-prerelease version details in the ARDB
            Assert.AreEqual(String.Empty, ardb.GetPackageVersion(results[0].Index).ToString());
        }
Exemple #6
0
        public void AddReferenceDatabase_NewlineFlexibility()
        {
            PackageDatabase db = PackageDatabaseTests.BuildDefaultSample();

            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);

            ardb.AddUniqueMembers(db);
            string originalTextFormat = Write.ToString(ardb.WriteText);

            // Ensure non-Windows newlines don't trip up ReadText
            string modifiedNewlines    = originalTextFormat.Replace("\r\n", "\n");
            AddReferenceDatabase ardb2 = new AddReferenceDatabase(ArdbVersion.Current);

            Read.FromString(ardb2.ReadText, modifiedNewlines);

            // Verify everything in the ARDB round-tripped to validate read success
            string roundTripped = Write.ToString(ardb2.WriteText);

            Assert.AreEqual(originalTextFormat, roundTripped);
        }
Exemple #7
0
        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");
                }
            }
        }
Exemple #8
0
 private DatabaseAddResult CallAddUniqueMembers(AddReferenceDatabase ardb, PackageDatabase source)
 {
     return(ardb.AddUniqueMembers(source));
 }