예제 #1
0
        static async public Task <ArrayList> EnumerateAssemblies()
        {
            ArrayList L = new ArrayList();

            //  Start a stopwatch.
            //var stopwatch = new Stopwatch();
            //stopwatch.Start();

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                //  Create an assembly view model.
                //onAssemblyEnumerated(desc);
                assemblyName = assemblyCacheEnum.GetNextAssembly();

                L.Add(desc);
            }

            //  Stop the stopwatch.
            //stopwatch.Stop();

            //  Return the elapsed time.
            //return stopwatch.Elapsed;

            return(L);
        }
예제 #2
0
        /// <summary>
        /// Enumerates assemblies from the global assembly cache.
        /// </summary>
        /// <param name="onAssemblyEnumerated">Action to call when each assembly is enumerated.</param>
        /// <returns>
        /// The time taken to enumerate all assemblies.
        /// </returns>
        public TimeSpan EnumerateAssemblies(Action <AssemblyDescription> onAssemblyEnumerated)
        {
            //  Start a stopwatch.
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                //  Create an assembly view model.
                onAssemblyEnumerated(desc);
                assemblyName = assemblyCacheEnum.GetNextAssembly();
            }

            //  Stop the stopwatch.
            stopwatch.Stop();

            //  Return the elapsed time.
            return(stopwatch.Elapsed);
        }
