internal static CmdletInfo GetCmdlet(string commandName, System.Management.Automation.ExecutionContext context) { CmdletInfo current = null; CommandSearcher searcher = new CommandSearcher(commandName, SearchResolutionOptions.None, CommandTypes.Cmdlet, context); Label_000C: try { if (!searcher.MoveNext()) { return current; } } catch (ArgumentException) { goto Label_000C; } catch (PathTooLongException) { goto Label_000C; } catch (FileLoadException) { goto Label_000C; } catch (MetadataException) { goto Label_000C; } catch (FormatException) { goto Label_000C; } current = ((IEnumerator) searcher).Current as CmdletInfo; goto Label_000C; }
public List <CmdletInfo> GetCmdlets(string pattern) { if (pattern == null) { throw PSTraceSource.NewArgumentNullException(nameof(pattern)); } List <CmdletInfo> cmdlets = new List <CmdletInfo>(); CmdletInfo current = null; CommandSearcher searcher = new CommandSearcher( pattern, SearchResolutionOptions.CommandNameIsPattern, CommandTypes.Cmdlet, _context); while (true) { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } current = ((IEnumerator)searcher).Current as CmdletInfo; if (current != null) { cmdlets.Add(current); } } return(cmdlets); }
internal IEnumerable <CommandInfo> GetCommands(string name, CommandTypes commandTypes, SearchResolutionOptions options, CommandOrigin?commandOrigin = null) { CommandSearcher searcher = new CommandSearcher( name, options, commandTypes, _context); if (commandOrigin != null) { searcher.CommandOrigin = commandOrigin.Value; } while (true) { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } CommandInfo commandInfo = ((IEnumerator)searcher).Current as CommandInfo; if (commandInfo != null) { yield return(commandInfo); } } }
internal static CmdletInfo GetCmdlet(string commandName, ExecutionContext context) { CmdletInfo current = null; CommandSearcher searcher = new CommandSearcher( commandName, SearchResolutionOptions.None, CommandTypes.Cmdlet, context); while (true) { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } current = ((IEnumerator)searcher).Current as CmdletInfo; } return(current); }
private static CommandInfo TryNormalSearch(string commandName, ExecutionContext context, CommandOrigin commandOrigin, SearchResolutionOptions searchResolutionOptions, CommandTypes commandTypes, ref Exception lastError) { CommandInfo current = null; CommandSearcher searcher = new CommandSearcher(commandName, searchResolutionOptions, commandTypes, context) { CommandOrigin = commandOrigin }; try { if (!searcher.MoveNext()) { if (!commandName.Contains("-") && !commandName.Contains(@"\")) { discoveryTracer.WriteLine("The command [{0}] was not found, trying again with get- prepended", new object[] { commandName }); commandName = "get" + '-' + commandName; try { current = LookupCommandInfo(commandName, commandTypes, searchResolutionOptions, commandOrigin, context); } catch (CommandNotFoundException) { } } return current; } current = searcher.Current; } catch (ArgumentException exception) { lastError = exception; } catch (PathTooLongException exception2) { lastError = exception2; } catch (FileLoadException exception3) { lastError = exception3; } catch (FormatException exception4) { lastError = exception4; } catch (MetadataException exception5) { lastError = exception5; } return current; }
/// <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; } } } }
public IEnumerable<CommandInfo> GetCommands(string name, CommandTypes commandTypes, bool nameIsPattern) { if (name == null) { throw PSTraceSource.NewArgumentNullException("name"); } CommandSearcher iteratorVariable0 = new CommandSearcher(name, nameIsPattern ? (SearchResolutionOptions.CommandNameIsPattern | SearchResolutionOptions.ResolveFunctionPatterns | SearchResolutionOptions.ResolveAliasPatterns) : SearchResolutionOptions.None, commandTypes, this._context); Label_0066: try { if (!iteratorVariable0.MoveNext()) { goto Label_00C2; } } catch (ArgumentException) { goto Label_0066; } catch (PathTooLongException) { goto Label_0066; } catch (FileLoadException) { goto Label_0066; } catch (MetadataException) { goto Label_0066; } catch (FormatException) { goto Label_0066; } CommandInfo current = ((IEnumerator) iteratorVariable0).Current as CommandInfo; if (current != null) { yield return current; } goto Label_0066; Label_00C2:; }
public List<CmdletInfo> GetCmdlets(string pattern) { if (pattern == null) { throw PSTraceSource.NewArgumentNullException("pattern"); } List<CmdletInfo> list = new List<CmdletInfo>(); CmdletInfo item = null; CommandSearcher searcher = new CommandSearcher(pattern, SearchResolutionOptions.CommandNameIsPattern, CommandTypes.Cmdlet, this._context); Label_0025: try { if (!searcher.MoveNext()) { return list; } } catch (ArgumentException) { goto Label_0025; } catch (PathTooLongException) { goto Label_0025; } catch (FileLoadException) { goto Label_0025; } catch (MetadataException) { goto Label_0025; } catch (FormatException) { goto Label_0025; } item = ((IEnumerator) searcher).Current as CmdletInfo; if (item != null) { list.Add(item); } goto Label_0025; }
internal IEnumerable<CommandInfo> GetCommands(string name, CommandTypes commandTypes, SearchResolutionOptions options, CommandOrigin? commandOrigin = null) { CommandSearcher searcher = new CommandSearcher( name, options, commandTypes, _context); if (commandOrigin != null) { searcher.CommandOrigin = commandOrigin.Value; } do { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } CommandInfo commandInfo = ((IEnumerator)searcher).Current as CommandInfo; if (commandInfo != null) { yield return commandInfo; } } while (true); }
/// <summary> /// Returns all cmdlets whose names match the pattern... /// </summary> /// <returns>A list of CmdletInfo objects...</returns> public List<CmdletInfo> GetCmdlets(string pattern) { if (pattern == null) throw PSTraceSource.NewArgumentNullException("pattern"); List<CmdletInfo> cmdlets = new List<CmdletInfo>(); CmdletInfo current = null; CommandSearcher searcher = new CommandSearcher( pattern, SearchResolutionOptions.CommandNameIsPattern, CommandTypes.Cmdlet, _context); do { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } current = ((IEnumerator)searcher).Current as CmdletInfo; if (current != null) cmdlets.Add(current); } while (true); return cmdlets; }
/// <summary> /// Returns the CmdletInfo object that corresponds to the name argument /// </summary> /// <param name="commandName">The name of the cmdlet to look for</param> /// <param name="context">The execution context instance to use for lookup</param> /// <returns>The cmdletInfo object if found, null otherwise</returns> internal static CmdletInfo GetCmdlet(string commandName, ExecutionContext context) { CmdletInfo current = null; CommandSearcher searcher = new CommandSearcher( commandName, SearchResolutionOptions.None, CommandTypes.Cmdlet, context); do { try { if (!searcher.MoveNext()) { break; } } catch (ArgumentException) { continue; } catch (PathTooLongException) { continue; } catch (FileLoadException) { continue; } catch (MetadataException) { continue; } catch (FormatException) { continue; } current = ((IEnumerator)searcher).Current as CmdletInfo; } while (true); return current; }
private bool FindCommandForName(SearchResolutionOptions options, string commandName, bool isPattern, bool emitErrors, ref int currentCount) { CommandSearcher searcher = new CommandSearcher(commandName, options, this.CommandType, base.Context); bool flag = false; Label_0016: try { if (!searcher.MoveNext()) { goto Label_016F; } } catch (ArgumentException exception) { if (emitErrors) { base.WriteError(new ErrorRecord(exception, "GetCommandInvalidArgument", ErrorCategory.SyntaxError, null)); } goto Label_0016; } catch (PathTooLongException exception2) { if (emitErrors) { base.WriteError(new ErrorRecord(exception2, "GetCommandInvalidArgument", ErrorCategory.SyntaxError, null)); } goto Label_0016; } catch (FileLoadException exception3) { if (emitErrors) { base.WriteError(new ErrorRecord(exception3, "GetCommandFileLoadError", ErrorCategory.ReadError, null)); } goto Label_0016; } catch (MetadataException exception4) { if (emitErrors) { base.WriteError(new ErrorRecord(exception4, "GetCommandMetadataError", ErrorCategory.MetadataError, null)); } goto Label_0016; } catch (FormatException exception5) { if (emitErrors) { base.WriteError(new ErrorRecord(exception5, "GetCommandBadFileFormat", ErrorCategory.InvalidData, null)); } goto Label_0016; } CommandInfo current = searcher.Current; if ((!SessionState.IsVisible(base.MyInvocation.CommandOrigin, current) || !this.IsCommandMatch(ref current)) || this.IsCommandInResult(current)) { goto Label_0016; } flag = true; if (this.IsParameterMatch(current)) { currentCount++; if ((this.TotalCount >= 0) && (currentCount > this.TotalCount)) { goto Label_016F; } this.accumulatedResults.Add(current); if (this.ArgumentList != null) { goto Label_016F; } } if (((isPattern || (this.All != false)) || ((this.totalCount != -1) || this.isCommandTypeSpecified)) || this.isModuleSpecified) { goto Label_0016; } Label_016F: if (this.All != false) { foreach (CommandInfo info2 in this.GetMatchingCommandsFromModules(commandName)) { CommandInfo info3 = info2; if (this.IsCommandMatch(ref info3)) { flag = true; if (!this.IsCommandInResult(info2) && this.IsParameterMatch(info3)) { currentCount++; if ((this.TotalCount >= 0) && (currentCount > this.TotalCount)) { return(flag); } this.accumulatedResults.Add(info3); } } } } return(flag); }
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; }