/// <summary> /// Load the namespace information from the reflection information /// </summary> /// <param name="reflectionFile">The reflection information filename</param> private void LoadNamespaces(string reflectionFile) { XPathDocument reflectionInfo; XPathNavigator navDoc, navNamespace, navLibrary; List <string> assemblies; string nsName, asmName; namespaceInfo = new Dictionary <string, List <string> >(); try { this.Cursor = Cursors.WaitCursor; lblProgress.Text = "Loading namespace information..."; Application.DoEvents(); reflectionInfo = new XPathDocument(reflectionFile); navDoc = reflectionInfo.CreateNavigator(); // Namespace nodes don't contain assembly info so we'll have to look at all types and add all // unique namespaces from their container info. foreach (XPathNavigator container in navDoc.Select( "reflection/apis/api[starts-with(@id, 'T:')]/containers")) { navNamespace = container.SelectSingleNode("namespace"); navLibrary = container.SelectSingleNode("library"); if (navNamespace != null && navLibrary != null) { nsName = navNamespace.GetAttribute("api", String.Empty).Substring(2); asmName = navLibrary.GetAttribute("assembly", String.Empty); if (namespaceInfo.TryGetValue(nsName, out assemblies)) { if (!assemblies.Contains(asmName)) { assemblies.Add(asmName); } } else { assemblies = new List <string>(); assemblies.Add(asmName); namespaceInfo.Add(nsName, assemblies); } } Application.DoEvents(); } // The global namespace (N:) isn't always listed but we'll add it as it does show up in the // reflection info anyway. if (!namespaceInfo.ContainsKey(String.Empty)) { namespaceInfo.Add(String.Empty, new List <string>()); } // Add new namespaces to the list as temporary items. They will get added to the project if // modified. foreach (string ns in namespaceInfo.Keys) { nsName = (ns.Length == 0) ? "(global)" : ns; if (!namespaceItems.ContainsKey(nsName)) { namespaceItems.Add(ns, nsColl.CreateTemporaryItem(ns, false)); } // Sort the assemblies for each namespace assemblies = namespaceInfo[ns]; assemblies.Sort(); } // Add namespace group info, if present. These are an abstract concept and aren't part of any // assemblies. foreach (XPathNavigator nsGroup in navDoc.Select("reflection/apis/api[starts-with(@id, 'G:') and " + "not(topicdata/@group='rootGroup')]/apidata")) { nsName = nsGroup.GetAttribute("name", String.Empty); nsName = nsName + NamespaceComparer.GroupSuffix; namespaceInfo.Add(nsName, new List <String>()); if (!namespaceItems.ContainsKey(nsName)) { namespaceItems.Add(nsName, nsColl.CreateTemporaryItem(nsName, true)); } } Application.DoEvents(); // Add all unique assembly names to the assembly combo box assemblies = new List <string>(); foreach (List <string> asmList in namespaceInfo.Values) { foreach (string asm in asmList) { if (!assemblies.Contains(asm)) { assemblies.Add(asm); } } } assemblies.Sort(); assemblies.Insert(0, "<All>"); cboAssembly.DataSource = assemblies; btnApplyFilter_Click(this, EventArgs.Empty); } finally { this.Cursor = Cursors.Default; } }
/// <summary> /// Load the namespace information from the reflection information /// </summary> /// <param name="reflectionFile">The reflection information filename</param> private void LoadNamespaces(string reflectionFile) { XPathDocument reflectionInfo; XPathNavigator navDoc, navNamespace, navLibrary; List <string> assemblies; string nsName, asmName; namespaceInfo = new Dictionary <string, List <string> >(); reflectionInfo = new XPathDocument(reflectionFile); navDoc = reflectionInfo.CreateNavigator(); // Namespace nodes don't contain assembly info so we'll have to look at all types and add all // unique namespaces from their container info. foreach (XPathNavigator container in navDoc.Select("reflection/apis/api[starts-with(@id, 'T:')]/containers")) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); navNamespace = container.SelectSingleNode("namespace"); navLibrary = container.SelectSingleNode("library"); if (navNamespace != null && navLibrary != null) { nsName = navNamespace.GetAttribute("api", String.Empty).Substring(2); asmName = navLibrary.GetAttribute("assembly", String.Empty); if (namespaceInfo.TryGetValue(nsName, out assemblies)) { if (!assemblies.Contains(asmName)) { assemblies.Add(asmName); } } else { namespaceInfo.Add(nsName, new List <string>() { asmName }); } } } // The global namespace (N:) isn't always listed but we'll add it as it does show up in the // reflection info anyway. if (!namespaceInfo.ContainsKey(String.Empty)) { namespaceInfo.Add(String.Empty, new List <string>()); } // Add new namespaces to the list as temporary items. They will get added to the project if // modified. foreach (string ns in namespaceInfo.Keys) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); nsName = (ns.Length == 0) ? "(global)" : ns; if (!namespaceItems.ContainsKey(nsName)) { namespaceItems.Add(nsName, nsColl.CreateTemporaryItem(ns, false)); } namespaceInfo[ns].Sort(); } // Add namespace group info, if present. These are an abstract concept and aren't part of any // assemblies. foreach (XPathNavigator nsGroup in navDoc.Select("reflection/apis/api[starts-with(@id, 'G:') and " + "not(topicdata/@group='rootGroup')]/apidata")) { cancellationTokenSource.Token.ThrowIfCancellationRequested(); nsName = nsGroup.GetAttribute("name", String.Empty); nsName = nsName + NamespaceComparer.GroupSuffix; namespaceInfo.Add(nsName, new List <String>()); if (!namespaceItems.ContainsKey(nsName)) { namespaceItems.Add(nsName, nsColl.CreateTemporaryItem(nsName, true)); } } }