Esempio n. 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);
        }
Esempio n. 2
0
        private MamlCommandHelpInfo GetFromCommandCacheByRemovingPrefix(string helpIdentifier, CommandInfo cmdInfo)
        {
            MamlCommandHelpInfo info  = null;
            MamlCommandHelpInfo info2 = this.GetFromCommandCache(helpIdentifier, ModuleCmdletBase.RemovePrefixFromCommandName(cmdInfo.Name, cmdInfo.Prefix), cmdInfo.HelpCategory) as MamlCommandHelpInfo;

            if (info2 != null)
            {
                info = info2.Copy();
                if (info.FullHelp.Properties["Name"] != null)
                {
                    info.FullHelp.Properties.Remove("Name");
                }
                info.FullHelp.Properties.Add(new PSNoteProperty("Name", cmdInfo.Name));
                if ((info.FullHelp.Properties["Details"] == null) || (info.FullHelp.Properties["Details"].Value == null))
                {
                    return(info);
                }
                PSObject obj2 = PSObject.AsPSObject(info.FullHelp.Properties["Details"].Value).Copy();
                if (obj2.Properties["Name"] != null)
                {
                    obj2.Properties.Remove("Name");
                }
                obj2.Properties.Add(new PSNoteProperty("Name", cmdInfo.Name));
                info.FullHelp.Properties["Details"].Value = obj2;
            }
            return(info);
        }
Esempio n. 3
0
        internal MamlCommandHelpInfo Copy(HelpCategory newCategoryToUse)
        {
            MamlCommandHelpInfo info = new MamlCommandHelpInfo(this._fullHelpObject.Copy(), newCategoryToUse);

            info.FullHelp.Properties["Category"].Value = newCategoryToUse;
            return(info);
        }
Esempio n. 4
0
        /// <summary>
        /// Merge the provider specific help with current command help.
        ///
        /// The cmdletHelp and dynamicParameterHelp is normally retrieved from ProviderHelpProvider.
        /// </summary>
        /// <remarks>
        /// A new MamlCommandHelpInfo is created to avoid polluting the provider help cache.
        /// </remarks>
        /// <param name="cmdletHelp">Provider-specific cmdletHelp to merge into current MamlCommandHelpInfo object.</param>
        /// <param name="dynamicParameterHelp">Provider-specific dynamic parameter help to merge into current MamlCommandHelpInfo object.</param>
        /// <returns>Merged command help info object.</returns>
        internal MamlCommandHelpInfo MergeProviderSpecificHelp(PSObject cmdletHelp, PSObject[] dynamicParameterHelp)
        {
            if (this._fullHelpObject == null)
            {
                return(null);
            }

            MamlCommandHelpInfo result = (MamlCommandHelpInfo)this.MemberwiseClone();

            // We will need to use a deep clone of _fullHelpObject
            // to avoid _fullHelpObject being get terminated.
            result._fullHelpObject = this._fullHelpObject.Copy();

            if (cmdletHelp != null)
            {
                result._fullHelpObject.Properties.Add(new PSNoteProperty("PS_Cmdlet", cmdletHelp));
            }

            if (dynamicParameterHelp != null)
            {
                result._fullHelpObject.Properties.Add(new PSNoteProperty("PS_DynamicParameters", dynamicParameterHelp));
            }

            return(result);
        }
Esempio n. 5
0
        internal MamlCommandHelpInfo Copy(HelpCategory newCategoryToUse)
        {
            MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), newCategoryToUse);

            result.FullHelp.Properties["Category"].Value = newCategoryToUse;
            return(result);
        }
