Пример #1
0
        private HelpInfo GetFromCommandCacheOrCmdletInfo(CmdletInfo cmdletInfo)
        {
            HelpInfo info = this.GetFromCommandCache(cmdletInfo.ModuleName, cmdletInfo.Name, cmdletInfo.HelpCategory);

            if (((info == null) && (cmdletInfo.Module != null)) && !string.IsNullOrEmpty(cmdletInfo.Prefix))
            {
                MamlCommandHelpInfo fromCommandCacheByRemovingPrefix = this.GetFromCommandCacheByRemovingPrefix(cmdletInfo.ModuleName, cmdletInfo);
                if (fromCommandCacheByRemovingPrefix != null)
                {
                    if ((fromCommandCacheByRemovingPrefix.FullHelp.Properties["Details"] != null) && (fromCommandCacheByRemovingPrefix.FullHelp.Properties["Details"].Value != null))
                    {
                        PSObject obj2 = PSObject.AsPSObject(fromCommandCacheByRemovingPrefix.FullHelp.Properties["Details"].Value);
                        if (obj2.Properties["Noun"] != null)
                        {
                            obj2.Properties.Remove("Noun");
                        }
                        obj2.Properties.Add(new PSNoteProperty("Noun", cmdletInfo.Noun));
                    }
                    this.AddToCommandCache(cmdletInfo.ModuleName, cmdletInfo.Name, fromCommandCacheByRemovingPrefix);
                    return(fromCommandCacheByRemovingPrefix);
                }
            }
            if (info == null)
            {
                PSObject pSObjectFromCmdletInfo = DefaultCommandHelpObjectBuilder.GetPSObjectFromCmdletInfo(cmdletInfo);
                pSObjectFromCmdletInfo.TypeNames.Clear();
                pSObjectFromCmdletInfo.TypeNames.Add(DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp);
                pSObjectFromCmdletInfo.TypeNames.Add("CmdletHelpInfo");
                pSObjectFromCmdletInfo.TypeNames.Add("HelpInfo");
                info = new MamlCommandHelpInfo(pSObjectFromCmdletInfo, cmdletInfo.HelpCategory);
            }
            return(info);
        }
Пример #2
0
        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);
        }
Пример #3
0
        internal static HelpInfo CreateFromComments(ExecutionContext context, CommandInfo commandInfo, HelpCommentsParser helpCommentsParser, bool dontSearchOnRemoteComputer)
        {
            if (!dontSearchOnRemoteComputer)
            {
                RemoteHelpInfo remoteHelpInfo = helpCommentsParser.GetRemoteHelpInfo(context, commandInfo);
                if (remoteHelpInfo != null)
                {
                    if (remoteHelpInfo.GetUriForOnlineHelp() == null)
                    {
                        DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(remoteHelpInfo.FullHelp, commandInfo.CommandMetadata.HelpUri);
                    }
                    return(remoteHelpInfo);
                }
            }
            XmlDocument         document     = helpCommentsParser.BuildXmlFromComments();
            HelpCategory        helpCategory = commandInfo.HelpCategory;
            MamlCommandHelpInfo helpInfo     = MamlCommandHelpInfo.Load(document.DocumentElement, helpCategory);

            if (helpInfo != null)
            {
                helpCommentsParser.SetAdditionalData(helpInfo);
                if (!string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpTargetName) || !string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpCategory))
                {
                    if (string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpTargetName))
                    {
                        helpInfo.ForwardTarget = helpInfo.Name;
                    }
                    else
                    {
                        helpInfo.ForwardTarget = helpCommentsParser._sections.ForwardHelpTargetName;
                    }
                    if (!string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpCategory))
                    {
                        try
                        {
                            helpInfo.ForwardHelpCategory = (HelpCategory)Enum.Parse(typeof(HelpCategory), helpCommentsParser._sections.ForwardHelpCategory, true);
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                    else
                    {
                        helpInfo.ForwardHelpCategory = HelpCategory.Workflow | HelpCategory.ExternalScript | HelpCategory.Filter | HelpCategory.Function | HelpCategory.ScriptCommand | HelpCategory.Cmdlet | HelpCategory.Alias;
                    }
                }
                WorkflowInfo info3 = commandInfo as WorkflowInfo;
                if (info3 != null)
                {
                    bool flag  = DefaultCommandHelpObjectBuilder.HasCommonParameters(commandInfo.Parameters);
                    bool flag2 = (commandInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow;
                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("CommonParameters", flag));
                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", flag2));
                    DefaultCommandHelpObjectBuilder.AddDetailsProperties(helpInfo.FullHelp, info3.Name, info3.Noun, info3.Verb, "MamlCommandHelpInfo", helpInfo.Synopsis);
                    DefaultCommandHelpObjectBuilder.AddSyntaxProperties(helpInfo.FullHelp, info3.Name, info3.ParameterSets, flag, flag2, "MamlCommandHelpInfo");
                }
                if (helpInfo.GetUriForOnlineHelp() == null)
                {
                    DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(helpInfo.FullHelp, commandInfo.CommandMetadata.HelpUri);
                }
            }
            return(helpInfo);
        }