示例#1
0
 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;
     }
 }
示例#2
0
        /// <summary>
        /// Forward help to the help provider with type forwardHelpCategory.
        ///
        /// This is used in the following known scenarios so far
        ///     1. Alias: helpInfo returned by Alias is not what end user needed.
        ///               The real help can be retrieved from Command help provider.
        ///
        /// </summary>
        /// <param name="helpInfo"></param>
        /// <param name="helpRequest">Help request object</param>
        /// <returns>Never returns null.</returns>
        /// <remarks>helpInfos is not null or empty.</remarks>
        private IEnumerable <HelpInfo> ForwardHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            Collection <HelpInfo> result = new Collection <HelpInfo>();

            // findout if this helpInfo needs to be processed further..
            if (helpInfo.ForwardHelpCategory == HelpCategory.None && string.IsNullOrEmpty(helpInfo.ForwardTarget))
            {
                // this helpInfo is final...so store this in result
                // and move on..
                yield return(helpInfo);
            }
            else
            {
                // Find out a capable provider to process this request...
                HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory;
                bool         isHelpInfoProcessed = false;
                for (int i = 0; i < this.HelpProviders.Count; i++)
                {
                    HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i];
                    if ((helpProvider.HelpCategory & forwardHelpCategory) != HelpCategory.None)
                    {
                        isHelpInfoProcessed = true;
                        // If this help info is processed by this provider already, break
                        // out of the provider loop...
                        foreach (HelpInfo fwdResult in helpProvider.ProcessForwardedHelp(helpInfo, helpRequest))
                        {
                            // Add each helpinfo to our repository
                            foreach (HelpInfo fHelpInfo in ForwardHelp(fwdResult, helpRequest))
                            {
                                yield return(fHelpInfo);
                            }

                            // get out of the provider loop..
                            yield break;
                        }
                    }
                }

                if (!isHelpInfoProcessed)
                {
                    // we are here because no help provider processed the helpinfo..
                    // so add this to our repository..
                    yield return(helpInfo);
                }
            }
        }
示例#3
0
 private void GetAndWriteParameterInfo(HelpInfo helpInfo)
 {
     tracer.WriteLine("Searching parameters for {0}", new object[] { helpInfo.Name });
     PSObject[] parameter = helpInfo.GetParameter(this._parameter);
     if ((parameter == null) || (parameter.Length == 0))
     {
         Exception exception = PSTraceSource.NewArgumentException("Parameter", "HelpErrors", "NoParmsFound", new object[] { this._parameter });
         base.WriteError(new ErrorRecord(exception, "NoParmsFound", ErrorCategory.InvalidArgument, helpInfo));
     }
     else
     {
         foreach (PSObject obj2 in parameter)
         {
             base.WriteObject(obj2);
         }
     }
 }
        /// <summary>
        /// Load help file based on the file path.
        /// </summary>
        /// <param name="path">file path to load help from</param>
        /// <returns>Help info object loaded from the file</returns>
        private HelpInfo LoadHelpFile(string path)
        {
            string fileName = Path.GetFileName(path);

            //Bug906435: Get-help for special devices throws an exception
            //There might be situations where path does not end with .help.txt extension
            //The assumption that path ends with .help.txt is broken under special
            //conditions when user uses "get-help" with device names like "prn","com1" etc.
            //First check whether path ends with .help.txt.

            // If path does not end with ".help.txt" return.
            if (!path.EndsWith(".help.txt", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            string name = fileName.Substring(0, fileName.Length - 9 /* ".help.txt".Length */);

            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            HelpInfo helpInfo = GetCache(path);

            if (helpInfo != null)
            {
                return(helpInfo);
            }

            string helpText = null;

            using (TextReader tr = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                helpText = tr.ReadToEnd();
            }
            // Add this file into _helpFiles hashtable to prevent it to be loaded again.
            _helpFiles[path] = 0;
            helpInfo         = HelpFileHelpInfo.GetHelpInfo(name, helpText, path);

            AddCache(path, helpInfo);

            return(helpInfo);
        }
示例#5
0
 private void LoadGlossaryDiv(System.Xml.XmlNode xmlNode)
 {
     if (xmlNode != null)
     {
         for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
         {
             System.Xml.XmlNode node = xmlNode.ChildNodes[i];
             if ((node.NodeType == XmlNodeType.Element) && (string.Compare(node.Name, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0))
             {
                 HelpInfo helpInfo = null;
                 helpInfo = GlossaryHelpInfo.Load(node);
                 if (helpInfo != null)
                 {
                     base.HelpSystem.TraceErrors(helpInfo.Errors);
                     base.AddCache(helpInfo.Name, helpInfo);
                 }
             }
         }
     }
 }
示例#6
0
 private void LoadFaqDiv(XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return;
     }
     for (int i = 0; i < xmlNode.ChildNodes.Count; ++i)
     {
         XmlNode childNode = xmlNode.ChildNodes[i];
         if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "faqEntry", StringComparison.OrdinalIgnoreCase) == 0)
         {
             HelpInfo helpInfo = (HelpInfo)FaqHelpInfo.Load(childNode);
             if (helpInfo != null)
             {
                 this.HelpSystem.TraceErrors(helpInfo.Errors);
                 this.AddCache(helpInfo.Name, helpInfo);
             }
         }
     }
 }
示例#7
0
        /// <summary>
        /// Get the help in for the PS Class Info.        ///
        /// </summary>
        /// <param name="searcher">Searcher for PS Classes.</param>
        /// <returns>Next HelpInfo object.</returns>
        private IEnumerable <HelpInfo> GetHelpInfo(PSClassSearcher searcher)
        {
            while (searcher.MoveNext())
            {
                PSClassInfo current = ((IEnumerator <PSClassInfo>)searcher).Current;

                string moduleName = current.Module.Name;
                string moduleDir  = current.Module.ModuleBase;

                if (!string.IsNullOrEmpty(moduleName) && !string.IsNullOrEmpty(moduleDir))
                {
                    string helpFileToFind = moduleName + "-Help.xml";

                    string helpFileName = null;

                    Collection <string> searchPaths = new Collection <string>();
                    searchPaths.Add(moduleDir);

                    string externalHelpFile = current.HelpFile;

                    if (!string.IsNullOrEmpty(externalHelpFile))
                    {
                        FileInfo      helpFileInfo = new FileInfo(externalHelpFile);
                        DirectoryInfo dirToSearch  = helpFileInfo.Directory;

                        if (dirToSearch.Exists)
                        {
                            searchPaths.Add(dirToSearch.FullName);
                            helpFileToFind = helpFileInfo.Name; // If external help file is specified. Then use it.
                        }
                    }

                    HelpInfo helpInfo = GetHelpInfoFromHelpFile(current, helpFileToFind, searchPaths, true, out helpFileName);

                    if (helpInfo != null)
                    {
                        yield return(helpInfo);
                    }
                }
            }
        }
