ReflectionProjectContent LoadProjectContent(string fileName, string include, ProjectContentRegistry registry) { fileName = Path.GetFullPath(fileName); LoggingService.Debug("Trying to load " + fileName); Assembly assembly; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += AssemblyResolve; lookupDirectory = Path.GetDirectoryName(fileName); try { if (File.Exists(fileName)) { assembly = Assembly.ReflectionOnlyLoadFrom(fileName); return new ReflectionProjectContent(assembly, fileName, registry); } assembly = ReflectionLoadGacAssembly(include, true); if (assembly != null) return new ReflectionProjectContent(assembly, registry); else throw new FileLoadException("Assembly not found."); } catch (BadImageFormatException ex) { LoggingService.Warn("BadImageFormat: " + include); throw new FileLoadException(ex.Message, ex); } finally { AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= AssemblyResolve; lookupDirectory = null; } }
internal DomPersistence(string cacheDirectory, ProjectContentRegistry registry) { this.cacheDirectory = cacheDirectory; this.registry = registry; cacheIndex = LoadCacheIndex(); }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, AssemblyName[] 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.referencedAssemblies = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); string fileName = LookupLocalizedXmlDoc(assemblyLocation); // Not found -> look in runtime directory. if (fileName == null) { string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); fileName = LookupLocalizedXmlDoc(Path.Combine(runtimeDirectory, Path.GetFileName(assemblyLocation))); } if (fileName == null) { // still not found -> look in WinFX reference directory string referenceDirectory = WinFXReferenceDirectory; if (!string.IsNullOrEmpty(referenceDirectory)) { fileName = LookupLocalizedXmlDoc(Path.Combine(referenceDirectory, Path.GetFileName(assemblyLocation))); } } if (fileName != null && registry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } }
public ProjectsManager() { _pcRegistry = new Dom.ProjectContentRegistry(); _pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "FOCodeCompletion")); _csProjectContent = new Dom.DefaultProjectContent(); }
public TextFile() { _scriptContent = string.Empty; _codeDocument = new TextDocument(new StringTextSource(_scriptContent)); _contentRegistry = new ProjectContentRegistry(); _filterStrategy = new NonFilterStrategy(); _projectContent = new DefaultProjectContent(); }
public ProjectFactory(ProjectParser projectParser, IFileSystem fileSystem, Compiler compiler, ProjectContentRegistry projectContentRegistry) { _projectParser = projectParser; _fileSystem = fileSystem; _compiler = compiler; _projectContentRegistry = projectContentRegistry; _projects = new Cache<string, ProjectData>(key => LoadProject(key)); }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); if (IsVisualBasic) { textEditorControl1.Text = @" Class A Sub B Dim xx As String End Sub End Class "; textEditorControl1.SetHighlighting("VBNET"); } else { textEditorControl1.Text = @"using System; class A { void B() { string x; } } "; textEditorControl1.SetHighlighting("C#"); } textEditorControl1.ShowEOLMarkers = false; textEditorControl1.ShowInvalidLines = false; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, textEditorControl1); ToolTipProvider.Attach(this, textEditorControl1); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = CurrentLanguageProperties; // create dummy parseInformation to prevent NullReferenceException when using CC before parsing // for the first time parseInformation = new Dom.ParseInformation(new Dom.DefaultCompilationUnit(myProjectContent)); }
public ReflectionProjectContent(Assembly assembly, string assemblyLocation, ProjectContentRegistry registry) : this(assembly.FullName, assemblyLocation, assembly.GetReferencedAssemblies(), registry) { foreach (Type type in assembly.GetExportedTypes()) { string name = type.FullName; if (name.IndexOf('+') < 0) { // type.IsNested AddClassToNamespaceListInternal(new ReflectionClass(assemblyCompilationUnit, type, name, null)); } } InitializeSpecialClasses(); }
public static ReflectionProjectContent LoadAssembly(string fileName, ProjectContentRegistry registry) { if (fileName == null) throw new ArgumentNullException("fileName"); if (registry == null) throw new ArgumentNullException("registry"); LoggingService.Info("Cecil: Load from " + fileName); AssemblyDefinition asm = AssemblyFactory.GetAssembly(fileName); List<AssemblyName> referencedAssemblies = new List<AssemblyName>(); foreach (AssemblyNameReference anr in asm.MainModule.AssemblyReferences) { referencedAssemblies.Add(new AssemblyName(anr.FullName)); } return new CecilProjectContent(asm.Name.FullName, fileName, referencedAssemblies.ToArray(), asm.MainModule.Types, registry); }
public void FixtureSetup() { ProjectContentRegistry r = new ProjectContentRegistry(); msc = r.Mscorlib; swf = r.GetProjectContentForReference("System.Windows.Forms", typeof(System.Windows.Forms.Form).Module.FullyQualifiedName); DefaultProjectContent dpc = new DefaultProjectContent(); dpc.ReferencedContents.Add(msc); DefaultCompilationUnit cu = new DefaultCompilationUnit(dpc); dummyClass = new DefaultClass(cu, "DummyClass"); cu.Classes.Add(dummyClass); methodForGenericCalls = new DefaultMethod(dummyClass, "DummyMethod"); dummyClass.Methods.Add(methodForGenericCalls); }
public static ReflectionProjectContent LoadAssembly(string fileName, ProjectContentRegistry registry) { if (fileName == null) throw new ArgumentNullException("fileName"); if (registry == null) throw new ArgumentNullException("registry"); LoggingService.Info("Cecil: Load from " + fileName); AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() }); List<DomAssemblyName> referencedAssemblies = new List<DomAssemblyName>(); foreach (ModuleDefinition module in asm.Modules) { foreach (AssemblyNameReference anr in module.AssemblyReferences) { referencedAssemblies.Add(new DomAssemblyName(anr.FullName)); } } return new CecilProjectContent(asm.Name.FullName, fileName, referencedAssemblies.ToArray(), asm, registry); }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // string appPath = Path.GetDirectoryName(Application.ExecutablePath); this.sqlConnection1.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + quot + Data_Path + quot + ";Integrated Security=True;User Instance=False;Timeout=60"; ICSharpCode.TextEditor.Document.FileSyntaxModeProvider provider = new ICSharpCode.TextEditor.Document.FileSyntaxModeProvider(appPath); ICSharpCode.TextEditor.Document.HighlightingManager.Manager.AddSyntaxModeFileProvider(provider); sqlEditor.Document.HighlightingStrategy = ICSharpCode.TextEditor.Document.HighlightingManager.Manager.FindHighlighter("SQL"); sqlEditor.Text = @"SELECT word.lemma, synset.pos, synset.definition FROM word LEFT JOIN sense ON word.wordid=sense.wordid LEFT JOIN synset ON sense.synsetid=synset.synsetid WHERE word.lemma='light' ORDER BY synset.pos "; // sqlEditor.SetHighlighting("C#"); // sqlEditor.SetHighlighting("SQL"); sqlEditor.ShowEOLMarkers = false; CodeCompletionKeyHandler.Attach(this, sqlEditor); HostCallbackImplementation.Register(this); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence caches referenced project contents for faster loading. // It also activates loading XML documentation files and caching them // for faster loading and lower memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); //myProjectContent.Language = Dom.LanguageProperties.CSharp; myProjectContent.Language = Dom.LanguageProperties.VBNet; }
public static ReflectionProjectContent LoadAssembly(string fileName, ProjectContentRegistry registry) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (registry == null) { throw new ArgumentNullException("registry"); } LoggingService.Info("Cecil: Load from " + fileName); AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(fileName, new ReaderParameters { AssemblyResolver = new DummyAssemblyResolver() }); return(new CecilProjectContent(asm.Name.FullName, fileName, (from module in asm.Modules from anr in module.AssemblyReferences select new DomAssemblyName(anr.FullName)).ToArray(), asm, registry)); }
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(); } return(pc); } catch (EndOfStreamException) { LoggingService.Warn("Read dom: EndOfStreamException"); return(null); } // do not close the stream }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, AssemblyName[] 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.referencedAssemblies = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); string fileName = LookupLocalizedXmlDoc(assemblyLocation); // Not found -> look in runtime directory. if (fileName == null) { string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); fileName = LookupLocalizedXmlDoc(Path.Combine(runtimeDirectory, Path.GetFileName(assemblyLocation))); } if (fileName == null) { // still not found -> look in WinFX reference directory string referenceDirectory = WinFXReferenceDirectory; if (!string.IsNullOrEmpty(referenceDirectory)) { fileName = LookupLocalizedXmlDoc(Path.Combine(referenceDirectory, Path.GetFileName(assemblyLocation))); } } if (fileName != null && registry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } }
public static ReflectionProjectContent LoadAssembly(string fileName, ProjectContentRegistry registry) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (registry == null) { throw new ArgumentNullException("registry"); } LoggingService.Info("Cecil: Load from " + fileName); AssemblyDefinition asm = AssemblyFactory.GetAssembly(fileName); List <AssemblyName> referencedAssemblies = new List <AssemblyName>(); foreach (AssemblyNameReference anr in asm.MainModule.AssemblyReferences) { referencedAssemblies.Add(new AssemblyName(anr.FullName)); } return(new CecilProjectContent(asm.Name.FullName, fileName, referencedAssemblies.ToArray(), asm.MainModule.Types, registry)); }
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); } AssemblyName[] referencedAssemblies = new AssemblyName[reader.ReadInt32()]; for (int i = 0; i < referencedAssemblies.Length; i++) { referencedAssemblies[i] = new AssemblyName(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); } }
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 }
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.referencedAssemblyNames = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); try { assemblyFileLastWriteTime = File.GetLastWriteTimeUtc(assemblyLocation); } catch (Exception ex) { LoggingService.Warn(ex); } string 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 (ProjectContentRegistry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(ProjectContentRegistry.persistence.CacheDirectory, "XmlDoc")); } else { this.XmlDoc = XmlDoc.Load(fileName, null); } } }
public IntellisenseEditor() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); textEditorControl1.SetHighlighting(Language); textEditorControl1.ShowEOLMarkers = false; CodeCompletionKeyHandler.Attach(this, textEditorControl1); HostCallbackImplementation.Register(this); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence caches referenced project contents for faster loading. // It also activates loading XML documentation files and caching them // for faster loading and lower memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = Dom.LanguageProperties.CSharp; }
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(); } 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 }
public void ExpectedPropertiesFromProjectContent() { ProjectContentRegistry registry = new ProjectContentRegistry(); IProjectContent mscorlibProjectContent = registry.Mscorlib; IClass c = mscorlibProjectContent.GetClass("System.Exception", 0); List<string> propertyNames = new List<string>(); foreach (IProperty p in c.Properties) { if (p.IsVirtual && !p.IsSealed) { propertyNames.Add(p.Name); } } propertyNames.Sort(); List<string> expectedPropertyNames = new List<string>(); expectedPropertyNames.Add("Data"); expectedPropertyNames.Add("HelpLink"); expectedPropertyNames.Add("Message"); expectedPropertyNames.Add("Source"); expectedPropertyNames.Add("StackTrace"); Assert.AreEqual(expectedPropertyNames.ToArray(), propertyNames.ToArray()); }
public void ExpectedMethodsFromProjectContent() { ProjectContentRegistry registry = new ProjectContentRegistry(); IProjectContent mscorlibProjectContent = registry.Mscorlib; IClass c = mscorlibProjectContent.GetClass("System.Collections.ObjectModel.Collection", 1); List<string> methodNames = new List<string>(); foreach (IMethod m in c.Methods) { if (m.IsVirtual && !m.IsSealed) { methodNames.Add(m.Name); } } List<string> expectedMethodNames = new List<string>(); expectedMethodNames.Add("ClearItems"); expectedMethodNames.Add("InsertItem"); expectedMethodNames.Add("RemoveItem"); expectedMethodNames.Add("SetItem"); methodNames.Sort(); expectedMethodNames.Sort(); Assert.AreEqual(expectedMethodNames.ToArray(), methodNames.ToArray()); }
public CecilProjectContent(string fullName, string fileName, AssemblyName[] referencedAssemblies, TypeDefinitionCollection types, ProjectContentRegistry registry) : base(fullName, fileName, referencedAssemblies, registry) { foreach (TypeDefinition td in types) { if ((td.Attributes & TypeAttributes.Public) == TypeAttributes.Public) { if ((td.Attributes & TypeAttributes.NestedAssembly) == TypeAttributes.NestedAssembly || (td.Attributes & TypeAttributes.NestedPrivate) == TypeAttributes.NestedPrivate || (td.Attributes & TypeAttributes.NestedFamANDAssem) == TypeAttributes.NestedFamANDAssem) { continue; } string name = td.FullName; if (name.Length == 0 || name[0] == '<') continue; if (name.Length > 2 && name[name.Length - 2] == '`') name = name.Substring(0, name.Length - 2); AddClassToNamespaceListInternal(new CecilClass(this.AssemblyCompilationUnit, null, td, name)); } } InitializeSpecialClasses(); }
static void UnloadReferencedContent(HashSet<IProject> projectsToRefresh, HashSet<IProjectContent> unloadedReferenceContents, ProjectContentRegistry referencedContentRegistry, IProjectContent referencedContent) { LoggingService.Debug("Unload referenced content " + referencedContent); List<RegistryContentPair> otherContentsToUnload = new List<RegistryContentPair>(); foreach (ProjectContentRegistryDescriptor registry in registries) { if (registry.IsRegistryLoaded) { foreach (IProjectContent pc in registry.Registry.GetLoadedProjectContents()) { if (pc.ThreadSafeGetReferencedContents().Contains(referencedContent)) { if (unloadedReferenceContents.Add(pc)) { LoggingService.Debug("Mark dependent content for unloading " + pc); otherContentsToUnload.Add(new RegistryContentPair(registry.Registry, pc)); } } } } } foreach (IProjectContent pc in ParserService.AllProjectContents) { IProject project = (IProject)pc.Project; if (projectsToRefresh.Contains(project)) continue; lock (pc.ReferencedContents) { if (pc.ReferencedContents.Remove(referencedContent)) { LoggingService.Debug("UnloadReferencedContent: Mark project for reparsing " + project.Name); projectsToRefresh.Add(project); } } } foreach (RegistryContentPair pair in otherContentsToUnload) { UnloadReferencedContent(projectsToRefresh, unloadedReferenceContents, pair.Key, pair.Value); } referencedContentRegistry.UnloadProjectContent(referencedContent); }
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); } } }
public ReflectionProjectContent(string assemblyFullName, string assemblyLocation, DomAssemblyName[] referencedAssemblies, ProjectContentRegistry registry) { // LoggingService.Special("ReflectionProjectContent started."); 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); } } else { if (registry.persistence != null) { this.XmlDoc = XmlDoc.Load(System.IO.Path.GetFileName(assemblyLocation), Path.Combine(registry.persistence.CacheDirectory, "XmlDoc")); } } // LoggingService.Special("ReflectionProjectContent passed."); }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); if (IsVisualBasic) { textEditorControl1.Text = @" Class A Sub B Dim xx As String End Sub End Class "; textEditorControl1.SetHighlighting("VBNET"); } else { textEditorControl1.Text = @"using System; class A { void B() { string x; } } "; textEditorControl1.SetHighlighting("C#"); } textEditorControl1.ShowEOLMarkers = false; textEditorControl1.ShowInvalidLines = false; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, textEditorControl1); ToolTipProvider.Attach(this, textEditorControl1); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = CurrentLanguageProperties; }
/// <summary> /// Initializes a new instance of the <see cref="MainForm"/> class. /// </summary> public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // if (IsVisualBasic) { // textEditorControl1.Text = @" //Class A // Sub B // Dim xx As String // // End Sub //End Class //"; // textEditorControl1.SetHighlighting("VBNET"); // } else { // textEditorControl1.Text = @"using System; //class A //{ // void B() // { // string x; // // } //} //"; // textEditorControl1.SetHighlighting("C#"); // } textEditorControl1.ShowEOLMarkers = false; textEditorControl1.ShowInvalidLines = false; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, textEditorControl1); ToolTipProvider.Attach(this, textEditorControl1); pcRegistry = new ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. // Paul Meems, 1 Sept. 2010: Create the file if it doesn't exist (Bug #1763): string cacheFolder = Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion"); if (!Directory.Exists(cacheFolder)) { Directory.CreateDirectory(cacheFolder); } pcRegistry.ActivatePersistence(cacheFolder); myProjectContent = new DefaultProjectContent(); myProjectContent.Language = CurrentLanguageProperties; }
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; } }
public void setupEnvironment() { try { TextEditor.ActiveTextAreaControl.TextArea.KeyEventHandler += TextAreaKeyEventHandler; TextEditor.ActiveTextAreaControl.TextArea.Caret.PositionChanged += Caret_PositionChanged; TextEditor.Disposed += CloseCodeCompletionWindow; // When the editor is disposed, close the code completion window //set up the ToolTipRequest event TextEditor.ActiveTextAreaControl.TextArea.ToolTipRequest += OnToolTipRequest; pcRegistry = new ProjectContentRegistry(); myProjectContent = new DefaultProjectContent {Language = currentLanguageProperties}; var persistanceFolder = PublicDI.config.O2TempDir.pathCombine("..//_CSharpCodeCompletion").fullPath(); // Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion"); persistanceFolder.createFolder(); pcRegistry.ActivatePersistence(persistanceFolder); // static parse current code thread //startParseCodeThread(); // add references startAddReferencesThread(); startParseCodeThread(); } catch (Exception ex) { ex.log("in setupEnvironment"); } }
private void ConfigureEditorTextControl() { txtCode.SetHighlighting("C#"); txtCode.ShowEOLMarkers = false; CodeCompletionKeyHandler.Attach(this, txtCode); HostCallbackImplementation.Register(this); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence caches referenced project contents for faster loading. // It also activates loading XML documentation files and caching them // for faster loading and lower memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = Dom.LanguageProperties.CSharp; }
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(); } return pc; } catch (EndOfStreamException) { LoggingService.Warn("Read dom: EndOfStreamException"); return null; } // do not close the stream }
public PNTabItem(string moduleName) { InitializeComponent(); DeclarationNode = new TreeNode("Declaration"); ModelNode = new TreeNode("Models"); TreeNode treeNode8 = new TreeNode("Petri Nets Model", new TreeNode[] { DeclarationNode, ModelNode }); MenuButton_SetError.Visible = false; //treeNode8.Name = "Root"; treeNode8.Text = "Petri Nets"; this.TreeView_Structure.Nodes.AddRange(new TreeNode[] { treeNode8 }); //AssertionNode.Name = "Declaration"; DeclarationNode.StateImageIndex = 0; //AssertionNode.Text = "Declaration"; ModelNode.Name = "Models"; ModelNode.StateImageIndex = 1; //ModelNode.Text = "Processes"; AddEventHandlerForButtons(); textEditorControl = new SharpDevelopTextAreaControl(); textEditorControl.Dock = DockStyle.Fill; textEditorControl.ContextMenuStrip = EditorContextMenuStrip; textEditorControl.BorderStyle = BorderStyle.Fixed3D; textEditorControl.Visible = true; this.splitContainer1.Panel2.Controls.Add(textEditorControl); this.TabText = Resources.Document_ + counter; counter++; textEditorControl.FileNameChanged += new EventHandler(_EditorControl_FileNameChanged); textEditorControl.TextChanged += new EventHandler(textEditorControl_TextChanged); textEditorControl.Tag = this; this.Padding = new Padding(2, 2, 2, 2); this.DockableAreas = DockAreas.Document; secondaryViewContentCollection = new SecondaryViewContentCollection(this); InitFiles(); file = FileService.CreateUntitledOpenedFile(TabText, new byte[] { }); file.CurrentView = this; textEditorControl.FileName = file.FileName; files.Clear(); files.Add(file); this.SetSyntaxLanguage(moduleName); textEditorControl.Document.FoldingManager.FoldingStrategy = new FoldingStrategy(); // Highlight the matching bracket or not... this.textEditorControl.ShowMatchingBracket = true; this.textEditorControl.BracketMatchingStyle = BracketMatchingStyle.Before; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, textEditorControl); ToolTipProvider.Attach(this, textEditorControl); pcRegistry = new ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. pcRegistry.ActivatePersistence(Path.Combine(Path.GetTempPath(), "CSharpCodeCompletion")); myProjectContent = new DefaultProjectContent(); myProjectContent.Language = LanguageProperties.CSharp; this.TreeView_Structure.HideSelection = false; splitContainer1.SplitterDistance = 100; addProcessToolStripMenuItem.PerformClick(); this.TreeView_Structure.ExpandAll(); Button_AddNewNail.Visible = false; //show the declaration TreeView_Structure.SelectedNode = DeclarationNode; TreeView_Structure_NodeMouseDoubleClick(null, new TreeNodeMouseClickEventArgs(DeclarationNode, MouseButtons.Left, 2, 0, 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.referencedAssemblyNames = referencedAssemblies; this.assemblyLocation = assemblyLocation; this.assemblyCompilationUnit = new DefaultCompilationUnit(this); try { assemblyFileLastWriteTime = File.GetLastWriteTimeUtc(assemblyLocation); } catch (Exception ex) { LoggingService.Warn(ex); } string 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 (ProjectContentRegistry.persistence != null) { this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(ProjectContentRegistry.persistence.CacheDirectory, "XmlDoc")); } else { this.XmlDoc = XmlDoc.Load(fileName, null); } } }
public void SetupIntellisense(TextEditorControl control) { _control = control; control.SetHighlighting((SupportedLanguage == SupportedLanguage.CSharp) ? "C#" : "VBNET"); control.ShowEOLMarkers = false; control.ShowInvalidLines = false; HostCallbackImplementation.Register(this); CodeCompletionKeyHandler.Attach(this, control); ToolTipProvider.Attach(this, control); ProjectContentRegistry = new ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence lets SharpDevelop.Dom create a cache file on disk so that // future starts are faster. // It also caches XML documentation files in an on-disk hash table, thus // reducing memory usage. try { if (Settings.Default.CacheFiles) { var persistencePath = Path.Combine(Path.GetTempPath(), ReflexilPersistence); var persistenceCheck = Path.Combine(persistencePath, ReflexilPersistenceCheck); Directory.CreateDirectory(persistencePath); // Check write/access to directory File.WriteAllText(persistenceCheck, @"Using cache!"); // Check write file rights File.ReadAllText(persistenceCheck); // Check read file rights ProjectContentRegistry.ActivatePersistence(persistencePath); } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // don't use cache file } ProjectContent = new DefaultProjectContent {Language = LanguageProperties}; ParseInformation = new ParseInformation(new DefaultCompilationUnit(ProjectContent)); }
public static void add_Reference(this DefaultProjectContent projectContent, ProjectContentRegistry pcRegistry, string assemblyToLoad, Action<string> debugMessage) { try { lock (ProjectContentRegistry.persistence) { //debugMessage("Loading Code Completion Reference: {0}".format(assemblyToLoad)); IProjectContent referenceProjectContent = pcRegistry.GetProjectContentForReference(assemblyToLoad, assemblyToLoad); if (referenceProjectContent == null) "referenceProjectContent was null".error(); else { projectContent.AddReferencedContent(referenceProjectContent); if (referenceProjectContent is ReflectionProjectContent) (referenceProjectContent as ReflectionProjectContent).InitializeReferences(); else "something when wrong in DefaultProjectContent.add_Reference".error(); } } } catch (Exception ex) { ex.log("in DefaultProjectContent.add_Reference for assembly: {0}".format(assemblyToLoad)); } }
public ScriptForm(PBObjLib.Application app) { m_App = app; InitializeComponent(); editor.ShowEOLMarkers = false; editor.ShowSpaces = false; editor.ShowTabs = false; editor.ShowInvalidLines = false; editor.SetHighlighting("C#"); workDir = Path.GetTempPath() + "gPBToolKit\\"; fullPathDummyFile = workDir + DummyFileName; if (!Directory.Exists(workDir)) { Directory.CreateDirectory(workDir); } if (!Directory.Exists(workDir + "\\CSharpCodeCompletion\\")) { Directory.CreateDirectory(workDir + "\\CSharpCodeCompletion"); } string indexFile = workDir + "CSharpCodeCompletion\\index.dat"; if (!File.Exists(fullPathDummyFile)) { string sh = @"using System; using System.Collections.Generic; using System.Text; using PBObjLib; using PBSymLib; using VBIDE; using System.Windows.Forms; namespace gPBToolKit { public class gkScript { // ���������� �������� ������� public static void StartScript(Display d) { foreach (Symbol s in d.Symbols) { if (s.Type == 7) { Value v = (Value)s; v.BackgroundColor = 32768; v.ShowUOM = true; } } Action(d.Application); } public static void Action(PBObjLib.Application m_App) { try { VBProject project = null; CodeModule codeModule = null; for (int i = 1; i <= ((VBE)m_App.VBE).VBProjects.Count; i++) { VBProject bufProject = ((VBE)m_App.VBE).VBProjects.Item(i); if (bufProject.FileName.ToLower() == m_App.ActiveDisplay.Path.ToLower()) // ���� �� ��������� ����� ������ { project = bufProject; break; } } if (project == null) { MessageBox.Show(""VBProject not found""); return; } codeModule = project.VBComponents.Item(""ThisDisplay"").CodeModule; try { string procName = ""Display_Open""; int procCountLine = -1, procStart = -1; try{ procStart = codeModule.get_ProcBodyLine(procName, vbext_ProcKind.vbext_pk_Proc); procCountLine = codeModule.get_ProcCountLines(procName, vbext_ProcKind.vbext_pk_Proc); } catch{} if (procStart > 0) codeModule.DeleteLines(procStart, procCountLine); string srvName = ""do51-dc1-du-pis.sgpz.gpp.gazprom.ru""; string rootModule = ""����""; string dispOpenText = string.Format(@"" Private Sub Display_Open() AVExtension1.Initialize """"{0}"""", """"{1}"""", ThisDisplay, Trend1 End Sub"", srvName, rootModule); codeModule.AddFromString(dispOpenText); } catch (Exception ex) { MessageBox.Show(ex.Message + "" ""+ ex.StackTrace); } } catch { } } } } "; UTF8Encoding asciEncoding = new UTF8Encoding(); FileStream fs = File.Create(fullPathDummyFile); fs.Write(asciEncoding.GetBytes(sh), 0, asciEncoding.GetByteCount(sh)); fs.Close(); } if (!File.Exists(indexFile)) { File.Create(indexFile).Close(); } editor.LoadFile(fullPathDummyFile); refList.Items.Add("System.dll"); refList.Items.Add("System.Drawing.dll"); refList.Items.Add("System.Windows.Forms.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBObjLib.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\OSIsoft.PBSymLib.dll"); refList.Items.Add(@"C:\Program Files (x86)\PIPC\Procbook\Interop.VBIDE.dll"); CodeCompletionKeyHandler.Attach(this, editor); HostCallbackImplementation.Register(this); pcRegistry = new Dom.ProjectContentRegistry(); // Default .NET 2.0 registry // Persistence caches referenced project contents for faster loading. // It also activates loading XML documentation files and caching them // for faster loading and lower memory usage. pcRegistry.ActivatePersistence(Path.Combine(workDir, "CSharpCodeCompletion")); myProjectContent = new Dom.DefaultProjectContent(); myProjectContent.Language = Dom.LanguageProperties.CSharp; }
public ReflectionProjectContent(Assembly assembly, ProjectContentRegistry registry) : this(assembly, assembly.Location, registry) { }
public void FixtureSetup() { ProjectContentRegistry r = new ProjectContentRegistry(); msc = r.Mscorlib; swf = r.GetProjectContentForReference("System.Windows.Forms", "System.Windows.Forms"); }
public CecilProjectContent(string fullName, string fileName, DomAssemblyName[] referencedAssemblies, AssemblyDefinition assembly, ProjectContentRegistry registry) : base(fullName, fileName, referencedAssemblies, registry) { foreach (ModuleDefinition module in assembly.Modules) { AddTypes(module.Types); } AddAttributes(this, this.AssemblyCompilationUnit.Attributes, assembly.CustomAttributes); InitializeSpecialClasses(); this.AssemblyCompilationUnit.Freeze(); }
public void CodeGeneratorProperties() { ProjectContentRegistry registry = new ProjectContentRegistry(); IProjectContent mscorlibProjectContent = registry.Mscorlib; IClass exceptionClass = mscorlibProjectContent.GetClass("System.Exception", 0); DefaultProjectContent projectContent = new DefaultProjectContent(); DefaultCompilationUnit unit = new DefaultCompilationUnit(projectContent); DefaultClass c = new DefaultClass(unit, "MyException"); c.BaseTypes.Add(new DefaultReturnType(exceptionClass)); MockProject project = new MockProject(); ProjectService.CurrentProject = project; OverridePropertiesCodeGenerator codeGenerator = new OverridePropertiesCodeGenerator(); codeGenerator.Initialize(c); List<string> properties = new List<string>(); foreach (object o in codeGenerator.Content) { properties.Add(o.ToString()); } List<string> expectedProperties = new List<string>(); expectedProperties.Add("Data"); expectedProperties.Add("HelpLink"); expectedProperties.Add("Message"); expectedProperties.Add("Source"); expectedProperties.Add("StackTrace"); Assert.AreEqual(expectedProperties.ToArray(), properties.ToArray()); }