/// <summary> /// Override SearchHelp to find a class module with help matching a pattern. /// </summary> /// <param name="helpRequest">Help request.</param> /// <param name="searchOnlyContent">Not used.</param> /// <returns></returns> internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { Debug.Assert(helpRequest != null, "helpRequest cannot be null."); string target = helpRequest.Target; Collection <string> patternList = new Collection <string>(); bool decoratedSearch = !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target); if (decoratedSearch) { patternList.Add("*" + target + "*"); } else { patternList.Add(target); } foreach (string pattern in patternList) { PSClassSearcher searcher = new PSClassSearcher(pattern, useWildCards: true, _context); foreach (var helpInfo in GetHelpInfo(searcher)) { if (helpInfo != null) { yield return(helpInfo); } } } }
/// <summary> /// Override ExactMatchHelp to find the matching class module matching help request. /// </summary> /// <param name="helpRequest">Help Request for the search.</param> /// <returns>Enumerable of HelpInfo objects.</returns> internal override IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { Debug.Assert(helpRequest != null, "helpRequest cannot be null."); if ((helpRequest.HelpCategory & Automation.HelpCategory.Class) == 0) { yield return(null); } PSClassSearcher searcher = new PSClassSearcher(helpRequest.Target, useWildCards: false, _context); foreach (var helpInfo in GetHelpInfo(searcher)) { if (helpInfo != null) { yield return(helpInfo); } } }
/// <summary> /// Get the help in for the PS Class Info. /// /// </summary> /// <param name="searcher">Searcher for PS Classes.</param> /// <returns>Next HelpInfo object.</returns> private IEnumerable <HelpInfo> GetHelpInfo(PSClassSearcher searcher) { while (searcher.MoveNext()) { PSClassInfo current = ((IEnumerator <PSClassInfo>)searcher).Current; string moduleName = current.Module.Name; string moduleDir = current.Module.ModuleBase; if (!string.IsNullOrEmpty(moduleName) && !string.IsNullOrEmpty(moduleDir)) { string helpFileToFind = moduleName + "-Help.xml"; string helpFileName = null; Collection <string> searchPaths = new Collection <string>(); searchPaths.Add(moduleDir); string externalHelpFile = current.HelpFile; if (!string.IsNullOrEmpty(externalHelpFile)) { FileInfo helpFileInfo = new FileInfo(externalHelpFile); DirectoryInfo dirToSearch = helpFileInfo.Directory; if (dirToSearch.Exists) { searchPaths.Add(dirToSearch.FullName); helpFileToFind = helpFileInfo.Name; // If external help file is specified. Then use it. } } HelpInfo helpInfo = GetHelpInfoFromHelpFile(current, helpFileToFind, searchPaths, true, out helpFileName); if (helpInfo != null) { yield return(helpInfo); } } } }