示例#8
0
 private IEnumerable <HelpInfo> DoGetHelp(HelpRequest helpRequest)
 {
     this._lastErrors.Clear();
     this._searchPaths      = null;
     this._lastHelpCategory = helpRequest.HelpCategory;
     if (string.IsNullOrEmpty(helpRequest.Target))
     {
         HelpInfo defaultHelp = this.GetDefaultHelp();
         if (defaultHelp != null)
         {
             yield return(defaultHelp);
         }
         yield return(null);
     }
     else
     {
         bool iteratorVariable1 = false;
         if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))
         {
             foreach (HelpInfo iteratorVariable2 in this.ExactMatchHelp(helpRequest))
             {
                 iteratorVariable1 = true;
                 yield return(iteratorVariable2);
             }
         }
         if (!iteratorVariable1)
         {
             foreach (HelpInfo iteratorVariable3 in this.SearchHelp(helpRequest))
             {
                 iteratorVariable1 = true;
                 yield return(iteratorVariable3);
             }
             if ((!iteratorVariable1 && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) && (this.LastErrors.Count == 0))
             {
                 Exception   exception = new HelpNotFoundException(helpRequest.Target);
                 ErrorRecord item      = new ErrorRecord(exception, "HelpNotFound", ErrorCategory.ResourceUnavailable, null);
                 this.LastErrors.Add(item);
             }
         }
     }
 }
示例#9
0
        /// <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;
            }
        }
示例#10
0
        private IEnumerable <HelpInfo> ForwardHelp(
            HelpInfo helpInfo,
            HelpRequest helpRequest)
        {
            Collection <HelpInfo> collection = new Collection <HelpInfo>();

            if (helpInfo.ForwardHelpCategory == HelpCategory.None && string.IsNullOrEmpty(helpInfo.ForwardTarget))
            {
                yield return(helpInfo);
            }
            else
            {
                HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory;
                bool         isHelpInfoProcessed = false;
                for (int i = 0; i < this.HelpProviders.Count; ++i)
                {
                    HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i];
                    if ((helpProvider.HelpCategory & forwardHelpCategory) == forwardHelpCategory)
                    {
                        isHelpInfoProcessed = true;
                        using (IEnumerator <HelpInfo> enumerator = helpProvider.ProcessForwardedHelp(helpInfo, helpRequest).GetEnumerator())
                        {
                            if (enumerator.MoveNext())
                            {
                                HelpInfo fwdResult = enumerator.Current;
                                foreach (HelpInfo helpInfo1 in this.ForwardHelp(fwdResult, helpRequest))
                                {
                                    yield return(helpInfo1);
                                }
                                yield break;
                            }
                        }
                    }
                }
                if (!isHelpInfoProcessed)
                {
                    yield return(helpInfo);
                }
            }
        }
示例#11
0
        internal override IEnumerable <HelpInfo> ExactMatchHelp(
            HelpRequest helpRequest)
        {
            using (HelpFileHelpProvider.tracer.TraceMethod())
            {
                int    countHelpInfosFound       = 0;
                string helpFileName              = helpRequest.Target + ".help.txt";
                Collection <string> filesMatched = MUIFileSearcher.SearchFiles(helpFileName, this.GetSearchPaths());
                foreach (string str in filesMatched)
                {
                    if (!this._helpFiles.ContainsKey((object)str))
                    {
                        try
                        {
                            this.LoadHelpFile(str);
                        }
                        catch (IOException ex)
                        {
                            this.ReportHelpFileError((Exception)ex, helpRequest.Target, str);
                        }
                        catch (SecurityException ex)
                        {
                            this.ReportHelpFileError((Exception)ex, helpRequest.Target, str);
                        }
                    }
                    HelpInfo helpInfo = this.GetCache(str);
                    if (helpInfo != null)
                    {
                        ++countHelpInfosFound;
                        yield return(helpInfo);

                        if (countHelpInfosFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0)
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#12
0
 private IEnumerable <HelpInfo> DoGetHelp(HelpRequest helpRequest)
 {
     this._lastErrors.Clear();
     this._searchPaths      = (Collection <string>)null;
     this._lastHelpCategory = helpRequest.HelpCategory;
     if (string.IsNullOrEmpty(helpRequest.Target))
     {
         HelpInfo helpInfo = this.GetDefaultHelp();
         if (helpInfo != null)
         {
             yield return(helpInfo);
         }
         yield return((HelpInfo)null);
     }
     else
     {
         bool isMatchFound = false;
         if (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))
         {
             foreach (HelpInfo helpInfo in this.ExactMatchHelp(helpRequest))
             {
                 isMatchFound = true;
                 yield return(helpInfo);
             }
         }
         if (!isMatchFound)
         {
             foreach (HelpInfo helpInfo in this.SearchHelp(helpRequest))
             {
                 isMatchFound = true;
                 yield return(helpInfo);
             }
             if (!isMatchFound && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target) && this.LastErrors.Count == 0)
             {
                 this.LastErrors.Add(new ErrorRecord((Exception) new HelpNotFoundException(helpRequest.Target), "HelpNotFound", ErrorCategory.ResourceUnavailable, (object)null));
             }
         }
     }
 }
        /// <summary>
        /// Get the help in for the DscResource Info.        ///
        /// </summary>
        /// <param name="searcher">Searcher for DscResources.</param>
        /// <returns>Next HelpInfo object.</returns>
        private IEnumerable <HelpInfo> GetHelpInfo(DscResourceSearcher searcher)
        {
            while (searcher.MoveNext())
            {
                DscResourceInfo current = ((IEnumerator <DscResourceInfo>)searcher).Current;

                string moduleName = null;
                string moduleDir  = current.ParentPath;

                // for binary modules, current.Module is empty.
                // in such cases use the leaf folder of ParentPath as filename.
                if (current.Module != null)
                {
                    moduleName = current.Module.Name;
                }
                else if (!String.IsNullOrEmpty(moduleDir))
                {
                    string[] splitPath = moduleDir.Split(Utils.Separators.Backslash);
                    moduleName = splitPath[splitPath.Length - 1];
                }

                if (!String.IsNullOrEmpty(moduleName) && !String.IsNullOrEmpty(moduleDir))
                {
                    string helpFileToFind = moduleName + "-Help.xml";

                    string helpFileName = null;

                    Collection <string> searchPaths = new Collection <string>();
                    searchPaths.Add(moduleDir);

                    HelpInfo helpInfo = GetHelpInfoFromHelpFile(current, helpFileToFind, searchPaths, true, out helpFileName);

                    if (helpInfo != null)
                    {
                        yield return(helpInfo);
                    }
                }
            }
        }
示例#14
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);
        }
        /// <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;
            }
        }