Esempio n. 6
0
        private void LoadHelpFile(string helpFile, string helpFileIdentifier)
        {
            XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(helpFile), false, null);

            this._helpFiles[helpFile] = 0;
            System.Xml.XmlNode helpItemsNode = null;
            if (document.HasChildNodes)
            {
                for (int i = 0; i < document.ChildNodes.Count; i++)
                {
                    System.Xml.XmlNode node2 = document.ChildNodes[i];
                    if ((node2.NodeType == XmlNodeType.Element) && (string.Compare(node2.LocalName, "helpItems", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        helpItemsNode = node2;
                        break;
                    }
                }
            }
            if (helpItemsNode == null)
            {
                tracer.WriteLine("Unable to find 'helpItems' element in file {0}", new object[] { helpFile });
            }
            else
            {
                bool flag = IsMamlHelp(helpFile, helpItemsNode);
                using (base.HelpSystem.Trace(helpFile))
                {
                    if (helpItemsNode.HasChildNodes)
                    {
                        for (int j = 0; j < helpItemsNode.ChildNodes.Count; j++)
                        {
                            System.Xml.XmlNode xmlNode = helpItemsNode.ChildNodes[j];
                            if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.LocalName, "command", StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                MamlCommandHelpInfo helpInfo = null;
                                if (flag)
                                {
                                    helpInfo = MamlCommandHelpInfo.Load(xmlNode, System.Management.Automation.HelpCategory.Cmdlet);
                                }
                                if (helpInfo != null)
                                {
                                    base.HelpSystem.TraceErrors(helpInfo.Errors);
                                    this.AddToCommandCache(helpFileIdentifier, helpInfo.Name, helpInfo);
                                }
                            }
                            if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.Name, "UserDefinedData", StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                UserDefinedHelpData userDefinedHelpData = UserDefinedHelpData.Load(xmlNode);
                                this.ProcessUserDefineddHelpData(helpFileIdentifier, userDefinedHelpData);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        internal static MamlCommandHelpInfo Load(System.Xml.XmlNode xmlNode, HelpCategory helpCategory)
        {
            MamlCommandHelpInfo info = new MamlCommandHelpInfo(xmlNode, helpCategory);

            if (string.IsNullOrEmpty(info.Name))
            {
                return(null);
            }
            info.AddCommonHelpProperties();
            return(info);
        }
Esempio n. 8
0
 private void AddToCommandCache(string mshSnapInId, string cmdletName, MamlCommandHelpInfo helpInfo)
 {
     string target = cmdletName;
     helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture, "MamlCommandHelpInfo#{0}#{1}", new object[] { mshSnapInId, cmdletName }));
     if (!string.IsNullOrEmpty(mshSnapInId))
     {
         target = mshSnapInId + @"\" + target;
         helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture, "MamlCommandHelpInfo#{0}", new object[] { mshSnapInId }));
     }
     base.AddCache(target, helpInfo);
 }
Esempio n. 9
0
        private void AddToCommandCache(string mshSnapInId, string cmdletName, MamlCommandHelpInfo helpInfo)
        {
            string target = cmdletName;

            helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture, "MamlCommandHelpInfo#{0}#{1}", new object[] { mshSnapInId, cmdletName }));
            if (!string.IsNullOrEmpty(mshSnapInId))
            {
                target = mshSnapInId + @"\" + target;
                helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture, "MamlCommandHelpInfo#{0}", new object[] { mshSnapInId }));
            }
            base.AddCache(target, helpInfo);
        }
Esempio n. 10
0
        internal static MamlCommandHelpInfo Load(
            XmlNode xmlNode,
            HelpCategory helpCategory)
        {
            MamlCommandHelpInfo mamlCommandHelpInfo = new MamlCommandHelpInfo(xmlNode, helpCategory);

            if (string.IsNullOrEmpty(mamlCommandHelpInfo.Name))
            {
                return((MamlCommandHelpInfo)null);
            }
            mamlCommandHelpInfo.AddCommonHelpProperties();
            return(mamlCommandHelpInfo);
        }
Esempio n. 11
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);
        }
        /// <summary>
        /// Gets the HelpInfo object corresponding to the command.
        /// </summary>
        /// <param name="helpFileIdentifier">help file identifier (either name of PSSnapIn or simply full path to help file)</param>
        /// <param name="helpCategory">Help Category for search.</param>
        /// <returns>HelpInfo object.</returns>
        private HelpInfo GetFromResourceHelpCache(string helpFileIdentifier, HelpCategory helpCategory)
        {
            Debug.Assert(!string.IsNullOrEmpty(helpFileIdentifier), "helpFileIdentifier should not be null or empty.");

            HelpInfo result = GetCache(helpFileIdentifier);

            if (result != null)
            {
                MamlCommandHelpInfo original = (MamlCommandHelpInfo)result;
                result = original.Copy(helpCategory);
            }

            return(result);
        }
