private void AddNamespacesFromFile(string path) { path = "@" + path; Assembly assembly = CodeAssistTools.LoadAssembly(path); if (assembly == null) { return; } try { foreach (Type type in assembly.GetTypes()) { if (!type.IsPublic) { continue; } string ns = type.Namespace; if (String.IsNullOrEmpty(ns)) { continue; } ReferenceNamespace item = FindListBoxItem(ns); if (item == null) { item = new ReferenceNamespace(ns); _checkedListBox.Items.Add(item, true); } item.AddAssembly(path); } } catch { // Ignore unloadable assemblies } }
public override void Save() { /* * Save the registry settings. */ if (!_disableColorization) { _settingsManager.ColorizeTypes = _colorizeTypesCheckBox.Checked; _settingsManager.ColorizeVariables = _colorizeVariablesCheckBox.Checked; _settingsManager.ColorizeOnActivate = _colorizeOnActivateCheckBox.Checked; _settingsManager.ColorizeOnLookup = _colorizeOnLookupCheckBox.Checked; _settingsManager.Save(); } /* * Write the reference database if it has been updated. */ if (_activeNamespaces == null || _inactiveNamespaces == null) { return; } /* * Sanitize the lists first. */ /* * Make sure we don't have any namespaces without assemblies. * (Not sure if that could happen but better safe than sorry.) */ Dictionary <string, ReferenceNamespace> cleanActiveNamespaces = new Dictionary <string, ReferenceNamespace>(); foreach (string key in _activeNamespaces.Keys) { if (_activeNamespaces[key].AssemblyList.Count > 0) { cleanActiveNamespaces[key] = _activeNamespaces[key]; } } /* * Check for any empty namespaces and also dump any '@' * referenced assemblies so they don't build up. */ ReferenceDatabase cleanInactiveNamespaces = new ReferenceDatabase(); foreach (string key in _inactiveNamespaces.Keys) { ReferenceNamespace ns = new ReferenceNamespace(key); foreach (string s in _inactiveNamespaces[key].AssemblyList) { if (!s.StartsWith("@")) { ns.AddAssembly(s); } } if (ns.AssemblyList.Count > 0) { cleanInactiveNamespaces[ns.Name] = ns; } } /* * Write the data to the database file. */ string path = _referenceManager.ReferenceDatabasePath; StreamWriter sw = null; try { sw = new StreamWriter(path); foreach (string key in cleanActiveNamespaces.Keys) { sw.WriteLine("+" + key); foreach (string assmembly in cleanActiveNamespaces[key].AssemblyList) { sw.WriteLine(assmembly); } } foreach (string key in cleanInactiveNamespaces.Keys) { sw.WriteLine("-" + key); foreach (string assmembly in cleanInactiveNamespaces[key].AssemblyList) { sw.WriteLine(assmembly); } } } catch (Exception ex) { MessageBox.Show(String.Format("{0}:\r\n{1}", Resources.CreateDbErrorMessage, ex.Message), Resources.CreateDbErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sw != null) { sw.Close(); } } /* * Reread the database. */ ReferenceManager.GetInstance().LoadReferenceDatabaseFromFile(); }
/* * Populate the database property with the namespaces * from the Global Assembly Cache. */ private void CreateReferenceDatabase() { List <string> assemblyList = new List <string>(); string gac = Path.Combine( Environment.SystemDirectory, @"..\assembly\GAC"); string gac32 = Path.Combine( Environment.SystemDirectory, @"..\assembly\GAC_32"); string gac64 = Path.Combine( Environment.SystemDirectory, @"..\assembly\GAC_64"); string gacMSIL = Path.Combine( Environment.SystemDirectory, @"..\assembly\GAC_MSIL"); assemblyList.AddRange(GetGACAssemblies(gac)); assemblyList.AddRange(GetGACAssemblies(gac32)); assemblyList.AddRange(GetGACAssemblies(gac64)); assemblyList.AddRange(GetGACAssemblies(gacMSIL)); _referenceDatabase = new ReferenceDatabase(); _progressBar.Maximum = assemblyList.Count; _progressBar.Step = 1; foreach (string name in assemblyList) { _progressBar.PerformStep(); Assembly assembly = CodeAssistTools.LoadAssembly(name); if (assembly == null) { continue; } try { foreach (Type type in assembly.GetTypes()) { if (!type.IsPublic) { continue; } string ns = type.Namespace; if (String.IsNullOrEmpty(ns)) { continue; } if (!_referenceDatabase.ContainsKey(ns)) { _referenceDatabase[ns] = new ReferenceNamespace(ns); } _referenceDatabase[ns].AddAssembly(name); } } catch { // Ignore unloadable assemblies } Refresh(); } }
internal void LoadReferenceDatabaseFromFile() { if (!File.Exists(_referenceDatabasePath)) { return; } ActiveNamespaces = new ReferenceDatabase(); InactiveNamespaces = new ReferenceDatabase(); StreamReader sr = null; try { sr = new StreamReader(_referenceDatabasePath); string line = null; string ns = null; bool readingActive = true; while ((line = sr.ReadLine()) != null) { if (line == String.Empty) { continue; } if (line[0] == '+') { ns = line.Substring(1); readingActive = true; ActiveNamespaces[ns] = new ReferenceNamespace(ns); } else if (line[0] == '-') { ns = line.Substring(1); readingActive = false; InactiveNamespaces[ns] = new ReferenceNamespace(ns); } else { if (readingActive) { ActiveNamespaces[ns].AddAssembly(line); } else { InactiveNamespaces[ns].AddAssembly(line); } } } } catch (Exception ex) { MessageBox.Show(String.Format("{0}:\r\n{1}", Resources.ReadDbErrorMessage, ex.Message), Resources.ReadDbErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sr != null) { sr.Close(); } } /* * Update the namespace lists (will be * empty if file read fails). */ _fullNamespaceList.Clear(); _rootNamespaceList.Clear(); foreach (string ns in ActiveNamespaces.Keys) { _fullNamespaceList.Add(ns); string[] split = ns.Split('.'); if (String.IsNullOrEmpty(split[0])) { continue; } if (!_rootNamespaceList.Contains(split[0])) { _rootNamespaceList.Add(split[0]); } } }