コード例 #1
0
ファイル: ProviderHelpInfo.cs プロジェクト: nickchal/pash
 internal static ProviderHelpInfo Load(System.Xml.XmlNode xmlNode)
 {
     ProviderHelpInfo info = new ProviderHelpInfo(xmlNode);
     if (string.IsNullOrEmpty(info.Name))
     {
         return null;
     }
     info.AddCommonHelpProperties();
     return info;
 }
コード例 #2
0
 internal static ProviderHelpInfo Load(XmlNode xmlNode)
 {
     using (ProviderHelpInfo.tracer.TraceMethod())
       {
     ProviderHelpInfo providerHelpInfo = new ProviderHelpInfo(xmlNode);
     if (string.IsNullOrEmpty(providerHelpInfo.Name))
       return (ProviderHelpInfo) null;
     providerHelpInfo.AddCommonHelpProperties();
     return providerHelpInfo;
       }
 }
コード例 #3
0
        internal static ProviderHelpInfo Load(System.Xml.XmlNode xmlNode)
        {
            ProviderHelpInfo info = new ProviderHelpInfo(xmlNode);

            if (string.IsNullOrEmpty(info.Name))
            {
                return(null);
            }
            info.AddCommonHelpProperties();
            return(info);
        }
コード例 #4
0
        /// <summary>
        /// Create providerHelpInfo from an xmlNode
        /// </summary>
        /// <param name="xmlNode">xml node that contains the provider help info</param>
        /// <returns>the providerHelpInfo object created</returns>
        internal static ProviderHelpInfo Load(XmlNode xmlNode)
        {
            ProviderHelpInfo providerHelpInfo = new ProviderHelpInfo(xmlNode);

            if (String.IsNullOrEmpty(providerHelpInfo.Name))
            {
                return(null);
            }

            providerHelpInfo.AddCommonHelpProperties();

            return(providerHelpInfo);
        }
コード例 #5
0
        /// <summary>
        /// Process a helpInfo forwarded from other providers (normally commandHelpProvider)
        /// </summary>
        /// <remarks>
        /// For command help info, this will
        ///     1. check whether provider-specific commandlet help exists.
        ///     2. merge found provider-specific help with commandlet help provided.
        /// </remarks>
        /// <param name="helpInfo">helpInfo forwarded in</param>
        /// <param name="helpRequest">help request object</param>
        /// <returns>The help info object after processing</returns>
        override internal HelpInfo ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            if (helpInfo == null)
            {
                return(null);
            }

            if (helpInfo.HelpCategory != HelpCategory.Command)
            {
                return(helpInfo);
            }

            string providerName = helpRequest.Provider;

            if (String.IsNullOrEmpty(providerName))
            {
                providerName = this._sessionState.Path.CurrentLocation.Provider.Name;
            }

            HelpRequest providerHelpRequest = helpRequest.Clone();

            providerHelpRequest.Target = providerName;

            ProviderHelpInfo providerHelpInfo = (ProviderHelpInfo)this.ExactMatchHelp(providerHelpRequest);

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

            CommandHelpInfo commandHelpInfo = (CommandHelpInfo)helpInfo;

            CommandHelpInfo result = commandHelpInfo.MergeProviderSpecificHelp(providerHelpInfo.GetCmdletHelp(commandHelpInfo.Name), providerHelpInfo.GetDynamicParameterHelp(helpRequest.DynamicParameters));

            // Reset ForwardHelpCategory for the helpinfo to be returned so that it will not be forwarded back again.
            result.ForwardHelpCategory = HelpCategory.None;

            return(result);
        }
