private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) { if (helpInfo != null) { if (showFullHelp && this.showOnlineHelp) { bool flag = false; tracer.WriteLine("Preparing to show help online.", new object[0]); Uri uriForOnlineHelp = helpInfo.GetUriForOnlineHelp(); if (null != uriForOnlineHelp) { flag = true; this.LaunchOnlineHelp(uriForOnlineHelp); } else if (!flag) { throw PSTraceSource.NewInvalidOperationException("HelpErrors", "NoURIFound", new object[0]); } } else if (showFullHelp && (this.ShowWindow != 0)) { this.graphicalHostReflectionWrapper.CallStaticMethod("ShowHelpWindow", new object[] { helpInfo.FullHelp, this }); } else if (showFullHelp) { if (!string.IsNullOrEmpty(this._parameter)) { this.GetAndWriteParameterInfo(helpInfo); } else { PSObject sendToPipeline = this.TransformView(helpInfo.FullHelp); sendToPipeline.IsHelpObject = true; base.WriteObject(sendToPipeline); } } else { if (!string.IsNullOrEmpty(this._parameter)) { PSObject[] parameter = helpInfo.GetParameter(this._parameter); if ((parameter == null) || (parameter.Length == 0)) { return; } } base.WriteObject(helpInfo.ShortHelp); } } }
/// <summary> /// Returns the Uri used by get-help cmdlet to show help /// online. Returns only the first uri found under /// RelatedLinks. /// </summary> /// <returns> /// Null if no Uri is specified by the helpinfo or a /// valid Uri. /// </returns> internal override Uri GetUriForOnlineHelp() { return(_helpInfo.GetUriForOnlineHelp()); }
private HelpInfo GetHelpInfo(IScriptCommandInfo scriptCommandInfo, bool reportErrors, bool searchOnlyContent) { CommandInfo commandInfo = (CommandInfo)scriptCommandInfo; HelpInfo helpInfoFromWorkflow = null; ScriptBlock scriptBlock = null; try { scriptBlock = scriptCommandInfo.ScriptBlock; } catch (RuntimeException) { return(null); } if (scriptBlock != null) { string helpFile = null; string str2 = null; string helpUriFromDotLink = null; helpInfoFromWorkflow = scriptBlock.GetHelpInfo(this._context, commandInfo, searchOnlyContent, base.HelpSystem.ScriptBlockTokenCache, out helpFile, out helpUriFromDotLink); if (!string.IsNullOrEmpty(helpUriFromDotLink)) { try { new Uri(helpUriFromDotLink); str2 = helpUriFromDotLink; } catch (UriFormatException) { } } if (helpInfoFromWorkflow != null) { Uri uriForOnlineHelp = helpInfoFromWorkflow.GetUriForOnlineHelp(); if (uriForOnlineHelp != null) { str2 = uriForOnlineHelp.ToString(); } } if (helpFile != null) { if (!this._helpFiles.Contains(helpFile)) { this.LoadHelpFile(helpFile, helpFile, commandInfo.Name, reportErrors); } helpInfoFromWorkflow = this.GetFromCommandCache(helpFile, commandInfo) ?? helpInfoFromWorkflow; } if (helpInfoFromWorkflow == null) { if ((commandInfo.CommandType == CommandTypes.ExternalScript) || (commandInfo.CommandType == CommandTypes.Script)) { helpInfoFromWorkflow = SyntaxHelpInfo.GetHelpInfo(commandInfo.Name, commandInfo.Syntax, commandInfo.HelpCategory); } else { if (commandInfo.CommandType == CommandTypes.Workflow) { helpInfoFromWorkflow = this.GetHelpInfoFromWorkflow(commandInfo, reportErrors); } if (helpInfoFromWorkflow == null) { PSObject pSObjectFromCmdletInfo = DefaultCommandHelpObjectBuilder.GetPSObjectFromCmdletInfo(commandInfo); pSObjectFromCmdletInfo.TypeNames.Clear(); pSObjectFromCmdletInfo.TypeNames.Add(DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp); pSObjectFromCmdletInfo.TypeNames.Add("CmdletHelpInfo"); pSObjectFromCmdletInfo.TypeNames.Add("HelpInfo"); helpInfoFromWorkflow = new MamlCommandHelpInfo(pSObjectFromCmdletInfo, commandInfo.HelpCategory); } } } if (helpInfoFromWorkflow.GetUriForOnlineHelp() == null) { if (!string.IsNullOrEmpty(commandInfo.CommandMetadata.HelpUri)) { DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(helpInfoFromWorkflow.FullHelp, commandInfo.CommandMetadata.HelpUri); } else if (!string.IsNullOrEmpty(str2)) { DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(helpInfoFromWorkflow.FullHelp, str2); } } } if ((helpInfoFromWorkflow != null) && (helpInfoFromWorkflow.FullHelp.Properties["ModuleName"] == null)) { helpInfoFromWorkflow.FullHelp.Properties.Add(new PSNoteProperty("ModuleName", commandInfo.ModuleName)); } return(helpInfoFromWorkflow); }
/// <summary> /// Helper method used to Write the help object onto the output /// stream or show online help (URI extracted from the HelpInfo) /// object. /// </summary> private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp) { if (helpInfo != null) { // online help can be showed only if showFullHelp is true.. // showFullHelp will be false when the help tries to display multiple help topics.. // -Online should not work when multiple help topics are displayed. if (showFullHelp && _showOnlineHelp) { bool onlineUriFound = false; // show online help s_tracer.WriteLine("Preparing to show help online."); Uri onlineUri = helpInfo.GetUriForOnlineHelp(); if (null != onlineUri) { onlineUriFound = true; LaunchOnlineHelp(onlineUri); return; } if (!onlineUriFound) { throw PSTraceSource.NewInvalidOperationException(HelpErrors.NoURIFound); } } else if (showFullHelp && ShowWindow) { #if !CORECLR graphicalHostReflectionWrapper.CallStaticMethod("ShowHelpWindow", helpInfo.FullHelp, this); #endif } else { // show inline help if (showFullHelp) { if (!string.IsNullOrEmpty(Parameter)) { GetAndWriteParameterInfo(helpInfo); } else { PSObject objectToReturn = TransformView(helpInfo.FullHelp); objectToReturn.IsHelpObject = true; WriteObject(objectToReturn); } } else { if (!string.IsNullOrEmpty(Parameter)) { PSObject[] pInfos = helpInfo.GetParameter(Parameter); if ((pInfos == null) || (pInfos.Length == 0)) { return; } } WriteObject(helpInfo.ShortHelp); } } } }