Esempio n. 13
0
        private HelpInfo GetFromCommandCache(string helpFileIdentifier, CommandInfo commandInfo)
        {
            HelpInfo info = this.GetFromCommandCache(helpFileIdentifier, commandInfo.Name, commandInfo.HelpCategory);

            if (((info == null) && (commandInfo.Module != null)) && !string.IsNullOrEmpty(commandInfo.Prefix))
            {
                MamlCommandHelpInfo fromCommandCacheByRemovingPrefix = this.GetFromCommandCacheByRemovingPrefix(helpFileIdentifier, commandInfo);
                if (fromCommandCacheByRemovingPrefix != null)
                {
                    this.AddToCommandCache(helpFileIdentifier, commandInfo.Name, fromCommandCacheByRemovingPrefix);
                    return(fromCommandCacheByRemovingPrefix);
                }
            }
            return(info);
        }
Esempio n. 14
0
 private void ProcessUserDefineddHelpData(string mshSnapInId, UserDefinedHelpData userDefinedHelpData)
 {
     if ((userDefinedHelpData != null) && !string.IsNullOrEmpty(userDefinedHelpData.Name))
     {
         HelpInfo info = this.GetFromCommandCache(mshSnapInId, userDefinedHelpData.Name, System.Management.Automation.HelpCategory.Cmdlet);
         if (info != null)
         {
             MamlCommandHelpInfo info2 = info as MamlCommandHelpInfo;
             if (info2 != null)
             {
                 info2.AddUserDefinedData(userDefinedHelpData);
             }
         }
     }
 }
        internal ProviderCommandHelpInfo(HelpInfo genericHelpInfo, ProviderContext providerContext)
        {
            base.ForwardHelpCategory = System.Management.Automation.HelpCategory.None;
            MamlCommandHelpInfo providerSpecificHelpInfo = providerContext.GetProviderSpecificHelpInfo(genericHelpInfo.Name);

            if (providerSpecificHelpInfo == null)
            {
                this._helpInfo = genericHelpInfo;
            }
            else
            {
                providerSpecificHelpInfo.OverrideProviderSpecificHelpWithGenericHelp(genericHelpInfo);
                this._helpInfo = providerSpecificHelpInfo;
            }
        }
        /// <summary>
        /// Constructor for ProviderCommandHelpInfo.
        /// </summary>
        internal ProviderCommandHelpInfo(HelpInfo genericHelpInfo, ProviderContext providerContext)
        {
            Dbg.Assert(genericHelpInfo != null, "Expected genericHelpInfo != null");
            Dbg.Assert(providerContext != null, "Expected providerContext != null");

            // This should be set to None to prevent infinite forwarding.
            this.ForwardHelpCategory = HelpCategory.None;

            // Now pick which help we should show.
            MamlCommandHelpInfo providerSpecificHelpInfo =
                providerContext.GetProviderSpecificHelpInfo(genericHelpInfo.Name);

            if (providerSpecificHelpInfo == null)
            {
                _helpInfo = genericHelpInfo;
            }
            else
            {
                providerSpecificHelpInfo.OverrideProviderSpecificHelpWithGenericHelp(genericHelpInfo);
                _helpInfo = providerSpecificHelpInfo;
            }
        }
Esempio n. 17
0
        internal MamlCommandHelpInfo Copy()
        {
            MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), this.HelpCategory);

            return(result);
        }
Esempio n. 18
0
 internal MamlCommandHelpInfo Copy(HelpCategory newCategoryToUse)
 {
     MamlCommandHelpInfo info = new MamlCommandHelpInfo(this._fullHelpObject.Copy(), newCategoryToUse);
     info.FullHelp.Properties["Category"].Value = newCategoryToUse;
     return info;
 }
Esempio n. 19
0
 internal static MamlCommandHelpInfo Load(System.Xml.XmlNode xmlNode, HelpCategory helpCategory)
 {
     MamlCommandHelpInfo info = new MamlCommandHelpInfo(xmlNode, helpCategory);
     if (string.IsNullOrEmpty(info.Name))
     {
         return null;
     }
     info.AddCommonHelpProperties();
     return info;
 }