コード例 #6
0
 private void LoadHelpFile(ProviderInfo providerInfo)
 {
     using (ProviderHelpProvider.tracer.TraceMethod())
     {
         string str1 = providerInfo != null ? providerInfo.HelpFile : throw ProviderHelpProvider.tracer.NewArgumentNullException(nameof(providerInfo));
         if (string.IsNullOrEmpty(str1) || this._helpFiles.Contains((object)str1))
         {
             return;
         }
         string              file        = str1;
         PSSnapInInfo        psSnapIn    = providerInfo.PSSnapIn;
         Collection <string> searchPaths = new Collection <string>();
         if (psSnapIn != null)
         {
             file = Path.Combine(psSnapIn.ApplicationBase, str1);
         }
         else if (providerInfo.Module != null && !string.IsNullOrEmpty(providerInfo.Module.Path))
         {
             file = Path.Combine(providerInfo.Module.ModuleBase, str1);
         }
         else
         {
             searchPaths.Add(this.GetDefaultShellSearchPath());
             searchPaths.Add(ProviderHelpProvider.GetProviderAssemblyPath(providerInfo));
         }
         string str2 = MUIFileSearcher.LocateFile(file, searchPaths);
         if (string.IsNullOrEmpty(str2))
         {
             throw new FileNotFoundException(str1);
         }
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(str2);
         this._helpFiles[(object)str1] = (object)0;
         XmlNode xmlNode = (XmlNode)null;
         if (xmlDocument.HasChildNodes)
         {
             for (int i = 0; i < xmlDocument.ChildNodes.Count; ++i)
             {
                 XmlNode childNode = xmlDocument.ChildNodes[i];
                 if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     xmlNode = childNode;
                     break;
                 }
             }
         }
         if (xmlNode == null)
         {
             return;
         }
         using (this.HelpSystem.Trace(str2))
         {
             if (!xmlNode.HasChildNodes)
             {
                 return;
             }
             for (int i = 0; i < xmlNode.ChildNodes.Count; ++i)
             {
                 XmlNode childNode = xmlNode.ChildNodes[i];
                 if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     HelpInfo helpInfo = (HelpInfo)ProviderHelpInfo.Load(childNode);
                     if (helpInfo != null)
                     {
                         this.HelpSystem.TraceErrors(helpInfo.Errors);
                         helpInfo.FullHelp.TypeNames.Insert(0, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}#{1}", (object)providerInfo.PSSnapInName, (object)helpInfo.Name));
                         if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                         {
                             helpInfo.FullHelp.Properties.Add((PSPropertyInfo) new PSNoteProperty("PSSnapIn", (object)providerInfo.PSSnapIn));
                             helpInfo.FullHelp.TypeNames.Insert(1, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}", (object)providerInfo.PSSnapInName));
                         }
                         this.AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo);
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Load help file provided.
        /// </summary>
        /// <remarks>
        /// This will load providerHelpInfo from help file into help cache.
        /// </remarks>
        /// <param name="providerInfo">providerInfo for which to locate help.</param>
        private void LoadHelpFile(ProviderInfo providerInfo)
        {
            if (providerInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("providerInfo");
            }

            string helpFile = providerInfo.HelpFile;

            if (String.IsNullOrEmpty(helpFile) || _helpFiles.Contains(helpFile))
            {
                return;
            }

            string helpFileToLoad = helpFile;

            // Get the mshsnapinfo object for this cmdlet.
            PSSnapInInfo mshSnapInInfo = providerInfo.PSSnapIn;

            // Search fallback
            // 1. If PSSnapInInfo exists, then always look in the application base
            //    of the mshsnapin
            // Otherwise,
            //    Look in the default search path and cmdlet assembly path
            Collection <String> searchPaths = new Collection <String>();

            if (mshSnapInInfo != null)
            {
                Diagnostics.Assert(!string.IsNullOrEmpty(mshSnapInInfo.ApplicationBase),
                                   "Application Base is null or empty.");
                // not minishell case..
                // we have to search only in the application base for a mshsnapin...
                // if you create an absolute path for helpfile, then MUIFileSearcher
                // will look only in that path.
                helpFileToLoad = Path.Combine(mshSnapInInfo.ApplicationBase, helpFile);
            }
            else if ((providerInfo.Module != null) && (!string.IsNullOrEmpty(providerInfo.Module.Path)))
            {
                helpFileToLoad = Path.Combine(providerInfo.Module.ModuleBase, helpFile);
            }
            else
            {
                searchPaths.Add(GetDefaultShellSearchPath());
                searchPaths.Add(GetProviderAssemblyPath(providerInfo));
            }

            string location = MUIFileSearcher.LocateFile(helpFileToLoad, searchPaths);

            if (String.IsNullOrEmpty(location))
            {
                throw new FileNotFoundException(helpFile);
            }

            XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument(
                new FileInfo(location),
                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.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                return;
            }

            using (this.HelpSystem.Trace(location))
            {
                if (helpItemsNode.HasChildNodes)
                {
                    for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++)
                    {
                        XmlNode node = helpItemsNode.ChildNodes[i];
                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = ProviderHelpInfo.Load(node);

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                // Add snapin qualified type name for this command..
                                // this will enable customizations of the help object.
                                helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
                                                                                    "ProviderHelpInfo#{0}#{1}", providerInfo.PSSnapInName, helpInfo.Name));

                                if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                                {
                                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn));
                                    helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
                                                                                        "ProviderHelpInfo#{0}", providerInfo.PSSnapInName));
                                }
                                AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo);
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: ProviderHelpInfo.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Create providerHelpInfo from an xmlNode
        /// </summary>
        /// <param name="xmlNode">xml node that contains the provider help info</param>
        /// <returns>the providerHelpInfo object created</returns>
        internal static ProviderHelpInfo Load(XmlNode xmlNode)
        {
            ProviderHelpInfo providerHelpInfo = new ProviderHelpInfo(xmlNode);

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

            providerHelpInfo.AddCommonHelpProperties();

            return providerHelpInfo;
        }
