public static List <string> SortAssemblies(List <string> assemblyNames)
        {
            List <SortableAssembly> unsorted = new List <SortableAssembly>();

            foreach (string name in assemblyNames)
            {
                Assembly assembly = CodeAssistTools.LoadAssembly(name);
                if (assembly != null)
                {
                    /*
                     * We don't know how expensive getting the
                     * referenced assemblies actually is so we get
                     * them once and keep a local copy.
                     */

                    SortableAssembly sa = new SortableAssembly();
                    sa.Name     = name;
                    sa.Assembly = assembly;
                    sa.Refs     = assembly.GetReferencedAssemblies();
                    unsorted.Add(sa);
                }
            }

            /*
             * Build the sorted list in reverse. Makes the logic easier
             * to follow and we have to iterate through the final list
             * to extract the filenames so we might as well do it backward.
             */

            List <SortableAssembly> sorted = new List <SortableAssembly>();

            foreach (SortableAssembly assembly in unsorted)
            {
                for (int i = 0; i < sorted.Count; i++)
                {
                    if (Array.IndexOf(
                            sorted[i].Refs, assembly.Assembly.FullName) != -1)
                    {
                        sorted.Insert(i, assembly);
                        break;
                    }
                }

                sorted.Add(assembly);
            }

            /*
             * Return the original filenames sorted in
             * dependency order.
             */

            List <string> sortedNames = new List <string>();

            foreach (SortableAssembly assembly in sorted)
            {
                sortedNames.Insert(0, assembly.Name);
            }

            return(sortedNames);
        }
Exemple #2
0
        private void AddNamespacesFromFile(string path)
        {
            path = "@" + path;

            Assembly assembly = CodeAssistTools.LoadAssembly(path);

            if (assembly == null)
            {
                return;
            }

            try
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsPublic)
                    {
                        continue;
                    }

                    string ns = type.Namespace;
                    if (String.IsNullOrEmpty(ns))
                    {
                        continue;
                    }

                    ReferenceNamespace item = FindListBoxItem(ns);

                    if (item == null)
                    {
                        item = new ReferenceNamespace(ns);
                        _checkedListBox.Items.Add(item, true);
                    }

                    item.AddAssembly(path);
                }
            }
            catch
            {
                // Ignore unloadable assemblies
            }
        }
        /*
         * Populate the database property with the namespaces
         * from the Global Assembly Cache.
         */

        private void CreateReferenceDatabase()
        {
            List <string> assemblyList = new List <string>();

            string gac = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC");
            string gac32 = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_32");
            string gac64 = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_64");
            string gacMSIL = Path.Combine(
                Environment.SystemDirectory, @"..\assembly\GAC_MSIL");

            assemblyList.AddRange(GetGACAssemblies(gac));
            assemblyList.AddRange(GetGACAssemblies(gac32));
            assemblyList.AddRange(GetGACAssemblies(gac64));
            assemblyList.AddRange(GetGACAssemblies(gacMSIL));

            _referenceDatabase = new ReferenceDatabase();

            _progressBar.Maximum = assemblyList.Count;
            _progressBar.Step    = 1;

            foreach (string name in assemblyList)
            {
                _progressBar.PerformStep();

                Assembly assembly = CodeAssistTools.LoadAssembly(name);
                if (assembly == null)
                {
                    continue;
                }

                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (!type.IsPublic)
                        {
                            continue;
                        }

                        string ns = type.Namespace;
                        if (String.IsNullOrEmpty(ns))
                        {
                            continue;
                        }

                        if (!_referenceDatabase.ContainsKey(ns))
                        {
                            _referenceDatabase[ns] = new ReferenceNamespace(ns);
                        }

                        _referenceDatabase[ns].AddAssembly(name);
                    }
                }
                catch
                {
                    // Ignore unloadable assemblies
                }

                Refresh();
            }
        }