Esempio n. 20
0
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            ProviderInfo          info    = null;
            PSDriveInfo           drive   = null;
            string                str     = null;
            CmdletProviderContext context = new CmdletProviderContext(this._executionContext);

            try
            {
                string str2 = this._requestedPath;
                if (string.IsNullOrEmpty(this._requestedPath))
                {
                    str2 = this._pathIntrinsics.CurrentLocation.Path;
                }
                str = this._executionContext.LocationGlobber.GetProviderPath(str2, context, out info, out drive);
            }
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }
            if (info == null)
            {
                return(null);
            }
            CmdletProvider provider          = info.CreateInstance();
            ICmdletProviderSupportsHelp help = provider as ICmdletProviderSupportsHelp;

            if (help == null)
            {
                return(null);
            }
            if (str == null)
            {
                throw new ItemNotFoundException(this._requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
            }
            provider.Start(info, context);
            string path     = str;
            string helpMaml = help.GetHelpMaml(helpItemName, path);

            if (string.IsNullOrEmpty(helpMaml))
            {
                return(null);
            }
            return(MamlCommandHelpInfo.Load(InternalDeserializer.LoadUnsafeXmlDocument(helpMaml, false, null).DocumentElement, HelpCategory.Provider));
        }
Esempio n. 21
0
 /// <summary>
 /// The analysis of the comments finds the component, functionality, and role fields, but
 /// those fields aren't added to the xml because they aren't children of the command xml
 /// node, they are under a sibling of the command xml node and apply to all command nodes
 /// in a maml file.
 /// </summary>
 /// <param name="helpInfo">The helpInfo object to set the fields on.</param>
 internal void SetAdditionalData(MamlCommandHelpInfo helpInfo)
 {
     helpInfo.SetAdditionalDataFromHelpComment(
         _sections.Component,
         _sections.Functionality,
         _sections.Role);
 }
        /// <summary>
        /// Load help file for HelpInfo objects. The HelpInfo objects will be
        /// put into help cache.
        /// </summary>
        /// <remarks>
        /// 1. Needs to pay special attention about error handling in this function.
        /// Common errors include: file not found and invalid xml. None of these error
        /// should cause help search to stop.
        /// 2. a helpfile cache is used to avoid same file got loaded again and again.
        /// </remarks>
        private void LoadHelpFile(string helpFile, string helpFileIdentifier)
        {
            Dbg.Assert(!String.IsNullOrEmpty(helpFile), "HelpFile cannot be null or empty.");
            Dbg.Assert(!String.IsNullOrEmpty(helpFileIdentifier), "helpFileIdentifier cannot be null or empty.");

            XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument(
                new FileInfo(helpFile),
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */

            // Add this file into _helpFiles hashtable to prevent it to be loaded again.
            _helpFiles[helpFile] = 0;

            XmlNode helpItemsNode = null;

            if (doc.HasChildNodes)
            {
                for (int i = 0; i < doc.ChildNodes.Count; i++)
                {
                    XmlNode node = doc.ChildNodes[i];
                    if (node.NodeType == XmlNodeType.Element && String.Compare(node.LocalName, "helpItems", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                s_tracer.WriteLine("Unable to find 'helpItems' element in file {0}", helpFile);
                return;
            }

            bool isMaml = IsMamlHelp(helpFile, helpItemsNode);

            using (this.HelpSystem.Trace(helpFile))
            {
                if (helpItemsNode.HasChildNodes)
                {
                    for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++)
                    {
                        XmlNode node = helpItemsNode.ChildNodes[i];

                        string nodeLocalName = node.LocalName;

                        bool isDscResource = (String.Compare(nodeLocalName, "dscResource", StringComparison.OrdinalIgnoreCase) == 0);

                        if (node.NodeType == XmlNodeType.Element && isDscResource)
                        {
                            MamlCommandHelpInfo helpInfo = null;

                            if (isMaml)
                            {
                                if (isDscResource)
                                {
                                    helpInfo = MamlCommandHelpInfo.Load(node, HelpCategory.DscResource);
                                }
                            }

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                AddCache(helpFileIdentifier, helpInfo);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 23
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;
 }
Esempio n. 24
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);
        }
Esempio n. 25
0
 internal void SetAdditionalData(MamlCommandHelpInfo helpInfo)
 {
     helpInfo.SetAdditionalDataFromHelpComment(this._sections.Component, this._sections.Functionality, this._sections.Role);
 }
Esempio n. 26
0
 internal void SetAdditionalData(MamlCommandHelpInfo helpInfo) => helpInfo.SetAdditionalDataFromHelpComment(this.sections.component, this.sections.functionality, this.sections.role);
Esempio n. 27
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);
        }
Esempio n. 28
0
        private HelpInfo GetHelpInfo(CommandInfo commandInfo, bool reportErrors, bool searchOnlyContent)
        {
            Dbg.Assert(commandInfo != null, "Caller should verify that commandInfo != null");

            HelpInfo result = null; // The help result
            string helpFile = null; // The file that contains the help info
            string helpUri = null;
            string helpUriFromDotLink = null;

            CmdletInfo cmdletInfo = commandInfo as CmdletInfo;
            IScriptCommandInfo scriptCommandInfo = commandInfo as IScriptCommandInfo;
            FunctionInfo functionInfo = commandInfo as FunctionInfo;
            bool isCmdlet = cmdletInfo != null;
            bool isScriptCommand = scriptCommandInfo != null;
            bool isFunction = functionInfo != null;

            string moduleName = null;
            string moduleDir = null;
            string nestedModulePath = null;

            // Only gets help for Cmdlet or script command
            if (!isCmdlet && !isScriptCommand)
                return null;

            // Check if the help of the command is already in the cache.
            // If not, try load the file specified by HelpFile property and retrieve help.
            if (isCmdlet)
            {
                result = GetFromCommandCache(cmdletInfo.ModuleName, cmdletInfo.Name, cmdletInfo.HelpCategory);
                if (null == result)
                {
                    // Try load the help file specified by CmdletInfo.HelpFile property
                    helpFile = FindHelpFile(cmdletInfo);
                    if (!String.IsNullOrEmpty(helpFile) && !_helpFiles.Contains(helpFile))
                    {
                        LoadHelpFile(helpFile, cmdletInfo.ModuleName, cmdletInfo.Name, reportErrors);
                    }
                    result = GetFromCommandCacheOrCmdletInfo(cmdletInfo);
                }
            }
            else if (isFunction)
            {
                // Try load the help file specified by FunctionInfo.HelpFile property
                helpFile = functionInfo.HelpFile;
                if (!String.IsNullOrEmpty(helpFile))
                {
                    if (!_helpFiles.Contains(helpFile))
                    {
                        LoadHelpFile(helpFile, helpFile, commandInfo.Name, reportErrors);
                    }
                    result = GetFromCommandCache(helpFile, commandInfo);
                }
            }

            // For scripts, try to retrieve the help from the file specified by .ExternalHelp directive
            if (null == result && isScriptCommand)
            {
                ScriptBlock sb = null;
                try
                {
                    sb = scriptCommandInfo.ScriptBlock;
                }
                catch (RuntimeException)
                {
                    // parsing errors should not block searching for help
                    return null;
                }

                if (sb != null)
                {
                    helpFile = null;
                    // searchOnlyContent == true means get-help is looking into the content, in this case we dont
                    // want to download the content from the remote machine. Reason: In Exchange scenario there
                    // are ~700 proxy commands, downloading help for all the commands and searching in that
                    // content takes a lot of time (in the order of 30 minutes) for their scenarios.
                    result = sb.GetHelpInfo(_context, commandInfo, searchOnlyContent, HelpSystem.ScriptBlockTokenCache,
                        out helpFile, out helpUriFromDotLink);

                    if (!String.IsNullOrEmpty(helpUriFromDotLink))
                    {
                        try
                        {
                            Uri testUri = new Uri(helpUriFromDotLink);
                            helpUri = helpUriFromDotLink;
                        }
                        catch (UriFormatException)
                        {
                            // Do not add if helpUriFromDotLink is not a URI
                        }
                    }

                    if (result != null)
                    {
                        Uri uri = result.GetUriForOnlineHelp();

                        if (uri != null)
                        {
                            helpUri = uri.ToString();
                        }
                    }

                    if (!String.IsNullOrEmpty(helpFile))
                    {
                        if (!_helpFiles.Contains(helpFile))
                        {
                            LoadHelpFile(helpFile, helpFile, commandInfo.Name, reportErrors);
                        }
                        result = GetFromCommandCache(helpFile, commandInfo) ?? result;
                    }
                }
            }

            // If the above fails to get help, try search for a file called <ModuleName>-Help.xml
            // in the appropriate UI culture subfolder of ModuleBase, and retrieve help
            // If still not able to get help, try search for a file called <NestedModuleName>-Help.xml
            // under the ModuleBase and the NestedModule's directory, and retrieve help
            if (null == result)
            {
                // Get the name and ModuleBase directory of the command's module
                // and the nested module that implements the command
                GetModulePaths(commandInfo, out moduleName, out moduleDir, out nestedModulePath);

                Collection<String> searchPaths = new Collection<String>();
                if (!String.IsNullOrEmpty(moduleDir))
                {
                    searchPaths.Add(moduleDir);
                }

                if (!String.IsNullOrEmpty(moduleName) && !String.IsNullOrEmpty(moduleDir))
                {
                    // Search for <ModuleName>-Help.xml under ModuleBase folder
                    string helpFileToFind = moduleName + "-Help.xml";
                    result = GetHelpInfoFromHelpFile(commandInfo, helpFileToFind, searchPaths, reportErrors, out helpFile);
                }

                if (null == result && !String.IsNullOrEmpty(nestedModulePath))
                {
                    // Search for <NestedModuleName>-Help.xml under both ModuleBase and NestedModule's directory
                    searchPaths.Add(Path.GetDirectoryName(nestedModulePath));
                    string helpFileToFind = Path.GetFileName(nestedModulePath) + "-Help.xml";
                    result = GetHelpInfoFromHelpFile(commandInfo, helpFileToFind, searchPaths, reportErrors, out helpFile);
                }
            }

            // Set the HelpFile property to the file that contains the help content
            if (null != result && !String.IsNullOrEmpty(helpFile))
            {
                if (isCmdlet)
                {
                    cmdletInfo.HelpFile = helpFile;
                }
                else if (isFunction)
                {
                    functionInfo.HelpFile = helpFile;
                }
            }

            // If the above fails to get help, construct an HelpInfo object using the syntax and definition of the command
            if (null == result)
            {
                if (commandInfo.CommandType == CommandTypes.ExternalScript ||
                    commandInfo.CommandType == CommandTypes.Script)
                {
                    result = SyntaxHelpInfo.GetHelpInfo(commandInfo.Name, commandInfo.Syntax, commandInfo.HelpCategory);
                }
                else
                {
                    PSObject helpInfo = Help.DefaultCommandHelpObjectBuilder.GetPSObjectFromCmdletInfo(commandInfo);

                    helpInfo.TypeNames.Clear();
                    helpInfo.TypeNames.Add(DefaultCommandHelpObjectBuilder.TypeNameForDefaultHelp);
                    helpInfo.TypeNames.Add("CmdletHelpInfo");
                    helpInfo.TypeNames.Add("HelpInfo");

                    result = new MamlCommandHelpInfo(helpInfo, commandInfo.HelpCategory);
                }
            }

            if (null != result)
            {
                if (isScriptCommand && result.GetUriForOnlineHelp() == null)
                {
                    if (!String.IsNullOrEmpty(commandInfo.CommandMetadata.HelpUri))
                    {
                        DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(result.FullHelp, commandInfo.CommandMetadata.HelpUri);
                    }
                    else if (!String.IsNullOrEmpty(helpUri))
                    {
                        DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(result.FullHelp, helpUri);
                    }
                }

                if (isCmdlet && result.FullHelp.Properties["PSSnapIn"] == null)
                {
                    result.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", cmdletInfo.PSSnapIn));
                }

                if (result.FullHelp.Properties["ModuleName"] == null)
                {
                    result.FullHelp.Properties.Add(new PSNoteProperty("ModuleName", commandInfo.ModuleName));
                }
            }

            return result;
        }
        /// <summary>
        /// Get provider specific help info.
        /// </summary>
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            // Get the provider.
            ProviderInfo          providerInfo          = null;
            PSDriveInfo           driveInfo             = null;
            string                resolvedProviderPath  = null;
            CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext);

            try
            {
                string psPath = _requestedPath;
                if (string.IsNullOrEmpty(_requestedPath))
                {
                    psPath = _pathIntrinsics.CurrentLocation.Path;
                }

                resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath(
                    psPath,
                    cmdletProviderContext,
                    out providerInfo,
                    out driveInfo);
            }
            // ignore exceptions caused by provider resolution
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }

            if (providerInfo == null)
            {
                return(null);
            }

            // Does the provider know how to generate MAML.
            CmdletProvider cmdletProvider        = providerInfo.CreateInstance();
            ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp;

            if (provider == null)
            {
                return(null);
            }

            if (resolvedProviderPath == null)
            {
                throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
            }

            // ok we have path and valid provider that supplys content..initialize the provider
            // and get the help content for the path.
            cmdletProvider.Start(providerInfo, cmdletProviderContext);
            // There should be exactly one resolved path.
            string providerPath = resolvedProviderPath;
            // Get the MAML help info. Don't catch exceptions thrown by provider.
            string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath);

            if (string.IsNullOrEmpty(mamlXmlString))
            {
                return(null);
            }
            // process the MAML content only if it is non-empty.
            XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument(
                mamlXmlString,
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */
            MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider);

            return(providerSpecificHelpInfo);
        }
