예제 #1
0
        public virtual IProjectContent GetProjectContentForReference(string itemInclude, string itemFileName)
        {
            lock (contents) {
                IProjectContent pc = GetExistingProjectContent(itemFileName);
                if (pc != null)
                {
                    return(pc);
                }

                LoggingService.Debug("Loading PC for " + itemInclude);

                string shortName = itemInclude;
                int    pos       = shortName.IndexOf(',');
                if (pos > 0)
                {
                    shortName = shortName.Substring(0, pos);
                }

                                #if DEBUG
                int time = Environment.TickCount;
                                #endif

                try {
                    pc = LoadProjectContent(itemInclude, itemFileName);
                } catch (BadImageFormatException ex) {
                    HostCallback.ShowAssemblyLoadErrorInternal(itemFileName, itemInclude, ex.Message);
                } catch (Exception ex) {
                    HostCallback.ShowError("Error loading assembly " + itemFileName, ex);
                } finally {
                                        #if DEBUG
                    LoggingService.Debug(string.Format("Loaded {0} in {1}ms", itemInclude, Environment.TickCount - time));
                                        #endif
                }

                if (pc != null)
                {
                    ReflectionProjectContent reflectionProjectContent = pc as ReflectionProjectContent;
                    if (reflectionProjectContent != null)
                    {
                        reflectionProjectContent.InitializeReferences();
                        if (reflectionProjectContent.AssemblyFullName != null)
                        {
                            contents[reflectionProjectContent.AssemblyFullName] = pc;
                        }
                    }
                    contents[itemInclude]  = pc;
                    contents[itemFileName] = pc;
                }
                return(pc);
            }
        }
예제 #2
0
        public static ReflectionProjectContent LoadProjectContent(Stream stream, ProjectContentRegistry registry)
        {
            ReflectionProjectContent pc;
            BinaryReader             reader = new BinaryReader(stream);

            try {
                pc = new ReadWriteHelper(reader).ReadProjectContent(registry);
                if (pc != null)
                {
                    pc.InitializeSpecialClasses();
                    pc.AssemblyCompilationUnit.Freeze();
                }
                return(pc);
            } catch (EndOfStreamException) {
                LoggingService.Warn("Read dom: EndOfStreamException");
                return(null);
            } catch (Exception ex) {
                HostCallback.ShowMessage("Error loading cached code-completion data.\n" +
                                         "The cached file might be corrupted and will be regenerated.\n\n" +
                                         ex.ToString());
                return(null);
            }
            // do not close the stream
        }
예제 #3
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);
                    }
                }
            }
            else
            {
                // find real file name for cecil:
                if (File.Exists(itemFileName))
                {
                    if (persistence != null)
                    {
                        pc = persistence.LoadProjectContentByAssemblyName(itemFileName);
                    }
                    if (pc == null)
                    {
                        pc = CecilReader.LoadAssembly(itemFileName, this);

                        if (persistence != null)
                        {
                            persistence.SaveProjectContent(pc);
                        }
                    }
                }
                else
                {
                    DomAssemblyName 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.ShortName, GetVersion__Token(asmName));
                        subPath = Path.Combine(subPath, asmName.ShortName + ".dll");
                        foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPathV4, "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(itemFileName, itemInclude, "Could not find assembly file.");
                    }
                }
            }
            return(pc);
        }