示例#16
0
 private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     if (helpRequest != null)
     {
         if ((helpRequest.HelpCategory & helpInfo.HelpCategory) == System.Management.Automation.HelpCategory.None)
         {
             return(false);
         }
         if (!Match(helpInfo.Component, helpRequest.Component))
         {
             return(false);
         }
         if (!Match(helpInfo.Role, helpRequest.Role))
         {
             return(false);
         }
         if (!Match(helpInfo.Functionality, helpRequest.Functionality))
         {
             return(false);
         }
     }
     return(true);
 }
 internal override bool IsHelpRequested(out string helpTarget, out HelpCategory helpCategory)
 {
     if (((base.arguments != null) && (base.CommandInfo != null)) && (!string.IsNullOrEmpty(base.CommandInfo.Name) && (this._scriptBlock != null)))
     {
         foreach (CommandParameterInternal internal2 in base.arguments)
         {
             if (internal2.IsDashQuestion())
             {
                 string str;
                 Dictionary <Ast, Token[]> scriptBlockTokenCache = new Dictionary <Ast, Token[]>();
                 HelpInfo info = this._scriptBlock.GetHelpInfo(base.Context, base.CommandInfo, false, scriptBlockTokenCache, out str, out str);
                 if (info == null)
                 {
                     break;
                 }
                 helpTarget   = info.Name;
                 helpCategory = info.HelpCategory;
                 return(true);
             }
         }
     }
     return(base.IsHelpRequested(out helpTarget, out helpCategory));
 }
示例#18
0
 private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     if (helpRequest != null)
     {
         if ((helpRequest.HelpCategory & helpInfo.HelpCategory) == System.Management.Automation.HelpCategory.None)
         {
             return false;
         }
         if (!Match(helpInfo.Component, helpRequest.Component))
         {
             return false;
         }
         if (!Match(helpInfo.Role, helpRequest.Role))
         {
             return false;
         }
         if (!Match(helpInfo.Functionality, helpRequest.Functionality))
         {
             return false;
         }
     }
     return true;
 }
示例#19
0
 internal override IEnumerable <HelpInfo> ExactMatchHelp(
     HelpRequest helpRequest)
 {
     using (AliasHelpProvider.tracer.TraceMethod())
     {
         CommandInfo commandInfo = (CommandInfo)null;
         try
         {
             commandInfo = this._commandDiscovery.LookupCommandInfo(helpRequest.Target);
         }
         catch (CommandNotFoundException ex)
         {
         }
         if (commandInfo != null && commandInfo.CommandType == CommandTypes.Alias)
         {
             AliasInfo aliasInfo = (AliasInfo)commandInfo;
             HelpInfo  helpInfo  = (HelpInfo)AliasHelpInfo.GetHelpInfo(aliasInfo);
             if (helpInfo != null)
             {
                 yield return(helpInfo);
             }
         }
     }
 }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xmlNode"></param>
        private void LoadGlossaryDiv(XmlNode xmlNode)
        {
            if (xmlNode == null)
            {
                return;
            }

            for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
            {
                XmlNode node = xmlNode.ChildNodes[i];
                if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    HelpInfo helpInfo = null;

                    helpInfo = GlossaryHelpInfo.Load(node);

                    if (helpInfo != null)
                    {
                        this.HelpSystem.TraceErrors(helpInfo.Errors);
                        AddCache(helpInfo.Name, helpInfo);
                    }
                }
            }
        }
示例#21
0
        private HelpInfo GetHelpInfoFromWorkflow(CommandInfo workflow, bool reportErrors)
        {
            HelpInfo info = null;

            if (workflow.Module == null)
            {
                return(info);
            }
            if (workflow.Module.NestedModules != null)
            {
                foreach (PSModuleInfo info2 in workflow.Module.NestedModules)
                {
                    string str = Path.GetFileName(info2.Path) + "-Help.xml";
                    if (!this._helpFiles.Contains(str))
                    {
                        this.LoadHelpFile(Path.Combine(workflow.Module.ModuleBase, Thread.CurrentThread.CurrentCulture.Name, str), str, workflow.Name, reportErrors);
                    }
                    info = this.GetFromCommandCache(str, workflow) ?? info;
                    if (info != null)
                    {
                        return(info);
                    }
                }
            }
            if (info != null)
            {
                return(info);
            }
            string key = workflow.Module.Name + "-Help.xml";

            if (!this._helpFiles.Contains(key))
            {
                this.LoadHelpFile(Path.Combine(workflow.Module.ModuleBase, Thread.CurrentThread.CurrentCulture.Name, key), key, workflow.Name, reportErrors);
            }
            return(this.GetFromCommandCache(key, workflow) ?? info);
        }
示例#22
0
        internal override IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest)
        {
            int    iteratorVariable0 = 0;
            string pattern           = helpRequest.Target + ".help.txt";
            Collection <string> iteratorVariable2 = MUIFileSearcher.SearchFiles(pattern, this.GetSearchPaths());

            foreach (string iteratorVariable3 in iteratorVariable2)
            {
                if (!this._helpFiles.ContainsKey(iteratorVariable3))
                {
                    try
                    {
                        this.LoadHelpFile(iteratorVariable3);
                    }
                    catch (IOException exception)
                    {
                        this.ReportHelpFileError(exception, helpRequest.Target, iteratorVariable3);
                    }
                    catch (SecurityException exception2)
                    {
                        this.ReportHelpFileError(exception2, helpRequest.Target, iteratorVariable3);
                    }
                }
                HelpInfo cache = this.GetCache(iteratorVariable3);
                if (cache != null)
                {
                    iteratorVariable0++;
                    yield return(cache);

                    if ((iteratorVariable0 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0))
                    {
                        break;
                    }
                }
            }
        }
示例#23
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);
                            }
                        }
                    }
                }
            }
        }
