Esempio n. 1
0
        /// <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;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <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);

            bool useWildCards = true;

            foreach (string pattern in patternList)
            {
                PSClassSearcher searcher = new PSClassSearcher(pattern, useWildCards, _context);

                foreach (var helpInfo in GetHelpInfo(searcher))
                {
                    if (helpInfo != null)
                        yield return helpInfo;
                }
            }
        }
Esempio n. 3
0
        /// <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;
            }

            string target = helpRequest.Target;
            bool useWildCards = false;

            PSClassSearcher searcher = new PSClassSearcher(target, useWildCards, _context);

            foreach (var helpInfo in GetHelpInfo(searcher))
            {
                if (helpInfo != null)
                {
                    yield return helpInfo;
                }
            }
        }