Ejemplo n.º 1
0
 internal override IEnumerable <HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     System.Management.Automation.HelpCategory iteratorVariable0 = System.Management.Automation.HelpCategory.Workflow | System.Management.Automation.HelpCategory.ExternalScript | System.Management.Automation.HelpCategory.Filter | System.Management.Automation.HelpCategory.Function | System.Management.Automation.HelpCategory.ScriptCommand | System.Management.Automation.HelpCategory.Alias;
     if ((helpInfo.HelpCategory & iteratorVariable0) != System.Management.Automation.HelpCategory.None)
     {
         HelpRequest iteratorVariable1 = helpRequest.Clone();
         iteratorVariable1.Target        = helpInfo.ForwardTarget;
         iteratorVariable1.CommandOrigin = CommandOrigin.Internal;
         if ((helpInfo.ForwardHelpCategory != System.Management.Automation.HelpCategory.None) && (helpInfo.HelpCategory != System.Management.Automation.HelpCategory.Alias))
         {
             iteratorVariable1.HelpCategory = helpInfo.ForwardHelpCategory;
         }
         else
         {
             try
             {
                 CommandInfo commandInfo = this._context.CommandDiscovery.LookupCommandInfo(iteratorVariable1.Target);
                 iteratorVariable1.HelpCategory = commandInfo.HelpCategory;
             }
             catch (CommandNotFoundException)
             {
             }
         }
         IEnumerator <HelpInfo> enumerator = this.ExactMatchHelp(iteratorVariable1).GetEnumerator();
         while (enumerator.MoveNext())
         {
             HelpInfo current = enumerator.Current;
             yield return(current);
         }
     }
     else
     {
         yield return(helpInfo);
     }
 }
