private static void GetWhitelistTest()
        {
            var nv          = WhitelistHeaderCollectionDownload.All();
            var pkgResponse = pmc.ExecuteAndDeserializeWithContent <List <PackageHeader> >(nv);

            if (pkgResponse == null)
            {
                Console.WriteLine("There was an error with the whitelist request.");
                return;
            }

            if (pkgResponse.content == null)
            {
                Console.WriteLine("The package response content was null.");
                return;
            }

            Console.WriteLine(pkgResponse.message);

            var libs = pkgResponse.content.SelectMany(p => p.versions.Last().node_libraries).Distinct();

            foreach (var lib in libs)
            {
                Console.WriteLine(lib);
            }
        }
Example #2
0
        /// <summary>
        /// Get a unique list of <seealso cref="AssemblyName"/> objects representing
        /// the assemblies that are in all the white listed packages.
        ///
        /// This method requests the white-listed package headers from the package manager.
        /// It then aggregates all of the values stored in the node_libraries fields.
        /// </summary>
        /// <returns></returns>
        private static IEnumerable <AssemblyName> GetWhitelistedAssemblyNames(IGregClient gregClient)
        {
            var assemblyNames = new List <AssemblyName>();

            try
            {
                var nv          = WhitelistHeaderCollectionDownload.All();
                var pkgResponse = gregClient.ExecuteAndDeserializeWithContent <List <PackageHeader> >(nv);
                if (pkgResponse == null || pkgResponse.content == null)
                {
                    return(assemblyNames);
                }

                // Get all the node_libraries for the latest version of each package
                var nodeLibraries = pkgResponse.content.ToList().
                                    Where(content => content.versions.Any() && content.versions.Last().node_libraries != null).
                                    SelectMany(content => content.versions.Last().node_libraries).Distinct();

                foreach (var asmName in nodeLibraries)
                {
                    try
                    {
                        assemblyNames.Add(new AssemblyName(asmName));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("The referenced assembly name in the package, {0}, could not be converted to an AssemblyName", asmName);
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to get whitelist assemblies from {0}", gregClient.BaseUrl);
                Console.WriteLine(ex.Message);
            }
            // convert values to AssemblyName
            return(assemblyNames);
        }