示例#24
0
 internal virtual IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     helpInfo.ForwardHelpCategory ^= this.HelpCategory;
     yield return helpInfo;
 }
示例#25
0
        /// <summary>
        /// Search an alias help target.
        /// </summary>
        /// <remarks>
        /// This will,
        ///     a. use _sessionState object to get a list of alias that match the target.
        ///     b. for each alias, retrieve help info as in ExactMatchHelp.
        /// </remarks>
        /// <param name="helpRequest">Help request object.</param>
        /// <param name="searchOnlyContent">
        /// If true, searches for pattern in the help content. Individual
        /// provider can decide which content to search in.
        ///
        /// If false, searches for pattern in the command names.
        /// </param>
        /// <returns>A IEnumerable of helpinfo object.</returns>
        internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
        {
            // aliases do not have help content...so doing nothing in that case
            if (!searchOnlyContent)
            {
                string    target    = helpRequest.Target;
                string    pattern   = target;
                Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase);

                if (!WildcardPattern.ContainsWildcardCharacters(target))
                {
                    pattern += "*";
                }

                WildcardPattern matcher = WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase);
                IDictionary <string, AliasInfo> aliasTable = _sessionState.Internal.GetAliasTable();

                foreach (string name in aliasTable.Keys)
                {
                    if (matcher.IsMatch(name))
                    {
                        HelpRequest exactMatchHelpRequest = helpRequest.Clone();
                        exactMatchHelpRequest.Target = name;
                        // Duplicates??
                        foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest))
                        {
                            // Component/Role/Functionality match is done only for SearchHelp
                            // as "get-help * -category alias" should not forwad help to
                            // CommandHelpProvider..(ExactMatchHelp does forward help to
                            // CommandHelpProvider)
                            if (!Match(helpInfo, helpRequest))
                            {
                                continue;
                            }

                            if (hashtable.ContainsKey(name))
                            {
                                continue;
                            }

                            hashtable.Add(name, null);

                            yield return(helpInfo);
                        }
                    }
                }

                CommandSearcher searcher =
                    new CommandSearcher(
                        pattern,
                        SearchResolutionOptions.ResolveAliasPatterns, CommandTypes.Alias,
                        _context);

                while (searcher.MoveNext())
                {
                    CommandInfo current = ((IEnumerator <CommandInfo>)searcher).Current;

                    if (_context.CurrentPipelineStopping)
                    {
                        yield break;
                    }

                    AliasInfo alias = current as AliasInfo;

                    if (alias != null)
                    {
                        string      name = alias.Name;
                        HelpRequest exactMatchHelpRequest = helpRequest.Clone();
                        exactMatchHelpRequest.Target = name;

                        // Duplicates??
                        foreach (HelpInfo helpInfo in ExactMatchHelp(exactMatchHelpRequest))
                        {
                            // Component/Role/Functionality match is done only for SearchHelp
                            // as "get-help * -category alias" should not forwad help to
                            // CommandHelpProvider..(ExactMatchHelp does forward help to
                            // CommandHelpProvider)
                            if (!Match(helpInfo, helpRequest))
                            {
                                continue;
                            }

                            if (hashtable.ContainsKey(name))
                            {
                                continue;
                            }

                            hashtable.Add(name, null);

                            yield return(helpInfo);
                        }
                    }
                }

                foreach (CommandInfo current in ModuleUtils.GetMatchingCommands(pattern, _context, helpRequest.CommandOrigin))
                {
                    if (_context.CurrentPipelineStopping)
                    {
                        yield break;
                    }

                    AliasInfo alias = current as AliasInfo;

                    if (alias != null)
                    {
                        string name = alias.Name;

                        HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(alias);

                        if (hashtable.ContainsKey(name))
                        {
                            continue;
                        }

                        hashtable.Add(name, null);

                        yield return(helpInfo);
                    }
                }
            }
        }
