public static List <DomAssemblyName> GetAssemblyList()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            List <DomAssemblyName> l = new List <DomAssemblyName>();

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder sb = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(sb, ref nChars, 0);

                l.Add(new DomAssemblyName(sb.ToString()));
            }
            return(l);
        }
        public static DomAssemblyName FindBestMatchingAssemblyName(DomAssemblyName name)
        {
            string[] info;
            string   version   = name.Version;
            string   publicKey = name.PublicKeyToken;

            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName;

            Fusion.CreateAssemblyNameObject(out assemblyName, name.ShortName, 0, 0);
            Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0);
            List <string> names = new List <string>();

            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder sb = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(sb, ref nChars, 0);

                string fullName = sb.ToString();
                if (publicKey != null)
                {
                    info = fullName.Split(',');
                    if (publicKey != info[3].Substring(info[3].LastIndexOf('=') + 1))
                    {
                        // Assembly has wrong public key
                        continue;
                    }
                }
                names.Add(fullName);
            }
            if (names.Count == 0)
            {
                return(null);
            }
            string  best        = null;
            Version bestVersion = null;
            Version currentVersion;

            if (version != null)
            {
                // use assembly with lowest version higher or equal to required version
                Version requiredVersion = new Version(version);
                for (int i = 0; i < names.Count; i++)
                {
                    info           = names[i].Split(',');
                    currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                    if (currentVersion.CompareTo(requiredVersion) < 0)
                    {
                        continue;                         // version not good enough
                    }
                    if (best == null || currentVersion.CompareTo(bestVersion) < 0)
                    {
                        bestVersion = currentVersion;
                        best        = names[i];
                    }
                }
                if (best != null)
                {
                    return(new DomAssemblyName(best));
                }
            }
            // use assembly with highest version
            best        = names[0];
            info        = names[0].Split(',');
            bestVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
            for (int i = 1; i < names.Count; i++)
            {
                info           = names[i].Split(',');
                currentVersion = new Version(info[1].Substring(info[1].LastIndexOf('=') + 1));
                if (currentVersion.CompareTo(bestVersion) > 0)
                {
                    bestVersion = currentVersion;
                    best        = names[i];
                }
            }
            return(new DomAssemblyName(best));
        }
Esempio n. 3
0
        private void workerPopulate_DoWork(object sender, DoWorkEventArgs e)
        {
            string runtimeDirectory            = RuntimeEnvironment.GetRuntimeDirectory();
            IEnumerable <string> refAssemblies = this.GetRefAssemblies(runtimeDirectory);
            HashSet <string>     coreFilesSet  = new HashSet <string>(from p in refAssemblies select Path.GetFileName(p), StringComparer.OrdinalIgnoreCase);
            IEnumerable <string> second        = from p in this.GetRefAssemblies(_baseRefPath)
                                                 where !coreFilesSet.Contains(Path.GetFileName(p))
                                                 select p;

            _refFileAssemblies = refAssemblies.Concat <string>(second).ToList <string>();
            if (!base.IsHandleCreated)
            {
                Thread.Sleep(500);
            }
            if (base.IsHandleCreated)
            {
                Exception exception;
                base.BeginInvoke(new Action(this.PopulateList));
                try
                {
                    _regFileAssemblies = this.GetExtraAssemblies().Distinct <string>().Except <string>(_refFileAssemblies).ToList <string>();
                }
                catch (Exception exception1)
                {
                    exception = exception1;
                    Log.Write(exception);
                }
                try
                {
                    Fusion.IAssemblyEnum enum2;
                    Fusion.IAssemblyName name;
                    List <string>        source = new List <string>();
                    Fusion.CreateAssemblyEnum(out enum2, IntPtr.Zero, null, Fusion.ASM_CACHE_FLAGS.ASM_CACHE_GAC, IntPtr.Zero);
                    while (enum2.GetNextAssembly(IntPtr.Zero, out name, 0) == 0)
                    {
                        name.GetDisplayName(null, 0, 0);
                        StringBuilder szDisplayName = new StringBuilder((int)pccDisplayName);
                        name.GetDisplayName(szDisplayName, ref pccDisplayName, 0);
                        source.Add(szDisplayName.ToString());
                    }
                    _gacAssemblies = (from n in source.Distinct <string>()
                                      select new AssemblyName(n) into a
                                      where !a.Name.EndsWith(".resources", StringComparison.InvariantCultureIgnoreCase)
                                      select a).ToList <AssemblyName>();
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                    Log.Write(exception);
                }
                try
                {
                    this.PopulateLatestFiles();
                }
                catch (Exception exception3)
                {
                    exception = exception3;
                    Log.Write(exception);
                }
                _populated = true;
            }
        }