Example #1
0
            public ReflectionProjectContent ReadProjectContent(ProjectContentRegistry registry)
            {
                if (reader.ReadInt64() != FileMagic)
                {
                    LoggingService.Warn("Read dom: wrong magic");
                    return(null);
                }
                if (reader.ReadInt16() != FileVersion)
                {
                    LoggingService.Warn("Read dom: wrong version");
                    return(null);
                }
                string assemblyName     = reader.ReadString();
                string assemblyLocation = reader.ReadString();
                long   time             = 0;

                try {
                    time = File.GetLastWriteTimeUtc(assemblyLocation).ToFileTime();
                } catch {}
                if (reader.ReadInt64() != time)
                {
                    LoggingService.Warn("Read dom: assembly changed since cache was created");
                    return(null);
                }
                DomAssemblyName[] referencedAssemblies = new DomAssemblyName[reader.ReadInt32()];
                for (int i = 0; i < referencedAssemblies.Length; i++)
                {
                    referencedAssemblies[i] = new DomAssemblyName(reader.ReadString());
                }
                this.pc = new ReflectionProjectContent(assemblyName, assemblyLocation, referencedAssemblies, registry);
                if (ReadClasses())
                {
                    return(pc);
                }
                else
                {
                    LoggingService.Warn("Read dom: error in file (invalid control mark)");
                    return(null);
                }
            }
Example #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
        }
Example #3
0
        public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, DomAssemblyName[] referencedAssemblies, ProjectContentRegistry registry)
        {
            if (assemblyFullName == null)
            {
                throw new ArgumentNullException("assemblyFullName");
            }
            if (assemblyLocation == null)
            {
                throw new ArgumentNullException("assemblyLocation");
            }
            if (registry == null)
            {
                throw new ArgumentNullException("registry");
            }

            this.registry                = registry;
            this.assemblyFullName        = assemblyFullName;
            this.assemblyName            = (assemblyFullName.IndexOf(',') > -1) ? assemblyFullName.Substring(0, assemblyFullName.IndexOf(',')) : assemblyFullName;
            this.referencedAssemblyNames = referencedAssemblies;
            this.assemblyLocation        = assemblyLocation;
            this.assemblyCompilationUnit = new DefaultCompilationUnit(this);

            try {
                assemblyFileLastWriteTime = File.GetLastWriteTimeUtc(assemblyLocation);
            } catch (Exception ex) {
                LoggingService.Warn(ex);
            }

            string fileName = null;

            if (assemblyLocation != typeof(object).Assembly.Location)
            {
                // First look in the assembly's directory.
                // mscorlib is the exception, because it is loaded from the runtime directory (C:\Windows\Microsoft.NET\Framework\v4.0.30319),
                // but that might contain an outdated version of mscorlib.xml (with less documented members than the mscorlib.xml in the Reference Assemblies)
                // (at least on my machine, lots of others don't seem to have the v4.0.30319\mscorlib.xml at all).
                fileName = XmlDoc.LookupLocalizedXmlDoc(assemblyLocation);
            }
            if (fileName == null)
            {
                // Not found -> look in other directories:
                foreach (string testDirectory in XmlDoc.XmlDocLookupDirectories)
                {
                    fileName = XmlDoc.LookupLocalizedXmlDoc(Path.Combine(testDirectory, Path.GetFileName(assemblyLocation)));
                    if (fileName != null)
                    {
                        break;
                    }
                }
            }

            if (fileName != null)
            {
                if (registry.persistence != null)
                {
                    this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc"));
                }
                else
                {
                    this.XmlDoc = XmlDoc.Load(fileName, null);
                }
            }
        }
Example #4
0
 public ReflectionProjectContent(Assembly assembly, ProjectContentRegistry registry)
     : this(assembly, assembly.Location, registry)
 {
 }