Ejemplo n.º 1
0
 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);
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get help based on the target, help type, etc
        /// 
        /// Help engine retrieve help based on following schemes,
        /// 
        ///     1. if help target is empty, get default help
        ///     2. if help target is not a search pattern, try to retrieve exact help
        ///     3. if help target is a search pattern or step 2 returns no helpInfo, try to search for help
        ///        (Search for pattern in command name followed by pattern match in help content)
        ///     4. if step 3 returns exact one helpInfo object, try to retrieve exact help.
        /// 
        /// </summary>
        /// <param name="helpRequest">Help request object</param>
        /// <returns>An array of HelpInfo object</returns>
        private IEnumerable<HelpInfo> DoGetHelp(HelpRequest helpRequest)
        {
            _lastErrors.Clear();
            // Reset SearchPaths
            _searchPaths = null;

            _lastHelpCategory = helpRequest.HelpCategory;

            if (String.IsNullOrEmpty(helpRequest.Target))
            {
                HelpInfo helpInfo = GetDefaultHelp();

                if (helpInfo != null)
                {
                    yield return helpInfo;
                }

                yield return null;
            }
            else
            {
                bool isMatchFound = false;
                if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))
                {
                    foreach (HelpInfo helpInfo in ExactMatchHelp(helpRequest))
                    {
                        isMatchFound = true;
                        yield return helpInfo;
                    }
                }

                if (!isMatchFound)
                {
                    foreach (HelpInfo helpInfo in SearchHelp(helpRequest))
                    {
                        isMatchFound = true;
                        yield return helpInfo;
                    }

                    if (!isMatchFound)
                    {
                        // Throwing exception here may not be the 
                        // best thing to do. Instead we can choose to
                        //    a. give a hint
                        //    b. just silently return an empty search result.
                        // Solution: 
                        //    If it is an exact help target, throw exception.
                        //    Otherwise, return empty result set.
                        if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target) && this.LastErrors.Count == 0)
                        {
                            Exception e = new HelpNotFoundException(helpRequest.Target);
                            ErrorRecord errorRecord = new ErrorRecord(e, "HelpNotFound", ErrorCategory.ResourceUnavailable, null);
                            this.LastErrors.Add(errorRecord);
                            yield break;
                        }
                    }
                }
            }
        }