/// <summary> /// Forward help to the help provider with type forwardHelpCategory. /// /// This is used in the following known scenarios so far /// 1. Alias: helpInfo returned by Alias is not what end user needed. /// The real help can be retrieved from Command help provider. /// </summary> /// <param name="helpInfo"></param> /// <param name="helpRequest">Help request object.</param> /// <returns>Never returns null.</returns> /// <remarks>helpInfos is not null or empty.</remarks> private IEnumerable <HelpInfo> ForwardHelp(HelpInfo helpInfo, HelpRequest helpRequest) { Collection <HelpInfo> result = new Collection <HelpInfo>(); // findout if this helpInfo needs to be processed further.. if (helpInfo.ForwardHelpCategory == HelpCategory.None && string.IsNullOrEmpty(helpInfo.ForwardTarget)) { // this helpInfo is final...so store this in result // and move on.. yield return(helpInfo); } else { // Find out a capable provider to process this request... HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory; bool isHelpInfoProcessed = false; for (int i = 0; i < this.HelpProviders.Count; i++) { HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i]; if ((helpProvider.HelpCategory & forwardHelpCategory) != HelpCategory.None) { isHelpInfoProcessed = true; // If this help info is processed by this provider already, break // out of the provider loop... foreach (HelpInfo fwdResult in helpProvider.ProcessForwardedHelp(helpInfo, helpRequest)) { // Add each helpinfo to our repository foreach (HelpInfo fHelpInfo in ForwardHelp(fwdResult, helpRequest)) { yield return(fHelpInfo); } // get out of the provider loop.. yield break; } } } if (!isHelpInfoProcessed) { // we are here because no help provider processed the helpinfo.. // so add this to our repository.. yield return(helpInfo); } } }
private IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest) { int countOfHelpInfosFound = 0; bool searchInHelpContent = false; bool shouldBreak = false; do { if (searchInHelpContent) { shouldBreak = true; } for (int i = 0; i < this.HelpProviders.Count; ++i) { HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i]; if ((helpProvider.HelpCategory & helpRequest.HelpCategory) > HelpCategory.None) { foreach (HelpInfo helpInfo in helpProvider.SearchHelp(helpRequest, searchInHelpContent)) { ++countOfHelpInfosFound; yield return(helpInfo); if (countOfHelpInfosFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) { yield break; } } } } if (countOfHelpInfosFound <= 0) { searchInHelpContent = true; } else { goto label_13; } }while (!shouldBreak); goto label_16; label_13: yield break; label_16 :; }
private HelpProvider GetHelpProvider(HelpProviderInfo providerInfo) { Assembly providerAssembly = null; if (String.IsNullOrEmpty(providerInfo.AssemblyName)) { providerAssembly = Assembly.GetExecutingAssembly(); } else { providerAssembly = Assembly.Load(providerInfo.AssemblyName); } try { if (providerAssembly != null) { HelpProvider helpProvider = (HelpProvider)providerAssembly.CreateInstance(providerInfo.ClassName, false, // don't ignore case BindingFlags.CreateInstance, null, // use default binder null, null, // use current culture null // no special activation attributes ); return(helpProvider); } } catch (TargetInvocationException e) { System.Console.WriteLine(e.Message); if (e.InnerException != null) { System.Console.WriteLine(e.InnerException.Message); System.Console.WriteLine(e.InnerException.StackTrace); } } return(null); }
private IEnumerable <HelpInfo> ForwardHelp( HelpInfo helpInfo, HelpRequest helpRequest) { Collection <HelpInfo> collection = new Collection <HelpInfo>(); if (helpInfo.ForwardHelpCategory == HelpCategory.None && string.IsNullOrEmpty(helpInfo.ForwardTarget)) { yield return(helpInfo); } else { HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory; bool isHelpInfoProcessed = false; for (int i = 0; i < this.HelpProviders.Count; ++i) { HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i]; if ((helpProvider.HelpCategory & forwardHelpCategory) == forwardHelpCategory) { isHelpInfoProcessed = true; using (IEnumerator <HelpInfo> enumerator = helpProvider.ProcessForwardedHelp(helpInfo, helpRequest).GetEnumerator()) { if (enumerator.MoveNext()) { HelpInfo fwdResult = enumerator.Current; foreach (HelpInfo helpInfo1 in this.ForwardHelp(fwdResult, helpRequest)) { yield return(helpInfo1); } yield break; } } } } if (!isHelpInfoProcessed) { yield return(helpInfo); } } }
/// <summary> /// Initialize help providers. /// </summary> /// <remarks> /// Currently we hardcode the sequence of help provider initialization. /// In the longer run, we probably will load help providers based on some provider catalog. That /// will allow new providers to be defined by customer. /// </remarks> private void InitializeHelpProviders() { HelpProvider helpProvider = null; helpProvider = new AliasHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new ScriptCommandHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new CommandHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new ProviderHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new PSClassHelpProvider(this); _helpProviders.Add(helpProvider); /* TH Bug#3141590 - Disable DscResourceHelp for ClientRTM due to perf issue. #if !CORECLR // TODO:CORECLR Add this back in once we support Get-DscResource * helpProvider = new DscResourceHelpProvider(this); * _helpProviders.Add(helpProvider); #endif */ helpProvider = new HelpFileHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new FaqHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new GlossaryHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new GeneralHelpProvider(this); _helpProviders.Add(helpProvider); helpProvider = new DefaultHelpProvider(this); _helpProviders.Add(helpProvider); }
private void InitializeHelpProviders() { HelpProvider provider = null; provider = new AliasHelpProvider(this); this._helpProviders.Add(provider); provider = new ScriptCommandHelpProvider(this); this._helpProviders.Add(provider); provider = new CommandHelpProvider(this); this._helpProviders.Add(provider); provider = new ProviderHelpProvider(this); this._helpProviders.Add(provider); provider = new HelpFileHelpProvider(this); this._helpProviders.Add(provider); provider = new FaqHelpProvider(this); this._helpProviders.Add(provider); provider = new GlossaryHelpProvider(this); this._helpProviders.Add(provider); provider = new GeneralHelpProvider(this); this._helpProviders.Add(provider); provider = new DefaultHelpProvider(this); this._helpProviders.Add(provider); }
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; } } }
private IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest) { bool isHelpInfoFound = false; for (int i = 0; i < this.HelpProviders.Count; ++i) { HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i]; if ((helpProvider.HelpCategory & helpRequest.HelpCategory) > HelpCategory.None) { foreach (HelpInfo helpInfo1 in helpProvider.ExactMatchHelp(helpRequest)) { isHelpInfoFound = true; foreach (HelpInfo helpInfo2 in this.ForwardHelp(helpInfo1, helpRequest)) { yield return(helpInfo2); } } } if (isHelpInfoFound) { break; } } }
/// <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); } }