Esempio n. 30
0
 internal MamlCommandHelpInfo Copy()
 {
     MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), this.HelpCategory);
     return result;
 }
Esempio n. 31
0
 internal MamlCommandHelpInfo Copy(HelpCategory newCategoryToUse)
 {
     MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), newCategoryToUse);
     result.FullHelp.Properties["Category"].Value = newCategoryToUse;
     return result;
 }
Esempio n. 32
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;
 }
Esempio n. 33
0
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            ProviderInfo          provider = (ProviderInfo)null;
            PSDriveInfo           drive    = (PSDriveInfo)null;
            string                str      = (string)null;
            CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(this._executionContext);

            try
            {
                string path = this._requestedPath;
                if (string.IsNullOrEmpty(this._requestedPath))
                {
                    path = this._pathIntrinsics.CurrentLocation.Path;
                }
                str = this._executionContext.LocationGlobber.GetProviderPath(path, cmdletProviderContext, out provider, out drive);
            }
            catch (ArgumentNullException ex)
            {
            }
            catch (ProviderNotFoundException ex)
            {
            }
            catch (DriveNotFoundException ex)
            {
            }
            catch (ProviderInvocationException ex)
            {
            }
            catch (NotSupportedException ex)
            {
            }
            catch (InvalidOperationException ex)
            {
            }
            catch (ItemNotFoundException ex)
            {
            }
            if (provider == null)
            {
                return((MamlCommandHelpInfo)null);
            }
            CmdletProvider instance = provider.CreateInstance();

            if (!(instance is ICmdletProviderSupportsHelp providerSupportsHelp))
            {
                return((MamlCommandHelpInfo)null);
            }
            if (str == null)
            {
                throw new ItemNotFoundException(this._requestedPath, "PathNotFound");
            }
            instance.Start(provider, cmdletProviderContext);
            string path1    = str;
            string helpMaml = providerSupportsHelp.GetHelpMaml(helpItemName, path1);

            if (string.IsNullOrEmpty(helpMaml))
            {
                return((MamlCommandHelpInfo)null);
            }
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(helpMaml);
            return(MamlCommandHelpInfo.Load((XmlNode)xmlDocument.DocumentElement, HelpCategory.Provider));
        }
