/// <summary> /// Exact match help for a target. /// </summary> /// <param name="helpRequest">Help request object</param> /// <returns>The HelpInfo found. Null if nothing is found</returns> internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { string target = helpRequest.Target; if (!this.HasCustomMatch) { if (_helpCache.Contains(target)) { yield return (HelpInfo)_helpCache[target]; } } else { foreach (string key in _helpCache.Keys) { if (CustomMatch(target, key)) { yield return (HelpInfo)_helpCache[key]; } } } if (!this.CacheFullyLoaded) { DoExactMatchHelp(helpRequest); if (_helpCache.Contains(target)) { yield return (HelpInfo)_helpCache[target]; } } }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { int iteratorVariable0 = 0; string pattern = helpRequest.Target + ".help.txt"; Collection<string> iteratorVariable2 = MUIFileSearcher.SearchFiles(pattern, this.GetSearchPaths()); foreach (string iteratorVariable3 in iteratorVariable2) { if (!this._helpFiles.ContainsKey(iteratorVariable3)) { try { this.LoadHelpFile(iteratorVariable3); } catch (IOException exception) { this.ReportHelpFileError(exception, helpRequest.Target, iteratorVariable3); } catch (SecurityException exception2) { this.ReportHelpFileError(exception2, helpRequest.Target, iteratorVariable3); } } HelpInfo cache = this.GetCache(iteratorVariable3); if (cache != null) { iteratorVariable0++; yield return cache; if ((iteratorVariable0 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { break; } } } }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { string target = helpRequest.Target; if (!this.HasCustomMatch) { if (this._helpCache.Contains(target)) { yield return (HelpInfo) this._helpCache[target]; } } else { IEnumerator enumerator = this._helpCache.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string current = (string) enumerator.Current; if (this.CustomMatch(target, current)) { yield return (HelpInfo) this._helpCache[current]; } } } if (!this.CacheFullyLoaded) { this.DoExactMatchHelp(helpRequest); if (this._helpCache.Contains(target)) { yield return (HelpInfo) this._helpCache[target]; } } }
/// <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; } } }
internal sealed override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { if (!base.CacheFullyLoaded || base.AreSnapInsSupported()) { this.LoadCache(); } base.CacheFullyLoaded = true; return base.SearchHelp(helpRequest, searchOnlyContent); }
internal sealed override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { if (!base.CacheFullyLoaded || base.AreSnapInsSupported()) { this.LoadCache(); } base.CacheFullyLoaded = true; return base.ExactMatchHelp(helpRequest); }
/// <summary> /// Do exact match help based on the target. /// </summary> /// <param name="helpRequest">help request object</param> internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { Collection<ProviderInfo> matchingProviders = null; try { matchingProviders = _sessionState.Provider.Get(helpRequest.Target); } catch (ProviderNotFoundException e) { // We distinguish two cases here, // a. If the "Provider" is the only category to search for in this case, // an error will be written. // b. Otherwise, no errors will be written since in end user's mind, // he may mean to search for provider help. if (this.HelpSystem.LastHelpCategory == HelpCategory.Provider) { ErrorRecord errorRecord = new ErrorRecord(e, "ProviderLoadError", ErrorCategory.ResourceUnavailable, null); errorRecord.ErrorDetails = new ErrorDetails(typeof(ProviderHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "ProviderLoadError", helpRequest.Target, e.Message); this.HelpSystem.LastErrors.Add(errorRecord); } } if (matchingProviders != null) { foreach (ProviderInfo providerInfo in matchingProviders) { try { LoadHelpFile(providerInfo); } catch (IOException ioException) { ReportHelpFileError(ioException, helpRequest.Target, providerInfo.HelpFile); } catch (System.Security.SecurityException securityException) { ReportHelpFileError(securityException, helpRequest.Target, providerInfo.HelpFile); } catch (XmlException xmlException) { ReportHelpFileError(xmlException, helpRequest.Target, providerInfo.HelpFile); } HelpInfo helpInfo = GetCache(providerInfo.PSSnapInName + "\\" + providerInfo.Name); if (helpInfo != null) { yield return helpInfo; } } } }
/// <summary> /// Search help for a target. This function will be sealed right here /// since this is no need for children class to override this member. /// </summary> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>a collection of help info objects</returns> internal sealed override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { // If the current invocation is a singleshell based // then we have to constantly update the cache as // snapins might get added / removed. if (!this.CacheFullyLoaded || AreSnapInsSupported()) { LoadCache(); } this.CacheFullyLoaded = true; return base.SearchHelp(helpRequest, searchOnlyContent); }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { int iteratorVariable0 = 0; string target = helpRequest.Target; Hashtable iteratorVariable2 = new Hashtable(StringComparer.OrdinalIgnoreCase); CommandSearcher commandSearcherForExactMatch = this.GetCommandSearcherForExactMatch(target, this._context); Label_PostSwitchInIterator:; while (commandSearcherForExactMatch.MoveNext()) { CommandInfo current = commandSearcherForExactMatch.Current; if (SessionState.IsVisible(helpRequest.CommandOrigin, current)) { CmdletInfo cmdletInfo = current as CmdletInfo; HelpInfo helpInfo = null; string key = null; if (cmdletInfo != null) { helpInfo = this.GetHelpInfo(cmdletInfo, true); key = cmdletInfo.FullName; } else { IScriptCommandInfo scriptCommandInfo = current as IScriptCommandInfo; if (scriptCommandInfo != null) { key = current.Name; helpInfo = this.GetHelpInfo(scriptCommandInfo, true, false); } } if ((helpInfo != null) && (key != null)) { if ((helpInfo.ForwardHelpCategory == helpRequest.HelpCategory) && helpInfo.ForwardTarget.Equals(helpRequest.Target, StringComparison.OrdinalIgnoreCase)) { throw new PSInvalidOperationException(HelpErrors.CircularDependencyInHelpForwarding); } if (!iteratorVariable2.ContainsKey(key) && Match(helpInfo, helpRequest, current)) { iteratorVariable0++; iteratorVariable2.Add(key, null); yield return helpInfo; if ((iteratorVariable0 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { break; } goto Label_PostSwitchInIterator; } } } } }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { Collection<ProviderInfo> iteratorVariable0 = null; try { iteratorVariable0 = this._sessionState.Provider.Get(helpRequest.Target); } catch (ProviderNotFoundException exception) { if (this.HelpSystem.LastHelpCategory == System.Management.Automation.HelpCategory.Provider) { ErrorRecord item = new ErrorRecord(exception, "ProviderLoadError", ErrorCategory.ResourceUnavailable, null) { ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "ProviderLoadError", new object[] { helpRequest.Target, exception.Message }) }; this.HelpSystem.LastErrors.Add(item); } } if (iteratorVariable0 != null) { foreach (ProviderInfo iteratorVariable1 in iteratorVariable0) { try { this.LoadHelpFile(iteratorVariable1); } catch (IOException exception2) { this.ReportHelpFileError(exception2, helpRequest.Target, iteratorVariable1.HelpFile); } catch (SecurityException exception3) { this.ReportHelpFileError(exception3, helpRequest.Target, iteratorVariable1.HelpFile); } catch (XmlException exception4) { this.ReportHelpFileError(exception4, helpRequest.Target, iteratorVariable1.HelpFile); } HelpInfo cache = this.GetCache(iteratorVariable1.PSSnapInName + @"\" + iteratorVariable1.Name); if (cache != null) { yield return cache; } } } }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { int countHelpInfosFound = 0; string helpFileName = helpRequest.Target + ".help.txt"; Collection<string> filesMatched = MUIFileSearcher.SearchFiles(helpFileName, GetExtendedSearchPaths()); Diagnostics.Assert(filesMatched != null, "Files collection should not be null."); var matchedFilesToRemove = FilterToLatestModuleVersion(filesMatched); foreach (string file in filesMatched) { if (matchedFilesToRemove.Contains(file)) continue; // Check whether the file is already loaded if (!_helpFiles.ContainsKey(file)) { try { LoadHelpFile(file); } catch (IOException ioException) { ReportHelpFileError(ioException, helpRequest.Target, file); } catch (System.Security.SecurityException securityException) { ReportHelpFileError(securityException, helpRequest.Target, file); } } HelpInfo helpInfo = GetCache(file); if (helpInfo != null) { countHelpInfosFound++; yield return helpInfo; if ((countHelpInfosFound >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) yield break; } } }
private IEnumerable<HelpInfo> DoGetHelp(HelpRequest helpRequest) { this._lastErrors.Clear(); this._searchPaths = null; this._lastHelpCategory = helpRequest.HelpCategory; if (string.IsNullOrEmpty(helpRequest.Target)) { HelpInfo defaultHelp = this.GetDefaultHelp(); if (defaultHelp != null) { yield return defaultHelp; } yield return null; } else { bool iteratorVariable1 = false; if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) { foreach (HelpInfo iteratorVariable2 in this.ExactMatchHelp(helpRequest)) { iteratorVariable1 = true; yield return iteratorVariable2; } } if (!iteratorVariable1) { foreach (HelpInfo iteratorVariable3 in this.SearchHelp(helpRequest)) { iteratorVariable1 = true; yield return iteratorVariable3; } if ((!iteratorVariable1 && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) && (this.LastErrors.Count == 0)) { Exception exception = new HelpNotFoundException(helpRequest.Target); ErrorRecord item = new ErrorRecord(exception, "HelpNotFound", ErrorCategory.ResourceUnavailable, null); this.LastErrors.Add(item); } } } }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { CommandInfo commandInfo = null; try { commandInfo = this._commandDiscovery.LookupCommandInfo(helpRequest.Target); } catch (CommandNotFoundException) { } if ((commandInfo != null) && (commandInfo.CommandType == CommandTypes.Alias)) { AliasInfo aliasInfo = (AliasInfo) commandInfo; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(aliasInfo); if (helpInfo != null) { yield return helpInfo; goto Label_PostSwitchInIterator; } } yield break; Label_PostSwitchInIterator:; }
private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest) { if (helpRequest != null) { if ((helpRequest.HelpCategory & helpInfo.HelpCategory) == System.Management.Automation.HelpCategory.None) { return false; } if (!Match(helpInfo.Component, helpRequest.Component)) { return false; } if (!Match(helpInfo.Role, helpRequest.Role)) { return false; } if (!Match(helpInfo.Functionality, helpRequest.Functionality)) { return false; } } return true; }
internal override IEnumerable <HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest) { ProviderCommandHelpInfo providerCommandHelpInfo = new ProviderCommandHelpInfo( helpInfo, helpRequest.ProviderContext); yield return(providerCommandHelpInfo); }
internal sealed override IEnumerable<HelpInfo> DoSearchHelp(HelpRequest helpRequest) { return null; }
/// <summary> /// Do search help. This is for child class to override. /// </summary> /// <remarks> /// Child class can choose to override SearchHelp of DoSearchHelp depending on /// whether it want to reuse the logic in SearchHelp for this class. /// </remarks> /// <param name="helpRequest">help request object</param> /// <returns>a collection of help info objects</returns> internal virtual IEnumerable <HelpInfo> DoSearchHelp(HelpRequest helpRequest) { yield break; }
/// <summary> /// Search an alias help target. /// </summary> /// <remarks> /// This will, /// a. use _sessionState object to get a list of alias that match the target. /// b. for each alias, retrieve help info as in ExactMatchHelp. /// </remarks> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>a IEnumerable of helpinfo object</returns> internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { // aliases do not have help content...so doing nothing in that case if (!searchOnlyContent) { string target = helpRequest.Target; string pattern = target; Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); if (!WildcardPattern.ContainsWildcardCharacters(target)) { pattern += "*"; } WildcardPattern matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase); IDictionary<string, AliasInfo> aliasTable = _sessionState.Internal.GetAliasTable(); foreach (string name in aliasTable.Keys) { if (matcher.IsMatch(name)) { HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return helpInfo; } } } CommandSearcher searcher = new CommandSearcher( pattern, SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias, _context); while (searcher.MoveNext()) { CommandInfo current = ((IEnumerator<CommandInfo>)searcher).Current; if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return helpInfo; } } } foreach (CommandInfo current in ModuleUtils.GetMatchingCommands(pattern, _context, helpRequest.CommandOrigin)) { if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(alias); if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return helpInfo; } } } }
/// <summary> /// Exact match an alias help target. /// </summary> /// <remarks> /// This will /// a. use _commandDiscovery object to retrieve AliasInfo object. /// b. Create AliasHelpInfo object based on AliasInfo object /// </remarks> /// <param name="helpRequest">help request object</param> /// <returns>help info found</returns> internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { CommandInfo commandInfo = null; try { commandInfo = _commandDiscovery.LookupCommandInfo(helpRequest.Target); } catch (CommandNotFoundException) { // CommandNotFoundException is expected here if target doesn't match any // commandlet. Just ignore this exception and bail out. } if ((commandInfo != null) && (commandInfo.CommandType == CommandTypes.Alias)) { AliasInfo aliasInfo = (AliasInfo)commandInfo; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(aliasInfo); if (helpInfo != null) { yield return helpInfo; } } }
/// <summary> /// Do search help. This is for child class to override. /// </summary> /// <remarks> /// Child class can choose to override SearchHelp of DoSearchHelp depending on /// whether it want to reuse the logic in SearchHelp for this class. /// </remarks> /// <param name="helpRequest">help request object</param> /// <returns>a collection of help info objects</returns> internal virtual IEnumerable<HelpInfo> DoSearchHelp(HelpRequest helpRequest) { yield break; }
/// <summary> /// Retrieve help info that exactly match the target. /// </summary> /// <param name="helpRequest">help request object</param> /// <returns>List of HelpInfo objects retrieved</returns> internal abstract IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest);
/// <summary> /// Do exact match help for a target. This member is sealed right here since /// children class don't need to override this member. /// </summary> /// <param name="helpRequest">help request object</param> internal sealed override void DoExactMatchHelp(HelpRequest helpRequest) { }
internal virtual IEnumerable <HelpInfo> DoSearchHelp(HelpRequest helpRequest) { return(new HelpInfo[0]); //TODO: <DoSearchHelp>d__18(-2) { <>4__this = this }; }
internal override IEnumerable <HelpInfo> SearchHelp( HelpRequest helpRequest, bool searchOnlyContent) { using (HelpFileHelpProvider.tracer.TraceMethod()) { string target = helpRequest.Target; string pattern = target; int countOfHelpInfoObjectsFound = 0; WildcardPattern wildCardPattern = (WildcardPattern)null; if (!searchOnlyContent && !WildcardPattern.ContainsWildcardCharacters(target)) { pattern = "*" + pattern + "*"; } if (searchOnlyContent) { string pattern1 = helpRequest.Target; if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) { pattern1 = "*" + pattern1 + "*"; } wildCardPattern = new WildcardPattern(pattern1, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); pattern = "*"; } // ISSUE: reference to a compiler-generated field this.\u003Cpattern\u003E5__e += ".help.txt"; Collection <string> files = MUIFileSearcher.SearchFiles(pattern, this.GetSearchPaths()); if (files != null) { foreach (string str in files) { if (!this._helpFiles.ContainsKey((object)str)) { try { this.LoadHelpFile(str); } catch (IOException ex) { this.ReportHelpFileError((Exception)ex, helpRequest.Target, str); } catch (SecurityException ex) { this.ReportHelpFileError((Exception)ex, helpRequest.Target, str); } } HelpFileHelpInfo helpInfo = this.GetCache(str) as HelpFileHelpInfo; if (helpInfo != null && (!searchOnlyContent || helpInfo.MatchPatternInContent(wildCardPattern))) { ++countOfHelpInfoObjectsFound; yield return((HelpInfo)helpInfo); if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) { break; } } } } } }
private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest) => helpRequest == null || (helpRequest.HelpCategory & helpInfo.HelpCategory) != HelpCategory.None && AliasHelpProvider.Match(helpInfo.Component, helpRequest.Component) && (AliasHelpProvider.Match(helpInfo.Role, helpRequest.Role) && AliasHelpProvider.Match(helpInfo.Functionality, helpRequest.Functionality));
internal override sealed void DoExactMatchHelp(HelpRequest helpRequest) { using (HelpProviderWithFullCache.tracer.TraceMethod()) ; }
/// <summary> /// Process a helpinfo forwarded over by another help provider. /// /// HelpProvider can choose to process the helpInfo or not, /// /// 1. If a HelpProvider chooses not to process the helpInfo, it can return null to indicate /// helpInfo is not processed. /// 2. If a HelpProvider indeed processes the helpInfo, it should create a new helpInfo /// object instead of modifying the passed-in helpInfo object. This is very important /// since the helpInfo object passed in is usually stored in cache, which can /// used in later queries. /// </summary> /// <param name="helpInfo">helpInfo passed over by another HelpProvider</param> /// <param name="helpRequest">help request object</param> /// <returns></returns> internal virtual IEnumerable <HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest) { // Win8: 508648. Remove the current provides category for resolving forward help as the current // help provider already process it. helpInfo.ForwardHelpCategory = helpInfo.ForwardHelpCategory ^ this.HelpCategory; yield return(helpInfo); }
/// <summary> /// Search help info that match the target search pattern. /// </summary> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>a collection of help info objects</returns> internal abstract IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent);
/// <summary> /// Do exact match help for a target. /// </summary> /// <remarks> /// Derived class can choose to either override ExactMatchHelp method to DoExactMatchHelp method. /// If ExactMatchHelp is overridden, initial cache checking will be disabled by default. /// If DoExactMatchHelp is overridden, cache check will be done first in ExactMatchHelp before the /// logic in DoExactMatchHelp is in place. /// </remarks> /// <param name="helpRequest">help request object</param> internal virtual void DoExactMatchHelp(HelpRequest helpRequest) { }
internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { string target = helpRequest.Target; string pattern = target; int countOfHelpInfoObjectsFound = 0; // this will be used only when searchOnlyContent == true WildcardPattern wildCardPattern = null; if ((!searchOnlyContent) && (!WildcardPattern.ContainsWildcardCharacters(target))) { // Search all the about conceptual topics. This pattern // makes about topics discoverable without actually // using the word "about_" as in "get-help while". pattern = "*" + pattern + "*"; } if (searchOnlyContent) { string searchTarget = helpRequest.Target; if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) { searchTarget = "*" + searchTarget + "*"; } wildCardPattern = WildcardPattern.Get(searchTarget, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); // search all about_* topics pattern = "*"; } pattern += ".help.txt"; Collection<String> files = MUIFileSearcher.SearchFiles(pattern, GetExtendedSearchPaths()); var matchedFilesToRemove = FilterToLatestModuleVersion(files); if (files == null) yield break; foreach (string file in files) { if (matchedFilesToRemove.Contains(file)) continue; // Check whether the file is already loaded if (!_helpFiles.ContainsKey(file)) { try { LoadHelpFile(file); } catch (IOException ioException) { ReportHelpFileError(ioException, helpRequest.Target, file); } catch (System.Security.SecurityException securityException) { ReportHelpFileError(securityException, helpRequest.Target, file); } } HelpFileHelpInfo helpInfo = GetCache(file) as HelpFileHelpInfo; if (helpInfo != null) { if (searchOnlyContent) { if (!helpInfo.MatchPatternInContent(wildCardPattern)) { continue; } } countOfHelpInfoObjectsFound++; yield return helpInfo; if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) yield break; } } }
/// <summary> /// Search help for a target /// </summary> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>a collection of help info objects</returns> internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { string target = helpRequest.Target; string wildcardpattern = GetWildCardPattern(target); HelpRequest searchHelpRequest = helpRequest.Clone(); searchHelpRequest.Target = wildcardpattern; if (!this.CacheFullyLoaded) { IEnumerable<HelpInfo> result = DoSearchHelp(searchHelpRequest); if (null != result) { foreach (HelpInfo helpInfoToReturn in result) { yield return helpInfoToReturn; } } } else { int countOfHelpInfoObjectsFound = 0; WildcardPattern helpMatchter = WildcardPattern.Get(wildcardpattern, WildcardOptions.IgnoreCase); foreach (string key in _helpCache.Keys) { if ((!searchOnlyContent && helpMatchter.IsMatch(key)) || (searchOnlyContent && ((HelpInfo)_helpCache[key]).MatchPatternInContent(helpMatchter))) { countOfHelpInfoObjectsFound++; yield return (HelpInfo)_helpCache[key]; if (helpRequest.MaxResults > 0 && countOfHelpInfoObjectsFound >= helpRequest.MaxResults) { yield break; } } } } }
internal virtual IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest) { helpInfo.ForwardHelpCategory ^= this.HelpCategory; yield return helpInfo; }
/// <summary> /// Search help info that match the target search pattern. /// </summary> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns>a collection of help info objects</returns> internal abstract IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent);
internal override sealed IEnumerable <HelpInfo> DoSearchHelp( HelpRequest helpRequest) { using (HelpProviderWithFullCache.tracer.TraceMethod()) return((IEnumerable <HelpInfo>)null); }
internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { HelpRequest request = helpRequest.Clone(); request.Target = "default"; return base.ExactMatchHelp(request); }
internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { int iteratorVariable0 = 0; string pattern = helpRequest.Target; string name = pattern; WildcardPattern iteratorVariable3 = null; bool iteratorVariable4 = !WildcardPattern.ContainsWildcardCharacters(pattern); if (!searchOnlyContent) { if (iteratorVariable4) { name = name + "*"; } } else { string target = helpRequest.Target; if (iteratorVariable4) { target = "*" + helpRequest.Target + "*"; } iteratorVariable3 = new WildcardPattern(target, WildcardOptions.IgnoreCase | WildcardOptions.Compiled); name = "*"; } PSSnapinQualifiedName instance = PSSnapinQualifiedName.GetInstance(name); if (instance != null) { foreach (ProviderInfo iteratorVariable6 in this._sessionState.Provider.GetAll()) { if (!iteratorVariable6.IsMatch(name)) { continue; } try { this.LoadHelpFile(iteratorVariable6); } catch (IOException exception) { if (!iteratorVariable4) { this.ReportHelpFileError(exception, iteratorVariable6.Name, iteratorVariable6.HelpFile); } } catch (SecurityException exception2) { if (!iteratorVariable4) { this.ReportHelpFileError(exception2, iteratorVariable6.Name, iteratorVariable6.HelpFile); } } catch (XmlException exception3) { if (!iteratorVariable4) { this.ReportHelpFileError(exception3, iteratorVariable6.Name, iteratorVariable6.HelpFile); } } HelpInfo cache = this.GetCache(iteratorVariable6.PSSnapInName + @"\" + iteratorVariable6.Name); if ((cache != null) && (!searchOnlyContent || cache.MatchPatternInContent(iteratorVariable3))) { iteratorVariable0++; yield return(cache); if ((iteratorVariable0 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { break; } } } } }
protected override void ProcessRecord() { try { if (this.ShowWindow != 0) { this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper"); } base.Context.HelpSystem.OnProgress += new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress); bool failed = false; HelpCategory cat = this.ToHelpCategory(this._category, ref failed); if (!failed) { this.ValidateAndThrowIfError(cat); HelpRequest helpRequest = new HelpRequest(this.Name, cat) { Provider = this._provider, Component = this._component, Role = this._role, Functionality = this._functionality, ProviderContext = new ProviderContext(this.Path, base.Context.Engine.Context, base.SessionState.Path), CommandOrigin = base.MyInvocation.CommandOrigin }; IEnumerable<HelpInfo> help = base.Context.HelpSystem.GetHelp(helpRequest); HelpInfo helpInfo = null; int num = 0; foreach (HelpInfo info2 in help) { if (base.IsStopping) { return; } if (num == 0) { helpInfo = info2; } else { if (helpInfo != null) { this.WriteObjectsOrShowOnlineHelp(helpInfo, false); helpInfo = null; } this.WriteObjectsOrShowOnlineHelp(info2, false); } num++; } if (1 == num) { this.WriteObjectsOrShowOnlineHelp(helpInfo, true); } else if (this.showOnlineHelp && (num > 1)) { throw PSTraceSource.NewInvalidOperationException("HelpErrors", "MultipleOnlineTopicsNotSupported", new object[] { "Online" }); } if ((((num == 0) && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) || base.Context.HelpSystem.VerboseHelpErrors) && (base.Context.HelpSystem.LastErrors.Count > 0)) { foreach (ErrorRecord record in base.Context.HelpSystem.LastErrors) { base.WriteError(record); } } } } finally { base.Context.HelpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress); base.Context.HelpSystem.ClearScriptBlockTokenCache(); } }
/// <summary> /// Search an alias help target. /// </summary> /// <remarks> /// This will, /// a. use _sessionState object to get a list of alias that match the target. /// b. for each alias, retrive help info as in ExactMatchHelp. /// </remarks> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, seraches for pattern in the command names. /// </param> /// <returns>a IEnumerable of helpinfo object</returns> internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { // aliases do not have help content...so doing nothing in that case if (!searchOnlyContent) { string target = helpRequest.Target; string pattern = target; Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); if (!WildcardPattern.ContainsWildcardCharacters(target)) { pattern += "*"; } WildcardPattern matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase); IDictionary <string, AliasInfo> aliasTable = _sessionState.Internal.GetAliasTable(); foreach (string name in aliasTable.Keys) { if (matcher.IsMatch(name)) { HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } CommandSearcher searcher = new CommandSearcher( pattern, SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias, _context); while (searcher.MoveNext()) { CommandInfo current = ((IEnumerator <CommandInfo>)searcher).Current; if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpRequest exactMatchHelpRequest = helpRequest.Clone(); exactMatchHelpRequest.Target = name; // Duplicates?? foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest)) { // Component/Role/Functionality match is done only for SearchHelp // as "get-help * -category alias" should not forwad help to // CommandHelpProvider..(ExactMatchHelp does forward help to // CommandHelpProvider) if (!Match(helpInfo, helpRequest)) { continue; } if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } foreach (CommandInfo current in ModuleUtils.GetMatchingCommands(pattern, _context, helpRequest.CommandOrigin)) { if (_context.CurrentPipelineStopping) { yield break; } AliasInfo alias = current as AliasInfo; if (alias != null) { string name = alias.Name; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(alias); if (hashtable.ContainsKey(name)) { continue; } hashtable.Add(name, null); yield return(helpInfo); } } } }
private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest) { if (helpRequest == null) return true; if (0 == (helpRequest.HelpCategory & helpInfo.HelpCategory)) { return false; } if (!Match(helpInfo.Component, helpRequest.Component)) { return false; } if (!Match(helpInfo.Role, helpRequest.Role)) { return false; } if (!Match(helpInfo.Functionality, helpRequest.Functionality)) { return false; } return true; }
/// <summary> /// Get help that exactly match the target /// </summary> /// <param name="helpRequest">help request object</param> /// <returns>An IEnumerable of HelpInfo object</returns> private IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest) { int countOfHelpInfosFound = 0; bool searchInHelpContent = false; bool shouldBreak = false; HelpProgressInfo progress = new HelpProgressInfo(); progress.Activity = StringUtil.Format(HelpDisplayStrings.SearchingForHelpContent, helpRequest.Target); progress.Completed = false; progress.PercentComplete = 0; try { OnProgress(this, progress); // algorithm: // 1. Search for pattern (helpRequest.Target) in command name // 2. If Step 1 fails then search for pattern in help content do { // we should not continue the search loop if we are // searching in the help content (as this is the last step // in our search algorithm). if (searchInHelpContent) { shouldBreak = true; } for (int i = 0; i < this.HelpProviders.Count; i++) { HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i]; if ((helpProvider.HelpCategory & helpRequest.HelpCategory) > 0) { foreach (HelpInfo helpInfo in helpProvider.SearchHelp(helpRequest, searchInHelpContent)) { if (_executionContext.CurrentPipelineStopping) { yield break; } countOfHelpInfosFound++; yield return(helpInfo); if ((countOfHelpInfosFound >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { yield break; } } } } // no need to do help content search once we have some help topics // with command name search. if (countOfHelpInfosFound > 0) { yield break; } // appears that we did not find any help matching command names..look for // pattern in help content. searchInHelpContent = true; if (this.HelpProviders.Count > 0) { progress.PercentComplete += (100 / this.HelpProviders.Count); OnProgress(this, progress); } } while (!shouldBreak); } finally { progress.Completed = true; progress.PercentComplete = 100; OnProgress(this, progress); } }
internal sealed override void DoExactMatchHelp(HelpRequest helpRequest) { }
/// <summary> /// Search for provider help based on a search target. /// </summary> /// <param name="helpRequest">help request object</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns></returns> internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { int countOfHelpInfoObjectsFound = 0; string target = helpRequest.Target; string pattern = target; // this will be used only when searchOnlyContent == true WildcardPattern wildCardPattern = null; bool decoratedSearch = !WildcardPattern.ContainsWildcardCharacters(target); if (!searchOnlyContent) { if (decoratedSearch) { pattern += "*"; } } else { string searchTarget = helpRequest.Target; if (decoratedSearch) { searchTarget = "*" + helpRequest.Target + "*"; } wildCardPattern = WildcardPattern.Get(searchTarget, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); // search in all providers pattern = "*"; } PSSnapinQualifiedName snapinQualifiedNameForPattern = PSSnapinQualifiedName.GetInstance(pattern); if (null == snapinQualifiedNameForPattern) { yield break; } foreach (ProviderInfo providerInfo in _sessionState.Provider.GetAll()) { if (providerInfo.IsMatch(pattern)) { try { LoadHelpFile(providerInfo); } catch (IOException ioException) { if (!decoratedSearch) { ReportHelpFileError(ioException, providerInfo.Name, providerInfo.HelpFile); } } catch (System.Security.SecurityException securityException) { if (!decoratedSearch) { ReportHelpFileError(securityException, providerInfo.Name, providerInfo.HelpFile); } } catch (XmlException xmlException) { if (!decoratedSearch) { ReportHelpFileError(xmlException, providerInfo.Name, providerInfo.HelpFile); } } HelpInfo helpInfo = GetCache(providerInfo.PSSnapInName + "\\" + providerInfo.Name); if (helpInfo != null) { if (searchOnlyContent) { // ignore help objects that do not have pattern in its help // content. if (!helpInfo.MatchPatternInContent(wildCardPattern)) { continue; } } countOfHelpInfoObjectsFound++; yield return(helpInfo); if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) { yield break; } } } } }
/// <summary> /// Do search help. This function will be sealed right here /// since this is no need for children class to override this member. /// </summary> /// <param name="helpRequest">help request object</param> /// <returns>a collection of help info objects</returns> internal sealed override IEnumerable <HelpInfo> DoSearchHelp(HelpRequest helpRequest) { return(null); }
/// <summary> /// Do exact match help for a target. /// </summary> /// <remarks> /// Derived class can choose to either override ExactMatchHelp method to DoExactMatchHelp method. /// If ExactMatchHelp is overridden, initial cache checking will be disabled by default. /// If DoExactMatchHelp is overridden, cache check will be done first in ExactMatchHelp before the /// logic in DoExactMatchHelp is in place. /// </remarks> /// <param name="helpRequest">help request object</param> internal virtual void DoExactMatchHelp(HelpRequest helpRequest) { }
/// <summary> /// Retrieve help info that exactly match the target. /// </summary> /// <param name="helpRequest">help request object</param> /// <returns>List of HelpInfo objects retrieved</returns> internal abstract IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest);
internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { string target = helpRequest.Target; string pattern = target; int countOfHelpInfoObjectsFound = 0; // this will be used only when searchOnlyContent == true WildcardPattern wildCardPattern = null; if ((!searchOnlyContent) && (!WildcardPattern.ContainsWildcardCharacters(target))) { // Search all the about conceptual topics. This pattern // makes about topics discoverable without actually // using the word "about_" as in "get-help while". pattern = "*" + pattern + "*"; } if (searchOnlyContent) { string searchTarget = helpRequest.Target; if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) { searchTarget = "*" + searchTarget + "*"; } wildCardPattern = WildcardPattern.Get(searchTarget, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); // search all about_* topics pattern = "*"; } pattern += ".help.txt"; Collection <String> files = MUIFileSearcher.SearchFiles(pattern, GetExtendedSearchPaths()); var matchedFilesToRemove = FilterToLatestModuleVersion(files); if (files == null) { yield break; } foreach (string file in files) { if (matchedFilesToRemove.Contains(file)) { continue; } // Check whether the file is already loaded if (!_helpFiles.ContainsKey(file)) { try { LoadHelpFile(file); } catch (IOException ioException) { ReportHelpFileError(ioException, helpRequest.Target, file); } catch (System.Security.SecurityException securityException) { ReportHelpFileError(securityException, helpRequest.Target, file); } } HelpFileHelpInfo helpInfo = GetCache(file) as HelpFileHelpInfo; if (helpInfo != null) { if (searchOnlyContent) { if (!helpInfo.MatchPatternInContent(wildCardPattern)) { continue; } } countOfHelpInfoObjectsFound++; yield return(helpInfo); if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) { yield break; } } } }
/// <summary> /// Process a helpinfo forwarded over by another help provider. /// /// HelpProvider can choose to process the helpInfo or not, /// /// 1. If a HelpProvider chooses not to process the helpInfo, it can return null to indicate /// helpInfo is not processed. /// 2. If a HelpProvider indeed processes the helpInfo, it should create a new helpInfo /// object instead of modifying the passed-in helpInfo object. This is very important /// since the helpInfo object passed in is usually stored in cache, which can /// used in later queries. /// </summary> /// <param name="helpInfo">helpInfo passed over by another HelpProvider</param> /// <param name="helpRequest">help request object</param> /// <returns></returns> internal virtual IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest) { // Win8: 508648. Remove the current provides category for resolving forward help as the current // help provider already process it. helpInfo.ForwardHelpCategory = helpInfo.ForwardHelpCategory ^ this.HelpCategory; yield return helpInfo; }
internal IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { bool iteratorVariable0 = false; for (int i = 0; i < this.HelpProviders.Count; i++) { HelpProvider iteratorVariable2 = (HelpProvider) this.HelpProviders[i]; if ((iteratorVariable2.HelpCategory & helpRequest.HelpCategory) > HelpCategory.None) { foreach (HelpInfo iteratorVariable3 in iteratorVariable2.ExactMatchHelp(helpRequest)) { iteratorVariable0 = true; foreach (HelpInfo iteratorVariable4 in this.ForwardHelp(iteratorVariable3, helpRequest)) { yield return iteratorVariable4; } } } if (iteratorVariable0 && !(iteratorVariable2 is ScriptCommandHelpProvider)) { break; } } }
internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { string pattern = helpRequest.Target; string iteratorVariable1 = pattern; int iteratorVariable2 = 0; WildcardPattern iteratorVariable3 = null; if (!searchOnlyContent && !WildcardPattern.ContainsWildcardCharacters(pattern)) { iteratorVariable1 = "*" + iteratorVariable1 + "*"; } if (searchOnlyContent) { string target = helpRequest.Target; if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) { target = "*" + target + "*"; } iteratorVariable3 = new WildcardPattern(target, WildcardOptions.IgnoreCase | WildcardOptions.Compiled); iteratorVariable1 = "*"; } iteratorVariable1 = iteratorVariable1 + ".help.txt"; Collection<string> iteratorVariable4 = MUIFileSearcher.SearchFiles(iteratorVariable1, this.GetSearchPaths()); if (iteratorVariable4 != null) { foreach (string iteratorVariable5 in iteratorVariable4) { if (!this._helpFiles.ContainsKey(iteratorVariable5)) { try { this.LoadHelpFile(iteratorVariable5); } catch (IOException exception) { this.ReportHelpFileError(exception, helpRequest.Target, iteratorVariable5); } catch (SecurityException exception2) { this.ReportHelpFileError(exception2, helpRequest.Target, iteratorVariable5); } } HelpFileHelpInfo cache = this.GetCache(iteratorVariable5) as HelpFileHelpInfo; if ((cache != null) && (!searchOnlyContent || cache.MatchPatternInContent(iteratorVariable3))) { iteratorVariable2++; yield return cache; if ((iteratorVariable2 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0)) { break; } } } } }
internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { if (!searchOnlyContent) { string target = helpRequest.Target; string pattern = target; Hashtable iteratorVariable2 = new Hashtable(StringComparer.OrdinalIgnoreCase); if (!WildcardPattern.ContainsWildcardCharacters(target)) { pattern = pattern + "*"; } WildcardPattern iteratorVariable3 = new WildcardPattern(pattern, WildcardOptions.IgnoreCase); IDictionary <string, AliasInfo> aliasTable = this._sessionState.Internal.GetAliasTable(); foreach (string iteratorVariable5 in aliasTable.Keys) { if (iteratorVariable3.IsMatch(iteratorVariable5)) { HelpRequest iteratorVariable6 = helpRequest.Clone(); iteratorVariable6.Target = iteratorVariable5; foreach (HelpInfo iteratorVariable7 in this.ExactMatchHelp(iteratorVariable6)) { if (!Match(iteratorVariable7, helpRequest) || iteratorVariable2.ContainsKey(iteratorVariable5)) { continue; } iteratorVariable2.Add(iteratorVariable5, null); yield return(iteratorVariable7); } } } CommandSearcher iteratorVariable8 = new CommandSearcher(pattern, SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias, this._context); while (iteratorVariable8.MoveNext()) { CommandInfo current = iteratorVariable8.Current; if (this._context.CurrentPipelineStopping) { goto Label_0423; } AliasInfo iteratorVariable10 = current as AliasInfo; if (iteratorVariable10 != null) { string name = iteratorVariable10.Name; HelpRequest iteratorVariable12 = helpRequest.Clone(); iteratorVariable12.Target = name; foreach (HelpInfo iteratorVariable13 in this.ExactMatchHelp(iteratorVariable12)) { if (!Match(iteratorVariable13, helpRequest) || iteratorVariable2.ContainsKey(name)) { continue; } iteratorVariable2.Add(name, null); yield return(iteratorVariable13); } } } foreach (CommandInfo iteratorVariable14 in ModuleUtils.GetMatchingCommands(pattern, this._context, helpRequest.CommandOrigin, false)) { if (this._context.CurrentPipelineStopping) { break; } AliasInfo aliasInfo = iteratorVariable14 as AliasInfo; if (aliasInfo != null) { string key = aliasInfo.Name; HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(aliasInfo); if (!iteratorVariable2.ContainsKey(key)) { iteratorVariable2.Add(key, null); yield return(helpInfo); } } } } Label_0423: yield break; }