Ejemplo n.º 2
0
 internal override IEnumerable <HelpInfo> SearchHelp(
     HelpRequest helpRequest,
     bool searchOnlyContent)
 {
     using (AliasHelpProvider.tracer.TraceMethod())
     {
         if (!searchOnlyContent)
         {
             string target  = helpRequest.Target;
             string pattern = target;
             if (!WildcardPattern.ContainsWildcardCharacters(target))
             {
                 // ISSUE: reference to a compiler-generated field
                 this.\u003Cpattern\u003E5__a += "*";
             }
             WildcardPattern matcher = new WildcardPattern(pattern, WildcardOptions.IgnoreCase);
             IDictionary <string, AliasInfo> aliasTable = this._sessionState.Internal.GetAliasTable();
             foreach (string key in (IEnumerable <string>)aliasTable.Keys)
             {
                 if (matcher.IsMatch(key))
                 {
                     HelpRequest exactMatchHelpRequest = helpRequest.Clone();
                     exactMatchHelpRequest.Target = key;
                     foreach (HelpInfo helpInfo in this.ExactMatchHelp(exactMatchHelpRequest))
                     {
                         if (AliasHelpProvider.Match(helpInfo, helpRequest))
                         {
                             yield return(helpInfo);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="helpRequest">help request object</param>
        /// <returns></returns>
        internal override IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest)
        {
            HelpRequest defaultHelpRequest = helpRequest.Clone();

            defaultHelpRequest.Target = "default";
            return(base.ExactMatchHelp(defaultHelpRequest));
        }
Ejemplo n.º 4
0
 internal override IEnumerable <HelpInfo> ExactMatchHelp(
     HelpRequest helpRequest)
 {
     using (DefaultHelpProvider.tracer.TraceMethod())
     {
         HelpRequest helpRequest1 = helpRequest.Clone();
         helpRequest1.Target = "default";
         return(base.ExactMatchHelp(helpRequest1));
     }
 }
        /// <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 (result != null)
                {
                    foreach (HelpInfo helpInfoToReturn in result)
                    {
                        yield return(helpInfoToReturn);
                    }
                }
            }
            else
            {
                int             countOfHelpInfoObjectsFound = 0;
                WildcardPattern helpMatcher = WildcardPattern.Get(wildcardpattern, WildcardOptions.IgnoreCase);
                foreach (string key in _helpCache.Keys)
                {
                    if ((!searchOnlyContent && helpMatcher.IsMatch(key)) ||
                        (searchOnlyContent && ((HelpInfo)_helpCache[key]).MatchPatternInContent(helpMatcher)))
                    {
                        countOfHelpInfoObjectsFound++;
                        yield return((HelpInfo)_helpCache[key]);

                        if (helpRequest.MaxResults > 0 && countOfHelpInfoObjectsFound >= helpRequest.MaxResults)
                        {
                            yield break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Process a helpInfo forwarded from other providers (normally commandHelpProvider)
        /// </summary>
        /// <remarks>
        /// For command help info, this will
        ///     1. check whether provider-specific commandlet help exists.
        ///     2. merge found provider-specific help with commandlet help provided.
        /// </remarks>
        /// <param name="helpInfo">helpInfo forwarded in</param>
        /// <param name="helpRequest">help request object</param>
        /// <returns>The help info object after processing</returns>
        override internal HelpInfo ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            if (helpInfo == null)
            {
                return(null);
            }

            if (helpInfo.HelpCategory != HelpCategory.Command)
            {
                return(helpInfo);
            }

            string providerName = helpRequest.Provider;

            if (String.IsNullOrEmpty(providerName))
            {
                providerName = this._sessionState.Path.CurrentLocation.Provider.Name;
            }

            HelpRequest providerHelpRequest = helpRequest.Clone();

            providerHelpRequest.Target = providerName;

            ProviderHelpInfo providerHelpInfo = (ProviderHelpInfo)this.ExactMatchHelp(providerHelpRequest);

            if (providerHelpInfo == null)
            {
                return(null);
            }

            CommandHelpInfo commandHelpInfo = (CommandHelpInfo)helpInfo;

            CommandHelpInfo result = commandHelpInfo.MergeProviderSpecificHelp(providerHelpInfo.GetCmdletHelp(commandHelpInfo.Name), providerHelpInfo.GetDynamicParameterHelp(helpRequest.DynamicParameters));

            // Reset ForwardHelpCategory for the helpinfo to be returned so that it will not be forwarded back again.
            result.ForwardHelpCategory = HelpCategory.None;

            return(result);
        }
Ejemplo n.º 7
0
        internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
        {
            string      target            = helpRequest.Target;
            string      wildCardPattern   = this.GetWildCardPattern(target);
            HelpRequest iteratorVariable2 = helpRequest.Clone();

            iteratorVariable2.Target = wildCardPattern;
            if (!this.CacheFullyLoaded)
            {
                IEnumerable <HelpInfo> iteratorVariable3 = this.DoSearchHelp(iteratorVariable2);
                if (iteratorVariable3 != null)
                {
                    foreach (HelpInfo iteratorVariable4 in iteratorVariable3)
                    {
                        yield return(iteratorVariable4);
                    }
                }
            }
            else
            {
                int             iteratorVariable5 = 0;
                WildcardPattern pattern           = new WildcardPattern(wildCardPattern, WildcardOptions.IgnoreCase);
                IEnumerator     enumerator        = this._helpCache.Keys.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string current = (string)enumerator.Current;
                    if ((!searchOnlyContent && pattern.IsMatch(current)) || (searchOnlyContent && ((HelpInfo)this._helpCache[current]).MatchPatternInContent(pattern)))
                    {
                        iteratorVariable5++;
                        yield return((HelpInfo)this._helpCache[current]);

                        if ((helpRequest.MaxResults > 0) && (iteratorVariable5 >= helpRequest.MaxResults))
                        {
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <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;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
 internal override IEnumerable<HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
 {
     string target = helpRequest.Target;
     string wildCardPattern = this.GetWildCardPattern(target);
     HelpRequest iteratorVariable2 = helpRequest.Clone();
     iteratorVariable2.Target = wildCardPattern;
     if (!this.CacheFullyLoaded)
     {
         IEnumerable<HelpInfo> iteratorVariable3 = this.DoSearchHelp(iteratorVariable2);
         if (iteratorVariable3 != null)
         {
             foreach (HelpInfo iteratorVariable4 in iteratorVariable3)
             {
                 yield return iteratorVariable4;
             }
         }
     }
     else
     {
         int iteratorVariable5 = 0;
         WildcardPattern pattern = new WildcardPattern(wildCardPattern, WildcardOptions.IgnoreCase);
         IEnumerator enumerator = this._helpCache.Keys.GetEnumerator();
         while (enumerator.MoveNext())
         {
             string current = (string) enumerator.Current;
             if ((!searchOnlyContent && pattern.IsMatch(current)) || (searchOnlyContent && ((HelpInfo) this._helpCache[current]).MatchPatternInContent(pattern)))
             {
                 iteratorVariable5++;
                 yield return (HelpInfo) this._helpCache[current];
                 if ((helpRequest.MaxResults > 0) && (iteratorVariable5 >= helpRequest.MaxResults))
                 {
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="helpRequest">help request object</param>
 /// <returns></returns>
 internal override IEnumerable<HelpInfo> ExactMatchHelp(HelpRequest helpRequest)
 {
     HelpRequest defaultHelpRequest = helpRequest.Clone();
     defaultHelpRequest.Target = "default";
     return base.ExactMatchHelp(defaultHelpRequest);
 }
Ejemplo n.º 13
0
 internal override IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     System.Management.Automation.HelpCategory iteratorVariable0 = System.Management.Automation.HelpCategory.Workflow | System.Management.Automation.HelpCategory.ExternalScript | System.Management.Automation.HelpCategory.Filter | System.Management.Automation.HelpCategory.Function | System.Management.Automation.HelpCategory.ScriptCommand | System.Management.Automation.HelpCategory.Alias;
     if ((helpInfo.HelpCategory & iteratorVariable0) != System.Management.Automation.HelpCategory.None)
     {
         HelpRequest iteratorVariable1 = helpRequest.Clone();
         iteratorVariable1.Target = helpInfo.ForwardTarget;
         iteratorVariable1.CommandOrigin = CommandOrigin.Internal;
         if ((helpInfo.ForwardHelpCategory != System.Management.Automation.HelpCategory.None) && (helpInfo.HelpCategory != System.Management.Automation.HelpCategory.Alias))
         {
             iteratorVariable1.HelpCategory = helpInfo.ForwardHelpCategory;
         }
         else
         {
             try
             {
                 CommandInfo commandInfo = this._context.CommandDiscovery.LookupCommandInfo(iteratorVariable1.Target);
                 iteratorVariable1.HelpCategory = commandInfo.HelpCategory;
             }
             catch (CommandNotFoundException)
             {
             }
         }
         IEnumerator<HelpInfo> enumerator = this.ExactMatchHelp(iteratorVariable1).GetEnumerator();
         while (enumerator.MoveNext())
         {
             HelpInfo current = enumerator.Current;
             yield return current;
         }
     }
     else
     {
         yield return helpInfo;
     }
 }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Process a helpInfo forwarded from other providers (normally commandHelpProvider)
        /// </summary>
        /// <remarks>
        /// For command help info, this will 
        ///     1. check whether provider-specific commandlet help exists.
        ///     2. merge found provider-specific help with commandlet help provided.
        /// </remarks>
        /// <param name="helpInfo">helpInfo forwarded in</param>
        /// <param name="helpRequest">help request object</param>        
        /// <returns>The help info object after processing</returns>
        override internal HelpInfo ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            if (helpInfo == null)
                return null;

            if (helpInfo.HelpCategory != HelpCategory.Command)
            {
                return helpInfo;
            }

            string providerName = helpRequest.Provider;
            if (String.IsNullOrEmpty(providerName))
            {
                providerName = this._sessionState.Path.CurrentLocation.Provider.Name;
            }

            HelpRequest providerHelpRequest = helpRequest.Clone();
            providerHelpRequest.Target = providerName;

            ProviderHelpInfo providerHelpInfo = (ProviderHelpInfo)this.ExactMatchHelp(providerHelpRequest);

            if (providerHelpInfo == null)
                return null;

            CommandHelpInfo commandHelpInfo = (CommandHelpInfo)helpInfo;

            CommandHelpInfo result = commandHelpInfo.MergeProviderSpecificHelp(providerHelpInfo.GetCmdletHelp(commandHelpInfo.Name), providerHelpInfo.GetDynamicParameterHelp(helpRequest.DynamicParameters));

            // Reset ForwardHelpCategory for the helpinfo to be returned so that it will not be forwarded back again.
            result.ForwardHelpCategory = HelpCategory.None;

            return result;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Process helpInfo forwarded over from other other providers, specificly AliasHelpProvider.
        /// This can return more than 1 helpinfo object.
        /// </summary>
        /// <param name="helpInfo">HelpInfo that is forwarded over</param>
        /// <param name="helpRequest">Help request object</param>        
        /// <returns>The result helpInfo objects after processing</returns>
        internal override IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            HelpCategory categoriesHandled = (HelpCategory.Alias
                | HelpCategory.ExternalScript | HelpCategory.Filter | HelpCategory.Function | HelpCategory.ScriptCommand | HelpCategory.Workflow);

            if ((helpInfo.HelpCategory & categoriesHandled) != 0)
            {
                HelpRequest commandHelpRequest = helpRequest.Clone();
                commandHelpRequest.Target = helpInfo.ForwardTarget;
                commandHelpRequest.CommandOrigin = CommandOrigin.Internal; // a public command can forward help to a private command

                // We may know what category to forward to.  If so, just set it.  If not, look up the
                // command and determine it's category.  For aliases, we definitely don't know the category
                // to forward to, so always do the lookup.
                if (helpInfo.ForwardHelpCategory != HelpCategory.None && helpInfo.HelpCategory != HelpCategory.Alias)
                {
                    commandHelpRequest.HelpCategory = helpInfo.ForwardHelpCategory;
                }
                else
                {
                    try
                    {
                        CommandInfo targetCommand = _context.CommandDiscovery.LookupCommandInfo(commandHelpRequest.Target);
                        commandHelpRequest.HelpCategory = targetCommand.HelpCategory;
                    }
                    catch (CommandNotFoundException)
                    {
                        // ignore errors for aliases pointing to non-existant commands
                    }
                }

                foreach (HelpInfo helpInfoToReturn in ExactMatchHelp(commandHelpRequest))
                {
                    yield return helpInfoToReturn;
                }
            }
            else
            {
                // command help provider can forward process only an AliasHelpInfo..
                // so returning the original help info here.
                yield return helpInfo;
            }
        }
Ejemplo n.º 17
0
        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;
        }