/// <summary> /// Scan for new namespaces when loaded /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void NamespacesDlg_Activated(object sender, EventArgs e) { NamespaceSummaryItemCollection nsColl = project.NamespaceSummaries; Collection <string> asmNS, namespaces = new Collection <string>(); AssemblyLoader loader = null; string path = null; // Only load them once and not at design time if (namespacesLoaded || this.DesignMode) { return; } try { this.Cursor = Cursors.WaitCursor; Application.DoEvents(); namespacesLoaded = true; try { // Make sure we start in the project's folder so that // relative paths are resolved correctly. Directory.SetCurrentDirectory(Path.GetDirectoryName( project.Filename)); loader = AssemblyLoader.CreateAssemblyLoader(project); // Get a list of all unique namespaces in the // documentation assemblies. foreach (DocumentAssembly da in project.Assemblies) { if (da.CommentsOnly) { continue; } try { path = da.AssemblyPath; asmNS = loader.GetNamespaces(path); foreach (string ns in asmNS) { if (!namespaces.Contains(ns)) { namespaces.Add(ns); } } } catch (FileNotFoundException ex) { System.Diagnostics.Debug.WriteLine(ex); if (MessageBox.Show("Unable to find the assembly '" + path + "' or one of its dependencies. You " + "may need to build it or add a dependency " + "to the project dependency list. Do you " + "want to continue loading the remaining " + "assemblies?", Constants.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No) { break; } } } } finally { if (loader != null) { AssemblyLoader.ReleaseAssemblyLoader(); } } // The global namespace (N:) isn't always listed but we'll // add it as it does show up in the reflection info anyway. if (!namespaces.Contains(String.Empty)) { namespaces.Add(String.Empty); } // Add new namespaces to the list foreach (string ns in namespaces) { if (!nsColl.Contains(ns)) { nsColl.Add(new NamespaceSummaryItem(ns)); } } nsColl.Sort(); // Load the listbox with the namespace items foreach (NamespaceSummaryItem nsi in nsColl) { lbNamespaces.Items.Add(nsi, nsi.IsDocumented); } if (lbNamespaces.Items.Count == 0) { btnDelete.Enabled = txtSummary.Enabled = false; } else { lbNamespaces.SelectedIndex = 0; } } finally { this.Cursor = Cursors.Default; } }