Esempio n. 34
0
        /// <summary>
        /// Prepends mshsnapin id to the cmdlet name and adds the result to help cache.
        /// </summary>
        /// <param name="mshSnapInId">PSSnapIn name that this cmdlet belongs to.</param>
        /// <param name="cmdletName">Name of the cmdlet.</param>
        /// <param name="helpInfo">Help object for the cmdlet.</param>
        private void AddToCommandCache(string mshSnapInId, string cmdletName, MamlCommandHelpInfo helpInfo)
        {
            Debug.Assert(!string.IsNullOrEmpty(cmdletName), "Cmdlet Name should not be null or empty.");

            string key = cmdletName;

            // Add snapin qualified type name for this command at the top..
            // this will enable customizations of the help object.
            helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
                "MamlCommandHelpInfo#{0}#{1}", mshSnapInId, cmdletName));

            if (!string.IsNullOrEmpty(mshSnapInId))
            {
                key = mshSnapInId + "\\" + key;
                // Add snapin name to the typenames of this object
                helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
                    "MamlCommandHelpInfo#{0}", mshSnapInId));
            }

            AddCache(key, helpInfo);
        }
Esempio n. 35
0
        /// <summary>
        /// Get provider specific help info.
        /// </summary>
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            if (InternalTestHooks.BypassOnlineHelpRetrieval)
            {
                // By returning null, we force get-help to return generic help
                // which includes a helpUri that points to the fwlink defined in the cmdlet code.
                return(null);
            }

            // Get the provider.
            ProviderInfo          providerInfo          = null;
            PSDriveInfo           driveInfo             = null;
            string                resolvedProviderPath  = null;
            CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext);

            try
            {
                string psPath = _requestedPath;
                if (string.IsNullOrEmpty(_requestedPath))
                {
                    psPath = _pathIntrinsics.CurrentLocation.Path;
                }

                resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath(
                    psPath,
                    cmdletProviderContext,
                    out providerInfo,
                    out driveInfo);
            }
            // ignore exceptions caused by provider resolution
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }

            if (providerInfo == null)
            {
                return(null);
            }

            // Does the provider know how to generate MAML.
            CmdletProvider cmdletProvider        = providerInfo.CreateInstance();
            ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp;

            // Under JEA sessions the resolvedProviderPath will be null, we should allow get-help to continue.
            if (provider == null)
            {
                return(null);
            }

            bool isJEASession = false;

            if (this._executionContext.InitialSessionState != null && this._executionContext.InitialSessionState.Providers != null && providerInfo != null)
            {
                foreach (
                    Runspaces.SessionStateProviderEntry sessionStateProvider in
                    this._executionContext.InitialSessionState.Providers[providerInfo.Name])
                {
                    if (sessionStateProvider.Visibility == SessionStateEntryVisibility.Private)
                    {
                        isJEASession = true;
                        break;
                    }
                }
            }

            if (resolvedProviderPath == null)
            {
                if (isJEASession)
                {
                    return(null);
                }
                else
                {
                    throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
                }
            }

            // ok we have path and valid provider that supplys content..initialize the provider
            // and get the help content for the path.
            cmdletProvider.Start(providerInfo, cmdletProviderContext);
            // There should be exactly one resolved path.
            string providerPath = resolvedProviderPath;
            // Get the MAML help info. Don't catch exceptions thrown by provider.
            string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath);

            if (string.IsNullOrEmpty(mamlXmlString))
            {
                return(null);
            }
            // process the MAML content only if it is non-empty.
            XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument(
                mamlXmlString,
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */
            MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider);

            return(providerSpecificHelpInfo);
        }
Esempio n. 36
0
        /// <summary>
        /// Create a MamlCommandHelpInfo object from an XmlNode.
        /// </summary>
        /// <param name="xmlNode">xmlNode that contains help info</param>
        /// <param name="helpCategory">help category this maml object fits into</param>
        /// <returns>MamlCommandHelpInfo object created</returns>
        internal static MamlCommandHelpInfo Load(XmlNode xmlNode, HelpCategory helpCategory)
        {
            MamlCommandHelpInfo mamlCommandHelpInfo = new MamlCommandHelpInfo(xmlNode, helpCategory);

            if (String.IsNullOrEmpty(mamlCommandHelpInfo.Name))
                return null;

            mamlCommandHelpInfo.AddCommonHelpProperties();

            return mamlCommandHelpInfo;
        }