示例#26
0
        internal override IEnumerable <HelpInfo> SearchHelp(
            HelpRequest helpRequest,
            bool searchOnlyContent)
        {
            using (ProviderHelpProvider.tracer.TraceMethod())
            {
                int             countOfHelpInfoObjectsFound = 0;
                string          target          = helpRequest.Target;
                string          pattern         = target;
                WildcardPattern wildCardPattern = (WildcardPattern)null;
                bool            decoratedSearch = !WildcardPattern.ContainsWildcardCharacters(target);
                if (!searchOnlyContent)
                {
                    if (decoratedSearch)
                    {
                        // ISSUE: reference to a compiler-generated field
                        this.\u003Cpattern\u003E5__d += "*";
                    }
                }
                else
                {
                    string pattern1 = helpRequest.Target;
                    if (decoratedSearch)
                    {
                        pattern1 = "*" + helpRequest.Target + "*";
                    }
                    wildCardPattern = new WildcardPattern(pattern1, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
                    pattern         = "*";
                }
                PSSnapinQualifiedName snapinQualifiedNameForPattern = PSSnapinQualifiedName.GetInstance(pattern);
                if (snapinQualifiedNameForPattern != null)
                {
                    foreach (ProviderInfo providerInfo in this._sessionState.Provider.GetAll())
                    {
                        if (providerInfo.IsMatch(pattern))
                        {
                            try
                            {
                                this.LoadHelpFile(providerInfo);
                            }
                            catch (IOException ex)
                            {
                                if (!decoratedSearch)
                                {
                                    this.ReportHelpFileError((Exception)ex, providerInfo.Name, providerInfo.HelpFile);
                                }
                            }
                            catch (SecurityException ex)
                            {
                                if (!decoratedSearch)
                                {
                                    this.ReportHelpFileError((Exception)ex, providerInfo.Name, providerInfo.HelpFile);
                                }
                            }
                            catch (XmlException ex)
                            {
                                if (!decoratedSearch)
                                {
                                    this.ReportHelpFileError((Exception)ex, providerInfo.Name, providerInfo.HelpFile);
                                }
                            }
                            HelpInfo helpInfo = this.GetCache(providerInfo.PSSnapInName + "\\" + providerInfo.Name);
                            if (helpInfo != null && (!searchOnlyContent || helpInfo.MatchPatternInContent(wildCardPattern)))
                            {
                                ++countOfHelpInfoObjectsFound;
                                yield return(helpInfo);

                                if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#27
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;
        }
示例#28
0
 /// <summary>
 /// Process a helpinfo forwarded over by another help provider. 
 /// 
 /// HelpProvider can choose to process the helpInfo or not, 
 /// 
 ///     1. If a HelpProvider chooses not to process the helpInfo, it can return null to indicate
 ///        helpInfo is not processed.
 ///     2. If a HelpProvider indeed processes the helpInfo, it should create a new helpInfo
 ///        object instead of modifying the passed-in helpInfo object. This is very important
 ///        since the helpInfo object passed in is usually stored in cache, which can 
 ///        used in later queries. 
 /// </summary>
 /// <param name="helpInfo">helpInfo passed over by another HelpProvider</param>
 /// <param name="helpRequest">help request object</param>        
 /// <returns></returns>
 internal virtual IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     // Win8: 508648. Remove the current provides category for resolving forward help as the current
     // help provider already process it.
     helpInfo.ForwardHelpCategory = helpInfo.ForwardHelpCategory ^ this.HelpCategory;
     yield return helpInfo;
 }
示例#29
0
        /// <summary>
        /// Process helpInfo forwarded over from other other providers, specificly AliasHelpProvider.
        /// This can return more than 1 helpinfo object.
        /// </summary>
        /// <param name="helpInfo">HelpInfo that is forwarded over</param>
        /// <param name="helpRequest">Help request object</param>        
        /// <returns>The result helpInfo objects after processing</returns>
        internal override IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            HelpCategory categoriesHandled = (HelpCategory.Alias
                | HelpCategory.ExternalScript | HelpCategory.Filter | HelpCategory.Function | HelpCategory.ScriptCommand | HelpCategory.Workflow);

            if ((helpInfo.HelpCategory & categoriesHandled) != 0)
            {
                HelpRequest commandHelpRequest = helpRequest.Clone();
                commandHelpRequest.Target = helpInfo.ForwardTarget;
                commandHelpRequest.CommandOrigin = CommandOrigin.Internal; // a public command can forward help to a private command

                // We may know what category to forward to.  If so, just set it.  If not, look up the
                // command and determine it's category.  For aliases, we definitely don't know the category
                // to forward to, so always do the lookup.
                if (helpInfo.ForwardHelpCategory != HelpCategory.None && helpInfo.HelpCategory != HelpCategory.Alias)
                {
                    commandHelpRequest.HelpCategory = helpInfo.ForwardHelpCategory;
                }
                else
                {
                    try
                    {
                        CommandInfo targetCommand = _context.CommandDiscovery.LookupCommandInfo(commandHelpRequest.Target);
                        commandHelpRequest.HelpCategory = targetCommand.HelpCategory;
                    }
                    catch (CommandNotFoundException)
                    {
                        // ignore errors for aliases pointing to non-existant commands
                    }
                }

                foreach (HelpInfo helpInfoToReturn in ExactMatchHelp(commandHelpRequest))
                {
                    yield return helpInfoToReturn;
                }
            }
            else
            {
                // command help provider can forward process only an AliasHelpInfo..
                // so returning the original help info here.
                yield return helpInfo;
            }
        }
示例#30
0
 private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
 {
     if (helpInfo != null)
     {
         if (showFullHelp && this.showOnlineHelp)
         {
             bool flag = false;
             tracer.WriteLine("Preparing to show help online.", new object[0]);
             Uri uriForOnlineHelp = helpInfo.GetUriForOnlineHelp();
             if (null != uriForOnlineHelp)
             {
                 flag = true;
                 this.LaunchOnlineHelp(uriForOnlineHelp);
             }
             else if (!flag)
             {
                 throw PSTraceSource.NewInvalidOperationException("HelpErrors", "NoURIFound", new object[0]);
             }
         }
         else if (showFullHelp && (this.ShowWindow != 0))
         {
             this.graphicalHostReflectionWrapper.CallStaticMethod("ShowHelpWindow", new object[] { helpInfo.FullHelp, this });
         }
         else if (showFullHelp)
         {
             if (!string.IsNullOrEmpty(this._parameter))
             {
                 this.GetAndWriteParameterInfo(helpInfo);
             }
             else
             {
                 PSObject sendToPipeline = this.TransformView(helpInfo.FullHelp);
                 sendToPipeline.IsHelpObject = true;
                 base.WriteObject(sendToPipeline);
             }
         }
         else
         {
             if (!string.IsNullOrEmpty(this._parameter))
             {
                 PSObject[] parameter = helpInfo.GetParameter(this._parameter);
                 if ((parameter == null) || (parameter.Length == 0))
                 {
                     return;
                 }
             }
             base.WriteObject(helpInfo.ShortHelp);
         }
     }
 }
示例#31
0
 internal virtual IEnumerable <HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     helpInfo.ForwardHelpCategory ^= this.HelpCategory;
     yield return(helpInfo);
 }
示例#32
0
        internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
        {
            string item = helpRequest.Target;
            Collection <string> iteratorVariable1 = new Collection <string>();
            WildcardPattern     pattern           = null;
            bool iteratorVariable3 = !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target);

            if (!searchOnlyContent)
            {
                if (iteratorVariable3)
                {
                    if (item.IndexOf('-') >= 0)
                    {
                        iteratorVariable1.Add(item + "*");
                    }
                    else
                    {
                        iteratorVariable1.Add("*" + item + "*");
                    }
                }
                else
                {
                    iteratorVariable1.Add(item);
                }
            }
            else
            {
                iteratorVariable1.Add("*");
                string target = helpRequest.Target;
                if (iteratorVariable3)
                {
                    target = "*" + helpRequest.Target + "*";
                }
                pattern = new WildcardPattern(target, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);
            }
            int       iteratorVariable4 = 0;
            Hashtable iteratorVariable5 = new Hashtable(StringComparer.OrdinalIgnoreCase);
            Hashtable iteratorVariable6 = new Hashtable(StringComparer.OrdinalIgnoreCase);

            foreach (string iteratorVariable7 in iteratorVariable1)
            {
                CommandSearcher commandSearcherForSearch = this.GetCommandSearcherForSearch(iteratorVariable7, this._context);
                while (commandSearcherForSearch.MoveNext())
                {
                    if (this._context.CurrentPipelineStopping)
                    {
                        break;
                    }
                    CommandInfo current    = commandSearcherForSearch.Current;
                    CmdletInfo  cmdletInfo = current as CmdletInfo;
                    HelpInfo    helpInfo   = null;
                    string      key        = null;
                    if (cmdletInfo != null)
                    {
                        helpInfo = this.GetHelpInfo(cmdletInfo, !iteratorVariable3);
                        key      = cmdletInfo.FullName;
                    }
                    else
                    {
                        IScriptCommandInfo scriptCommandInfo = current as IScriptCommandInfo;
                        if (scriptCommandInfo != null)
                        {
                            key      = current.Name;
                            helpInfo = this.GetHelpInfo(scriptCommandInfo, !iteratorVariable3, searchOnlyContent);
                        }
                    }
                    if (helpInfo != null)
                    {
                        if (!SessionState.IsVisible(helpRequest.CommandOrigin, current))
                        {
                            if (!iteratorVariable6.ContainsKey(key))
                            {
                                iteratorVariable6.Add(key, null);
                            }
                        }
                        else if ((!iteratorVariable5.ContainsKey(key) && Match(helpInfo, helpRequest, current)) && (!searchOnlyContent || helpInfo.MatchPatternInContent(pattern)))
                        {
                            iteratorVariable5.Add(key, null);
                            iteratorVariable4++;
                            yield return(helpInfo);

                            if ((iteratorVariable4 < helpRequest.MaxResults) || (helpRequest.MaxResults <= 0))
                            {
                                continue;
                            }
                            break;
                        }
                    }
                }
                if (this.HelpCategory == (System.Management.Automation.HelpCategory.Cmdlet | System.Management.Automation.HelpCategory.Alias))
                {
                    foreach (CommandInfo iteratorVariable13 in ModuleUtils.GetMatchingCommands(iteratorVariable7, this._context, helpRequest.CommandOrigin, false))
                    {
                        if (this._context.CurrentPipelineStopping)
                        {
                            break;
                        }
                        if (SessionState.IsVisible(helpRequest.CommandOrigin, iteratorVariable13))
                        {
                            CmdletInfo iteratorVariable14 = iteratorVariable13 as CmdletInfo;
                            HelpInfo   iteratorVariable15 = null;
                            string     fullName           = null;
                            if (iteratorVariable14 != null)
                            {
                                iteratorVariable15 = this.GetHelpInfo(iteratorVariable14, !iteratorVariable3);
                                fullName           = iteratorVariable14.FullName;
                            }
                            else
                            {
                                IScriptCommandInfo info2 = iteratorVariable13 as IScriptCommandInfo;
                                if (info2 != null)
                                {
                                    fullName           = iteratorVariable13.Name;
                                    iteratorVariable15 = this.GetHelpInfo(info2, !iteratorVariable3, searchOnlyContent);
                                }
                            }
                            if ((((iteratorVariable15 != null) && !iteratorVariable5.ContainsKey(fullName)) && (!iteratorVariable6.ContainsKey(fullName) && Match(iteratorVariable15, helpRequest, iteratorVariable13))) && (!searchOnlyContent || iteratorVariable15.MatchPatternInContent(pattern)))
                            {
                                iteratorVariable5.Add(fullName, null);
                                iteratorVariable4++;
                                yield return(iteratorVariable15);

                                if ((iteratorVariable4 >= helpRequest.MaxResults) && (helpRequest.MaxResults > 0))
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#33
0
 private IEnumerable<HelpInfo> ForwardHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     new Collection<HelpInfo>();
     if ((helpInfo.ForwardHelpCategory == HelpCategory.None) && string.IsNullOrEmpty(helpInfo.ForwardTarget))
     {
         yield return helpInfo;
     }
     else
     {
         HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory;
         bool iteratorVariable1 = false;
         for (int i = 0; i < this.HelpProviders.Count; i++)
         {
             HelpProvider iteratorVariable3 = (HelpProvider) this.HelpProviders[i];
             if ((iteratorVariable3.HelpCategory & forwardHelpCategory) != HelpCategory.None)
             {
                 iteratorVariable1 = true;
                 foreach (HelpInfo iteratorVariable4 in iteratorVariable3.ProcessForwardedHelp(helpInfo, helpRequest))
                 {
                     foreach (HelpInfo iteratorVariable5 in this.ForwardHelp(iteratorVariable4, helpRequest))
                     {
                         yield return iteratorVariable5;
                     }
                     goto Label_01FB;
                 }
             }
         }
         if (!iteratorVariable1)
         {
             yield return helpInfo;
         }
     }
 Label_01FB:
     yield break;
 }
示例#34
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);
        }
示例#35
0
        /// <summary>
        /// Search for provider help based on a search target.
        /// </summary>
        /// <param name="helpRequest">help request object</param>
        /// <param name="searchOnlyContent">
        /// If true, searches for pattern in the help content. Individual
        /// provider can decide which content to search in.
        ///
        /// If false, searches for pattern in the command names.
        /// </param>
        /// <returns></returns>
        internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent)
        {
            int    countOfHelpInfoObjectsFound = 0;
            string target  = helpRequest.Target;
            string pattern = target;
            // this will be used only when searchOnlyContent == true
            WildcardPattern wildCardPattern = null;

            bool decoratedSearch = !WildcardPattern.ContainsWildcardCharacters(target);

            if (!searchOnlyContent)
            {
                if (decoratedSearch)
                {
                    pattern += "*";
                }
            }
            else
            {
                string searchTarget = helpRequest.Target;
                if (decoratedSearch)
                {
                    searchTarget = "*" + helpRequest.Target + "*";
                }

                wildCardPattern = WildcardPattern.Get(searchTarget, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
                // search in all providers
                pattern = "*";
            }

            PSSnapinQualifiedName snapinQualifiedNameForPattern =
                PSSnapinQualifiedName.GetInstance(pattern);

            if (null == snapinQualifiedNameForPattern)
            {
                yield break;
            }

            foreach (ProviderInfo providerInfo in _sessionState.Provider.GetAll())
            {
                if (providerInfo.IsMatch(pattern))
                {
                    try
                    {
                        LoadHelpFile(providerInfo);
                    }
                    catch (IOException ioException)
                    {
                        if (!decoratedSearch)
                        {
                            ReportHelpFileError(ioException, providerInfo.Name, providerInfo.HelpFile);
                        }
                    }
                    catch (System.Security.SecurityException securityException)
                    {
                        if (!decoratedSearch)
                        {
                            ReportHelpFileError(securityException, providerInfo.Name, providerInfo.HelpFile);
                        }
                    }
                    catch (XmlException xmlException)
                    {
                        if (!decoratedSearch)
                        {
                            ReportHelpFileError(xmlException, providerInfo.Name, providerInfo.HelpFile);
                        }
                    }

                    HelpInfo helpInfo = GetCache(providerInfo.PSSnapInName + "\\" + providerInfo.Name);

                    if (helpInfo != null)
                    {
                        if (searchOnlyContent)
                        {
                            // ignore help objects that do not have pattern in its help
                            // content.
                            if (!helpInfo.MatchPatternInContent(wildCardPattern))
                            {
                                continue;
                            }
                        }

                        countOfHelpInfoObjectsFound++;
                        yield return(helpInfo);

                        if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0)
                        {
                            yield break;
                        }
                    }
                }
            }
        }
示例#36
0
        /// <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.
        /// </remarks>
        /// <param name="helpFile"></param>
        private void LoadHelpFile(string helpFile)
        {
            if (String.IsNullOrEmpty(helpFile))
            {
                return;
            }

            XmlDocument doc;

            try
            {
                doc = InternalDeserializer.LoadUnsafeXmlDocument(
                    new FileInfo(helpFile),
                    false, /* ignore whitespace, comments, etc. */
                    null); /* default maxCharactersInDocument */
            }
            catch (IOException ioException)
            {
                ErrorRecord errorRecord = new ErrorRecord(ioException, "HelpFileLoadFailure", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileLoadFailure", helpFile, ioException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (System.Security.SecurityException securityException)
            {
                ErrorRecord errorRecord = new ErrorRecord(securityException, "HelpFileNotAccessible", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotAccessible", helpFile, securityException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (XmlException xmlException)
            {
                ErrorRecord errorRecord = new ErrorRecord(xmlException, "HelpFileNotValid", ErrorCategory.SyntaxError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotValid", helpFile, xmlException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }

            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, "faq", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                return;
            }

            using (this.HelpSystem.Trace(helpFile))
            {
                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, "faqEntry", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = null;

                            helpInfo = FaqHelpInfo.Load(node);

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                AddCache(helpInfo.Name, helpInfo);
                            }
                            continue;
                        }

                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "faqDiv", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            LoadFaqDiv(node);
                        }
                    }
                }
            }
        }
示例#37
0
        /// <summary>
        /// Gets the parameter info for patterns identified Parameter property.
        /// Writes the parameter info(s) to the output stream. An error is thrown
        /// if a parameter with a given pattern is not found.
        /// </summary>
        /// <param name="helpInfo">HelpInfo Object to look for the parameter.</param>
        private void GetAndWriteParameterInfo(HelpInfo helpInfo)
        {
            s_tracer.WriteLine("Searching parameters for {0}", helpInfo.Name);
            PSObject[] pInfos = helpInfo.GetParameter(Parameter);

            if ((pInfos == null) || (pInfos.Length == 0))
            {
                Exception innerException = PSTraceSource.NewArgumentException("Parameter",
                    HelpErrors.NoParmsFound, Parameter);
                WriteError(new ErrorRecord(innerException, "NoParmsFound", ErrorCategory.InvalidArgument, helpInfo));
            }
            else
            {
                foreach (PSObject pInfo in pInfos)
                {
                    WriteObject(pInfo);
                }
            }
        }
示例#38
0
 private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest) => helpRequest == null || (helpRequest.HelpCategory & helpInfo.HelpCategory) != HelpCategory.None && AliasHelpProvider.Match(helpInfo.Component, helpRequest.Component) && (AliasHelpProvider.Match(helpInfo.Role, helpRequest.Role) && AliasHelpProvider.Match(helpInfo.Functionality, helpRequest.Functionality));
示例#39
0
 private void LoadHelpFile(string helpFile)
 {
     using (FaqHelpProvider.tracer.TraceMethod())
     {
         if (string.IsNullOrEmpty(helpFile))
         {
             return;
         }
         XmlDocument xmlDocument = new XmlDocument();
         try
         {
             xmlDocument.Load(helpFile);
         }
         catch (IOException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileLoadFailure", ErrorCategory.OpenError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileLoadFailure", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         catch (SecurityException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileNotAccessible", ErrorCategory.OpenError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotAccessible", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         catch (XmlException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileNotValid", ErrorCategory.SyntaxError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotValid", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         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, "faq", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     xmlNode = childNode;
                     break;
                 }
             }
         }
         if (xmlNode == null)
         {
             return;
         }
         using (this.HelpSystem.Trace(helpFile))
         {
             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, "faqEntry", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     HelpInfo helpInfo = (HelpInfo)FaqHelpInfo.Load(childNode);
                     if (helpInfo != null)
                     {
                         this.HelpSystem.TraceErrors(helpInfo.Errors);
                         this.AddCache(helpInfo.Name, helpInfo);
                     }
                 }
                 else if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "faqDiv", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     this.LoadFaqDiv(childNode);
                 }
             }
         }
     }
 }
