Пример #1
0
        public bool MoveNext()
        {
            bool flag1 = false;

            this._currentMatch = (CommandInfo)null;
            if (this.currentState == CommandSearcher.SearchState.Reset)
            {
                this._currentMatch = this.ProcessResetState();
                if (this._currentMatch != null && SessionState.IsVisible(this._commandOrigin, this._currentMatch))
                {
                    flag1 = true;
                    goto label_48;
                }
                else
                {
                    this.currentState = CommandSearcher.SearchState.AliasResolution;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.AliasResolution)
            {
                this._currentMatch = this.ProcessAliasState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                    goto label_48;
                }
                else
                {
                    this.currentState = CommandSearcher.SearchState.FunctionResolution;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.FunctionResolution)
            {
                this._currentMatch = this.ProcessFunctionState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                    goto label_48;
                }
                else
                {
                    this.currentState = CommandSearcher.SearchState.CmdletResolution;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.CmdletResolution)
            {
                this._currentMatch = this.ProcessCmdletState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                    goto label_48;
                }
                else
                {
                    this.currentState = CommandSearcher.SearchState.BuiltinScriptResolution;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.BuiltinScriptResolution)
            {
                if ((this.commandTypes & (CommandTypes.ExternalScript | CommandTypes.Application)) == (CommandTypes)0)
                {
                    flag1 = false;
                    goto label_48;
                }
                else
                {
                    if (this._commandOrigin == CommandOrigin.Runspace && this.commandName.IndexOfAny(this._pathSeparators) >= 0)
                    {
                        bool flag2 = false;
                        if (this._context.EngineSessionState.Applications.Count == 1 && this._context.EngineSessionState.Applications[0].Equals("*", StringComparison.OrdinalIgnoreCase) || this._context.EngineSessionState.Scripts.Count == 1 && this._context.EngineSessionState.Scripts[0].Equals("*", StringComparison.OrdinalIgnoreCase))
                        {
                            flag2 = true;
                        }
                        else
                        {
                            foreach (string application in this._context.EngineSessionState.Applications)
                            {
                                if (this.checkPath(application, this.commandName))
                                {
                                    flag2 = true;
                                    break;
                                }
                            }
                            if (!flag2)
                            {
                                foreach (string script in this._context.EngineSessionState.Scripts)
                                {
                                    if (this.checkPath(script, this.commandName))
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!flag2)
                        {
                            flag1 = false;
                            goto label_48;
                        }
                    }
                    this.currentState  = CommandSearcher.SearchState.PowerShellPathResolution;
                    this._currentMatch = this.ProcessBuiltinScriptState();
                    if (this._currentMatch != null)
                    {
                        this.currentState = CommandSearcher.SearchState.QualifiedFileSystemPath;
                        flag1             = true;
                        goto label_48;
                    }
                }
            }
            if (this.currentState == CommandSearcher.SearchState.PowerShellPathResolution)
            {
                this.currentState  = CommandSearcher.SearchState.QualifiedFileSystemPath;
                this._currentMatch = this.ProcessPathResolutionState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                    goto label_48;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.QualifiedFileSystemPath || this.currentState == CommandSearcher.SearchState.PathSearch)
            {
                this._currentMatch = this.ProcessQualifiedFileSystemState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                    goto label_48;
                }
            }
            if (this.currentState == CommandSearcher.SearchState.PathSearch)
            {
                this.currentState  = CommandSearcher.SearchState.PowerShellRelativePath;
                this._currentMatch = this.ProcessPathSearchState();
                if (this._currentMatch != null)
                {
                    flag1 = true;
                }
            }
label_48:
            return(flag1);
        }
Пример #2
0
        internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
        {
            string item = helpRequest.Target;
            Collection <string> iteratorVariable1 = new Collection <string>();
            WildcardPattern     pattern           = null;
            bool iteratorVariable3 = !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target);

            if (!searchOnlyContent)
            {
                if (iteratorVariable3)
                {
                    if (item.IndexOf('-') >= 0)
                    {
                        iteratorVariable1.Add(item + "*");
                    }
                    else
                    {
                        iteratorVariable1.Add("*" + item + "*");
                    }
                }
                else
                {
                    iteratorVariable1.Add(item);
                }
            }
            else
            {
                iteratorVariable1.Add("*");
                string target = helpRequest.Target;
                if (iteratorVariable3)
                {
                    target = "*" + helpRequest.Target + "*";
                }
                pattern = new WildcardPattern(target, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
            }
            int       iteratorVariable4 = 0;
            Hashtable iteratorVariable5 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Hashtable iteratorVariable6 = new Hashtable(StringComparer.OrdinalIgnoreCase);

            foreach (string iteratorVariable7 in iteratorVariable1)
            {
                CommandSearcher commandSearcherForSearch = this.GetCommandSearcherForSearch(iteratorVariable7, this._context);
                while (commandSearcherForSearch.MoveNext())
                {
                    if (this._context.CurrentPipelineStopping)
                    {
                        break;
                    }
                    CommandInfo current    = commandSearcherForSearch.Current;
                    CmdletInfo  cmdletInfo = current as CmdletInfo;
                    HelpInfo    helpInfo   = null;
                    string      key        = null;
                    if (cmdletInfo != null)
                    {
                        helpInfo = this.GetHelpInfo(cmdletInfo, !iteratorVariable3);
                        key      = cmdletInfo.FullName;
                    }
                    else
                    {
                        IScriptCommandInfo scriptCommandInfo = current as IScriptCommandInfo;
                        if (scriptCommandInfo != null)
                        {
                            key      = current.Name;
                            helpInfo = this.GetHelpInfo(scriptCommandInfo, !iteratorVariable3, searchOnlyContent);
                        }
                    }
                    if (helpInfo != null)
                    {
                        if (!SessionState.IsVisible(helpRequest.CommandOrigin, current))
                        {
                            if (!iteratorVariable6.ContainsKey(key))
                            {
                                iteratorVariable6.Add(key, null);
                            }
                        }
                        else if ((!iteratorVariable5.ContainsKey(key) && Match(helpInfo, helpRequest, current)) && (!searchOnlyContent || helpInfo.MatchPatternInContent(pattern)))
                        {
                            iteratorVariable5.Add(key, null);
                            iteratorVariable4++;
                            yield return(helpInfo);

                            if ((iteratorVariable4 < helpRequest.MaxResults) || (helpRequest.MaxResults <= 0))
                            {
                                continue;
                            }
                            break;
                        }
                    }
                }
                if (this.HelpCategory == (System.Management.Automation.HelpCategory.Cmdlet | System.Management.Automation.HelpCategory.Alias))
                {
                    foreach (CommandInfo iteratorVariable13 in ModuleUtils.GetMatchingCommands(iteratorVariable7, this._context, helpRequest.CommandOrigin, false))
                    {
                        if (this._context.CurrentPipelineStopping)
                        {
                            break;
                        }
                        if (SessionState.IsVisible(helpRequest.CommandOrigin, iteratorVariable13))
                        {
                            CmdletInfo iteratorVariable14 = iteratorVariable13 as CmdletInfo;
                            HelpInfo   iteratorVariable15 = null;
                            string     fullName           = null;
                            if (iteratorVariable14 != null)
                            {
                                iteratorVariable15 = this.GetHelpInfo(iteratorVariable14, !iteratorVariable3);
                                fullName           = iteratorVariable14.FullName;
                            }
                            else
                            {
                                IScriptCommandInfo info2 = iteratorVariable13 as IScriptCommandInfo;
                                if (info2 != null)
                                {
                                    fullName           = iteratorVariable13.Name;
                                    iteratorVariable15 = this.GetHelpInfo(info2, !iteratorVariable3, searchOnlyContent);
                                }
                            }
                            if ((((iteratorVariable15 != null) && !iteratorVariable5.ContainsKey(fullName)) && (!iteratorVariable6.ContainsKey(fullName) && Match(iteratorVariable15, helpRequest, iteratorVariable13))) && (!searchOnlyContent || iteratorVariable15.MatchPatternInContent(pattern)))
                            {
                                iteratorVariable5.Add(fullName, null);
                                iteratorVariable4++;
                                yield return(iteratorVariable15);

                                if ((iteratorVariable4 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0))
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
 public bool MoveNext()
 {
     this._currentMatch = null;
     if (this.currentState == SearchState.SearchingAliases)
     {
         this._currentMatch = this.SearchForAliases();
         if ((this._currentMatch != null) && SessionState.IsVisible(this._commandOrigin, this._currentMatch))
         {
             return(true);
         }
         this._currentMatch = null;
         this.currentState  = SearchState.SearchingFunctions;
     }
     if (this.currentState == SearchState.SearchingFunctions)
     {
         this._currentMatch = this.SearchForFunctions();
         if (this._currentMatch != null)
         {
             return(true);
         }
         this.currentState = SearchState.SearchingCmdlets;
     }
     if (this.currentState == SearchState.SearchingCmdlets)
     {
         this._currentMatch = this.SearchForCmdlets();
         if (this._currentMatch != null)
         {
             return(true);
         }
         this.currentState = SearchState.SearchingBuiltinScripts;
     }
     if (this.currentState == SearchState.SearchingBuiltinScripts)
     {
         this._currentMatch = this.SearchForBuiltinScripts();
         if (this._currentMatch != null)
         {
             return(true);
         }
         this.currentState = SearchState.StartSearchingForExternalCommands;
     }
     if (this.currentState == SearchState.StartSearchingForExternalCommands)
     {
         if ((this.commandTypes & (CommandTypes.Application | CommandTypes.ExternalScript)) == 0)
         {
             return(false);
         }
         if ((this._commandOrigin == System.Management.Automation.CommandOrigin.Runspace) && (this.commandName.IndexOfAny(_pathSeparators) >= 0))
         {
             bool flag = false;
             if (((this._context.EngineSessionState.Applications.Count == 1) && this._context.EngineSessionState.Applications[0].Equals("*", StringComparison.OrdinalIgnoreCase)) || ((this._context.EngineSessionState.Scripts.Count == 1) && this._context.EngineSessionState.Scripts[0].Equals("*", StringComparison.OrdinalIgnoreCase)))
             {
                 flag = true;
             }
             else
             {
                 foreach (string str in this._context.EngineSessionState.Applications)
                 {
                     if (checkPath(str, this.commandName))
                     {
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     foreach (string str2 in this._context.EngineSessionState.Scripts)
                     {
                         if (checkPath(str2, this.commandName))
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
             }
             if (!flag)
             {
                 return(false);
             }
         }
         this.currentState  = SearchState.PowerShellPathResolution;
         this._currentMatch = this.ProcessBuiltinScriptState();
         if (this._currentMatch != null)
         {
             this.currentState = SearchState.QualifiedFileSystemPath;
             return(true);
         }
     }
     if (this.currentState == SearchState.PowerShellPathResolution)
     {
         this.currentState  = SearchState.QualifiedFileSystemPath;
         this._currentMatch = this.ProcessPathResolutionState();
         if (this._currentMatch != null)
         {
             return(true);
         }
     }
     if ((this.currentState == SearchState.QualifiedFileSystemPath) || (this.currentState == SearchState.PathSearch))
     {
         this._currentMatch = this.ProcessQualifiedFileSystemState();
         if (this._currentMatch != null)
         {
             return(true);
         }
     }
     if (this.currentState == SearchState.PathSearch)
     {
         this.currentState  = SearchState.PowerShellRelativePath;
         this._currentMatch = this.ProcessPathSearchState();
         if (this._currentMatch != null)
         {
             return(true);
         }
     }
     return(false);
 }