Example #1
0
        protected virtual IProjectContent LoadProjectContent(string itemInclude, string itemFileName)
        {
            string shortName = itemInclude;
            int    pos       = shortName.IndexOf(',');

            if (pos > 0)
            {
                shortName = shortName.Substring(0, pos);
            }

            Assembly assembly           = GetDefaultAssembly(shortName);
            ReflectionProjectContent pc = null;

            if (assembly != null)
            {
                if (persistence != null)
                {
                    pc = persistence.LoadProjectContentByAssemblyName(assembly.FullName);
                }
                if (pc == null)
                {
                    pc = new ReflectionProjectContent(assembly, this);
                    if (persistence != null)
                    {
                        persistence.SaveProjectContent(pc);
                    }
                }
                if (pc != null)
                {
                    // add default .NET assemblies to redirected assemblies (both when loaded from persistence
                    // and when loaded using Reflection)
                    lock (redirectedAssemblyNames) {
                        redirectedAssemblyNames.Add(shortName, pc.AssemblyFullName);
                    }
                }
            }
            else
            {
                // find real file name for cecil:
                if (File.Exists(itemFileName))
                {
                    pc = CecilReader.LoadAssembly(itemFileName, this);
                }
                else
                {
                    GacAssemblyName asmName = GacInterop.FindBestMatchingAssemblyName(itemInclude);
                    if (persistence != null && asmName != null)
                    {
                        //LoggingService.Debug("Looking up in DOM cache: " + asmName.FullName);
                        pc = persistence.LoadProjectContentByAssemblyName(asmName.FullName);
                    }
                    if (pc == null && asmName != null)
                    {
                        string subPath = Path.Combine(asmName.Name, GetVersion__Token(asmName));
                        subPath = Path.Combine(subPath, asmName.Name + ".dll");
                        foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPath, "GAC*"))
                        {
                            itemFileName = Path.Combine(dir, subPath);
                            if (File.Exists(itemFileName))
                            {
                                pc = CecilReader.LoadAssembly(itemFileName, this);
                                if (persistence != null)
                                {
                                    persistence.SaveProjectContent(pc);
                                }
                                break;
                            }
                        }
                    }
                    if (pc == null)
                    {
                        HostCallback.ShowAssemblyLoadErrorInternal("?", itemInclude, "Could not find assembly file.");
                    }
                }
            }
            return(pc);
        }