示例#40
0
 internal override IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     ProviderCommandHelpInfo iteratorVariable0 = new ProviderCommandHelpInfo(helpInfo, helpRequest.ProviderContext);
     yield return iteratorVariable0;
 }
示例#41
0
 internal override IEnumerable<HelpInfo> ProcessForwardedHelp(HelpInfo helpInfo, HelpRequest helpRequest)
 {
     System.Management.Automation.HelpCategory iteratorVariable0 = System.Management.Automation.HelpCategory.Workflow | System.Management.Automation.HelpCategory.ExternalScript | System.Management.Automation.HelpCategory.Filter | System.Management.Automation.HelpCategory.Function | System.Management.Automation.HelpCategory.ScriptCommand | System.Management.Automation.HelpCategory.Alias;
     if ((helpInfo.HelpCategory & iteratorVariable0) != System.Management.Automation.HelpCategory.None)
     {
         HelpRequest iteratorVariable1 = helpRequest.Clone();
         iteratorVariable1.Target = helpInfo.ForwardTarget;
         iteratorVariable1.CommandOrigin = CommandOrigin.Internal;
         if ((helpInfo.ForwardHelpCategory != System.Management.Automation.HelpCategory.None) && (helpInfo.HelpCategory != System.Management.Automation.HelpCategory.Alias))
         {
             iteratorVariable1.HelpCategory = helpInfo.ForwardHelpCategory;
         }
         else
         {
             try
             {
                 CommandInfo commandInfo = this._context.CommandDiscovery.LookupCommandInfo(iteratorVariable1.Target);
                 iteratorVariable1.HelpCategory = commandInfo.HelpCategory;
             }
             catch (CommandNotFoundException)
             {
             }
         }
         IEnumerator<HelpInfo> enumerator = this.ExactMatchHelp(iteratorVariable1).GetEnumerator();
         while (enumerator.MoveNext())
         {
             HelpInfo current = enumerator.Current;
             yield return current;
         }
     }
     else
     {
         yield return helpInfo;
     }
 }