コード例 #9
0
        private void LoadHelpFile(ProviderInfo providerInfo)
        {
            if (providerInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("providerInfo");
            }
            string helpFile = providerInfo.HelpFile;

            if (!string.IsNullOrEmpty(helpFile) && !this._helpFiles.Contains(helpFile))
            {
                string              file        = helpFile;
                PSSnapInInfo        pSSnapIn    = providerInfo.PSSnapIn;
                Collection <string> searchPaths = new Collection <string>();
                if (pSSnapIn != null)
                {
                    file = Path.Combine(pSSnapIn.ApplicationBase, helpFile);
                }
                else if ((providerInfo.Module != null) && !string.IsNullOrEmpty(providerInfo.Module.Path))
                {
                    file = Path.Combine(providerInfo.Module.ModuleBase, helpFile);
                }
                else
                {
                    searchPaths.Add(base.GetDefaultShellSearchPath());
                    searchPaths.Add(GetProviderAssemblyPath(providerInfo));
                }
                string str3 = MUIFileSearcher.LocateFile(file, searchPaths);
                if (string.IsNullOrEmpty(str3))
                {
                    throw new FileNotFoundException(helpFile);
                }
                XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(str3), false, null);
                this._helpFiles[helpFile] = 0;
                System.Xml.XmlNode node = 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.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            node = node2;
                            break;
                        }
                    }
                }
                if (node != null)
                {
                    using (base.HelpSystem.Trace(str3))
                    {
                        if (node.HasChildNodes)
                        {
                            for (int j = 0; j < node.ChildNodes.Count; j++)
                            {
                                System.Xml.XmlNode xmlNode = node.ChildNodes[j];
                                if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0))
                                {
                                    HelpInfo helpInfo = ProviderHelpInfo.Load(xmlNode);
                                    if (helpInfo != null)
                                    {
                                        base.HelpSystem.TraceErrors(helpInfo.Errors);
                                        helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}#{1}", new object[] { providerInfo.PSSnapInName, helpInfo.Name }));
                                        if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                                        {
                                            helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn));
                                            helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}", new object[] { providerInfo.PSSnapInName }));
                                        }
                                        base.AddCache(providerInfo.PSSnapInName + @"\" + helpInfo.Name, helpInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }