Пример #1
0
        internal static HelpInfo CreateFromComments(
            ExecutionContext context,
            CommandInfo commandInfo,
            List <Token> comments,
            List <List <Token> > parameterComments,
            out string helpFile)
        {
            HelpCommentsParser helpCommentsParser = new HelpCommentsParser(commandInfo, parameterComments);

            helpCommentsParser.AnalyzeCommentBlock(comments);
            helpFile = helpCommentsParser.GetHelpFile(commandInfo);
            RemoteHelpInfo remoteHelpInfo = helpCommentsParser.GetRemoteHelpInfo(context, commandInfo);

            if (remoteHelpInfo != null)
            {
                return((HelpInfo)remoteHelpInfo);
            }
            MamlCommandHelpInfo helpInfo = MamlCommandHelpInfo.Load((XmlNode)helpCommentsParser.BuildXmlFromComments().DocumentElement, commandInfo.HelpCategory);

            if (helpInfo != null)
            {
                helpCommentsParser.SetAdditionalData(helpInfo);
                if (!string.IsNullOrEmpty(helpCommentsParser.sections.forwardHelpTargetName) || !string.IsNullOrEmpty(helpCommentsParser.sections.fowardHelpCategory))
                {
                    if (string.IsNullOrEmpty(helpCommentsParser.sections.forwardHelpTargetName))
                    {
                        helpInfo.ForwardTarget = helpInfo.Name;
                    }
                    else
                    {
                        helpInfo.ForwardTarget = helpCommentsParser.sections.forwardHelpTargetName;
                    }
                    if (!string.IsNullOrEmpty(helpCommentsParser.sections.fowardHelpCategory))
                    {
                        try
                        {
                            helpInfo.ForwardHelpCategory = (HelpCategory)Enum.Parse(typeof(HelpCategory), helpCommentsParser.sections.fowardHelpCategory, true);
                        }
                        catch (ArgumentException ex)
                        {
                        }
                    }
                    else
                    {
                        helpInfo.ForwardHelpCategory = HelpCategory.Alias | HelpCategory.Cmdlet | HelpCategory.ScriptCommand | HelpCategory.Function | HelpCategory.Filter | HelpCategory.ExternalScript;
                    }
                }
            }
            return((HelpInfo)helpInfo);
        }
Пример #2
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);
        }