示例#42
0
        /// <summary>
        /// Forward help to the help provider with type forwardHelpCategory. 
        /// 
        /// This is used in the following known scenarios so far
        ///     1. Alias: helpInfo returned by Alias is not what end user needed. 
        ///               The real help can be retrieved from Command help provider.
        /// 
        /// </summary>
        /// <param name="helpInfo"></param>
        /// <param name="helpRequest">Help request object</param>        
        /// <returns>Never returns null.</returns>
        /// <remarks>helpInfos is not null or empty.</remarks>
        private IEnumerable<HelpInfo> ForwardHelp(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            Collection<HelpInfo> result = new Collection<HelpInfo>();
            // findout if this helpInfo needs to be processed further..
            if (helpInfo.ForwardHelpCategory == HelpCategory.None && string.IsNullOrEmpty(helpInfo.ForwardTarget))
            {
                // this helpInfo is final...so store this in result
                // and move on..
                yield return helpInfo;
            }
            else
            {
                // Find out a capable provider to process this request...
                HelpCategory forwardHelpCategory = helpInfo.ForwardHelpCategory;
                bool isHelpInfoProcessed = false;
                for (int i = 0; i < this.HelpProviders.Count; i++)
                {
                    HelpProvider helpProvider = (HelpProvider)this.HelpProviders[i];
                    if ((helpProvider.HelpCategory & forwardHelpCategory) != HelpCategory.None)
                    {
                        isHelpInfoProcessed = true;
                        // If this help info is processed by this provider already, break
                        // out of the provider loop...
                        foreach (HelpInfo fwdResult in helpProvider.ProcessForwardedHelp(helpInfo, helpRequest))
                        {
                            // Add each helpinfo to our repository
                            foreach (HelpInfo fHelpInfo in ForwardHelp(fwdResult, helpRequest))
                            {
                                yield return fHelpInfo;
                            }

                            // get out of the provider loop..
                            yield break;
                        }
                    }
                }

                if (!isHelpInfoProcessed)
                {
                    // we are here because no help provider processed the helpinfo..
                    // so add this to our repository..
                    yield return helpInfo;
                }
            }
        }
示例#43
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);
                     }
                 }
             }
         }
     }
 }
示例#44
0
        /// <summary>
        /// Helper method used to Write the help object onto the output
        /// stream or show online help (URI extracted from the HelpInfo)
        /// object.
        /// </summary>
        private void WriteObjectsOrShowOnlineHelp(HelpInfo helpInfo, bool showFullHelp)
        {
            if (helpInfo != null)
            {
                // online help can be showed only if showFullHelp is true..
                // showFullHelp will be false when the help tries to display multiple help topics..
                // -Online should not work when multiple help topics are displayed.
                if (showFullHelp && _showOnlineHelp)
                {
                    bool onlineUriFound = false;
                    // show online help
                    s_tracer.WriteLine("Preparing to show help online.");
                    Uri onlineUri = helpInfo.GetUriForOnlineHelp();
                    if (null != onlineUri)
                    {
                        onlineUriFound = true;
                        LaunchOnlineHelp(onlineUri);
                        return;
                    }

                    if (!onlineUriFound)
                    {
                        throw PSTraceSource.NewInvalidOperationException(HelpErrors.NoURIFound);
                    }
                }
                else if (showFullHelp && ShowWindow)
                {
#if !CORECLR
                    graphicalHostReflectionWrapper.CallStaticMethod("ShowHelpWindow", helpInfo.FullHelp, this);
#endif
                }
                else
                {
                    // show inline help
                    if (showFullHelp)
                    {
                        if (!string.IsNullOrEmpty(Parameter))
                        {
                            GetAndWriteParameterInfo(helpInfo);
                        }
                        else
                        {
                            PSObject objectToReturn = TransformView(helpInfo.FullHelp);
                            objectToReturn.IsHelpObject = true;
                            WriteObject(objectToReturn);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Parameter))
                        {
                            PSObject[] pInfos = helpInfo.GetParameter(Parameter);
                            if ((pInfos == null) || (pInfos.Length == 0))
                            {
                                return;
                            }
                        }

                        WriteObject(helpInfo.ShortHelp);
                    }
                }
            }
        }
示例#45
0
 internal void OverrideProviderSpecificHelpWithGenericHelp(HelpInfo genericHelpInfo)
 {
     PSObject fullHelp = genericHelpInfo.FullHelp;
     MamlUtil.OverrideName(this._fullHelpObject, fullHelp);
     MamlUtil.OverridePSTypeNames(this._fullHelpObject, fullHelp);
     MamlUtil.PrependSyntax(this._fullHelpObject, fullHelp);
     MamlUtil.PrependDetailedDescription(this._fullHelpObject, fullHelp);
     MamlUtil.OverrideParameters(this._fullHelpObject, fullHelp);
     MamlUtil.PrependNotes(this._fullHelpObject, fullHelp);
     MamlUtil.AddCommonProperties(this._fullHelpObject, fullHelp);
 }
示例#46
0
        private static bool Match(HelpInfo helpInfo, HelpRequest helpRequest)
        {
            if (helpRequest == null)
                return true;

            if (0 == (helpRequest.HelpCategory & helpInfo.HelpCategory))
            {
                return false;
            }

            if (!Match(helpInfo.Component, helpRequest.Component))
            {
                return false;
            }

            if (!Match(helpInfo.Role, helpRequest.Role))
            {
                return false;
            }

            if (!Match(helpInfo.Functionality, helpRequest.Functionality))
            {
                return false;
            }

            return true;
        }
 /// <summary>
 /// Add an help entry to cache.
 /// </summary>
 /// <param name="target">The key of the help entry.</param>
 /// <param name="helpInfo">HelpInfo object as the value of the help entry.</param>
 internal void AddCache(string target, HelpInfo helpInfo)
 {
     _helpCache[target] = helpInfo;
 }
示例#48
0
 /// <summary>
 /// Add an help entry to cache.
 /// </summary>
 /// <param name="target">the key of the help entry</param>
 /// <param name="helpInfo">helpInfo object as the value of the help entry</param>
 internal void AddCache(string target, HelpInfo helpInfo)
 {
     _helpCache[target] = helpInfo;
 }