예제 #3
0
        static List <IFileListing> GetDllListing(IFileListing src)
        {
            var completeList     = new List <IFileListing>();
            var fileSystemParent = new DllListing {
                Name = "File System", IsDirectory = true
            };
            var gacItem = new DllListing {
                Name = "GAC", IsDirectory = true
            };

            if (src == null)
            {
                var drives = DriveInfo.GetDrives().Where(info => info.DriveType != DriveType.CDRom && info.DriveType != DriveType.Removable);
                try
                {
                    var listing = drives.Select(BuildDllListing);
                    fileSystemParent.Children = listing.ToList();
                }
                catch (Exception e)
                {
                    Dev2Logger.Error(e.Message, GlobalConstants.WarewolfError);
                }
                var enumAssembly = new AssemblyCacheEnumerator();
                var assemblyName = enumAssembly.GetNextAssembly();
                var gacList      = new List <IFileListing>();
                while (assemblyName != null)
                {
                    //  Create the assembly description.

                    try
                    {
                        var displayName = new AssemblyDescription(assemblyName).DisplayName;
                        var name        = GlobalConstants.GACPrefix + displayName;
                        gacList.Add(new DllListing {
                            Name = displayName, FullName = name, IsDirectory = false
                        });
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Error(e.Message, GlobalConstants.WarewolfError);
                    }
                    //  Create an assembly view model.
                    assemblyName = enumAssembly.GetNextAssembly();
                }
                gacItem.Children = gacList;

                completeList.Add(fileSystemParent);
                completeList.Add(gacItem);
            }
            else
            {
                if (src.IsDirectory)
                {
                    completeList = GetChildrenForDllListing(new DirectoryInfo(src.FullName));
                }
            }
            return(completeList);
        }
        public void AssemblyCacheEnumConstructorTest()
        {
            var target   = new AssemblyCacheEnumerator(null);
            var assembly = target.GetNextAssembly();

            while (assembly != null)
            {
                System.Diagnostics.Trace.WriteLine(assembly);
                assembly = target.GetNextAssembly();
            }

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
예제 #5
0
        public void EnumerateAssemblies()
        {
            //  Create an assembly enumerator.
            var assemblyEnumerator = new AssemblyCacheEnumerator();

            //  Get the first assembly.
            var assemblyName = assemblyEnumerator.GetNextAssembly();

            //  Start to loop through the assemblies.
            while (assemblyName != null)
            {
                //  The 'assemblyName' object is a COM interface, if we create an
                //  AssemblyDescription from it, we will have access to more information.
                var assemblyDescription = new AssemblyDescription(assemblyName);

                //  Show the display name.
                System.Diagnostics.Trace.WriteLine("Display Name: " + assemblyDescription.DisplayName);

                //  Move to the next assembly.
                assemblyName = assemblyEnumerator.GetNextAssembly();
            }
        }
예제 #6
0
        public static List <DotnetLibrary> GetGACLibraries()
        {
            var gacList = new List <DotnetLibrary>();

            try
            {
                var assemblyEnumerator = new AssemblyCacheEnumerator();

                var assemblyName = assemblyEnumerator.GetNextAssembly();

                while (assemblyName != null)
                {
                    var assemblyDescription = new AssemblyDescription(assemblyName);

                    string name = assemblyDescription.Name;
                    bool   probablyMicrosoftPackage = (name.StartsWith("Microsoft", StringComparison.Ordinal) || name.StartsWith("System", StringComparison.Ordinal));
                    if (!probablyMicrosoftPackage)
                    {
                        var gacLib = new DotnetLibrary
                        {
                            Culture = assemblyDescription.Culture,
                            ProcessorArchitecture = assemblyDescription.ProcessorArchitecture,
                            Name     = name,
                            Version  = assemblyDescription.Version,
                            Filepath = assemblyDescription.Path,
                        };
                        FileInfo fi = new FileInfo(gacLib.Filepath);
                        if (fi.Exists)
                        {
                            gacLib.Filename = fi.Name;
                            FileVersionInfo fvi                  = FileVersionInfo.GetVersionInfo(gacLib.Filepath);
                            bool            isDllFile            = fvi.FileVersion != null;
                            bool            isMicrosoftCopyright = fvi.LegalCopyright != null && fvi.LegalCopyright.Contains("Microsoft Corporation");

                            if (isDllFile && !isMicrosoftCopyright)
                            {
                                gacLib.FileDescription = fvi.FileDescription;
                                gacLib.Version         = fvi.FileVersion;
                                gacLib.ProductName     = fvi.ProductName;
                                gacLib.ProductVersion  = fvi.ProductVersion;
                                gacLib.Copyright       = fvi.LegalCopyright;
                                gacLib.Language        = fvi.Language;
                                gacLib.SHA1Hash        = GetFileSHA1(gacLib.Filepath);
                                gacLib.Md5Hash         = GetFileMD5(gacLib.Filepath);
                                try
                                {
                                    gacLib.Issue = LibraryIssueChecker.GetIssue(gacLib);
                                }
                                catch
                                {
                                    gacLib.Issue = null;
                                }

                                gacList.Add(gacLib);
                            }
                        }
                    }

                    assemblyName = assemblyEnumerator.GetNextAssembly();
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Could not load DLL list from the GAC. Error: {0}", ex.ToString());
                Console.Error.WriteLine("Could not load DLL list from the GAC.");
                return(new List <DotnetLibrary>());
            }

            return(gacList);
        }
예제 #7
0
        private void FindFrameworks()
        {
            if (frameworks == null || frameworks.Count < 0)
            {
                L = new ArrayList();

                var ac = new AssemblyCacheEnumerator();

                int i = 0;
                while (i < 2000)
                {
                    GACManagerApi.Fusion.IAssemblyName name = ac.GetNextAssembly();

                    if (name == null)
                    {
                        break;
                    }

                    //  Get the first assembly in the global assembly cache.
                    var someAssembly = new AssemblyDescription(name);

                    if (someAssembly == null)
                    {
                        break;
                    }

                    if (someAssembly.Name == null)
                    {
                        break;
                    }

                    //  Show the Runtime Version.
                    System.Diagnostics.Trace.WriteLine(someAssembly.ReflectionProperties.RuntimeVersion);
                    //richTextBox1.AppendText("\n\n\n" + someAssembly.ReflectionProperties.RuntimeVersion);
                    //richTextBox1.AppendText("\n\n\n" + someAssembly.ReflectionProperties.ToString());

                    int p = L.IndexOf(someAssembly.ReflectionProperties.RuntimeVersion);

                    if (p < 0)
                    {
                        L.Add(someAssembly.ReflectionProperties.RuntimeVersion);
                    }

                    i++;
                }
            }
            else
            {
                L = new ArrayList();

                foreach (DirectoryInfo d in frameworks)
                {
                    L.Add(d.Name);
                }
            }
            ToolStripComboBox c = toolStripComboBox1;

            c.DropDownStyle = ComboBoxStyle.DropDownList;

            c.Items.Clear();

            foreach (string s in L)
            {
                c.Items.Add(s);
            }

            if (c.Items.Count > 0)
            {
                c.SelectedIndex = c.Items.Count - 1;
            }
        }
예제 #8
0
        private static AssemblyDescription GetGacAssemblyPath(String moduleName)
        {
            ////String embedResourcePath = "DXApplication";
            ////String embedResourceCategoryPath = "Path";
            String dllModuleName = moduleName;

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                if (desc.Name.Equals(dllModuleName))
                {
                    //  We'll need a display name of the assembly to uninstall.
                    ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL";
                    var displayName = desc.DisplayName;
                    //  When we try to uninstall an assembly, an uninstall disposition will be
                    //  set to indicate the success of the operation.
                    var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown;

                    //  Install the assembly, without an install reference.
                    try
                    {
                        IAssemblyCache ac = AssemblyCache.GetIAssemblyCache(displayName, null);
                        if (ac != null)
                        {
                            return(desc);
                        }
                    }
                    catch (Exception exception)
                    {
                        //  We've failed to uninstall the assembly.
                        throw new InvalidOperationException("Failed to uninstall the assembly.", exception);
                    }
                    finally
                    {
                        ////////assemblyName = null;
                    }
                    //////////  Did we succeed?
                    ////////if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED)
                    ////////{
                    ////////    //  Hooray!
                    ////////    if (false)
                    ////////    {
                    ////////        assemblyName = null;
                    ////////    }
                    ////////    else
                    ////////    {
                    ////////        //  Create an assembly cache enumerator.
                    ////////        assemblyCacheEnum = new AssemblyCacheEnumerator(null);
                    ////////        //  Enumerate the assemblies.
                    ////////        assemblyName = assemblyCacheEnum.GetNextAssembly();
                    ////////    }
                    ////////}
                }
                else
                {
                    assemblyName = assemblyCacheEnum.GetNextAssembly();
                }
            }
            return(null);
        }
예제 #9
0
        private static void UnregisterDll(String moduleName, Boolean log = false)
        {
            ////String embedResourcePath = "DXApplication";
            ////String embedResourceCategoryPath = "Path";
            String dllModuleName = moduleName;

            //  Create an assembly cache enumerator.
            var assemblyCacheEnum = new AssemblyCacheEnumerator(null);

            //  Enumerate the assemblies.
            var assemblyName = assemblyCacheEnum.GetNextAssembly();

            while (assemblyName != null)
            {
                //  Create the assembly description.
                var desc = new AssemblyDescription(assemblyName);

                if (desc.Name.Equals(dllModuleName))
                {
                    //  We'll need a display name of the assembly to uninstall.
                    ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL";
                    var displayName = desc.DisplayName;
                    //  When we try to uninstall an assembly, an uninstall disposition will be
                    //  set to indicate the success of the operation.
                    var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown;

                    //  Install the assembly, without an install reference.
                    try
                    {
                        AssemblyCache.UninstallAssembly(displayName, null, out uninstallDisposition);
                        //  Depending on the result, show the appropriate message.
                        string message = string.Empty;
                        switch (uninstallDisposition)
                        {
                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown:
                            message = "Failed to uninstall assembly.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED:
                            message = "The assembly was uninstalled successfully!";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE:
                            message = "Cannot uninstall this assembly - it is in use.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED:
                            message = "Cannot uninstall this assembly - it has already been uninstalled.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING:
                            message = "Cannot uninstall this assembly - it has has a delete pending.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES:
                            message = "Cannot uninstall this assembly - it was installed as part of another product.";
                            break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND:
                            message = "Cannot uninstall this assembly - cannot find the assembly.";
                            break;

                        default:
                            break;
                        }
                        if (log)
                        {
                        }
                    }
                    catch (Exception exception)
                    {
                        //  We've failed to uninstall the assembly.
                        throw new InvalidOperationException("Failed to uninstall the assembly.", exception);
                    }
                    finally
                    {
                        ////////assemblyName = null;
                    }
                    //  Did we succeed?
                    if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED)
                    {
                        //  Hooray!
                        if (false)
                        {
                            assemblyName = null;
                        }
                        else
                        {
                            //  Create an assembly cache enumerator.
                            assemblyCacheEnum = new AssemblyCacheEnumerator(null);
                            //  Enumerate the assemblies.
                            assemblyName = assemblyCacheEnum.GetNextAssembly();
                        }
                    }
                }
                else
                {
                    assemblyName = assemblyCacheEnum.GetNextAssembly();
                }
            }
        }