internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) { ProviderInfo info = null; PSDriveInfo drive = null; string str = null; CmdletProviderContext context = new CmdletProviderContext(this._executionContext); try { string str2 = this._requestedPath; if (string.IsNullOrEmpty(this._requestedPath)) { str2 = this._pathIntrinsics.CurrentLocation.Path; } str = this._executionContext.LocationGlobber.GetProviderPath(str2, context, out info, out drive); } catch (ArgumentNullException) { } catch (ProviderNotFoundException) { } catch (DriveNotFoundException) { } catch (ProviderInvocationException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (ItemNotFoundException) { } if (info == null) { return(null); } CmdletProvider provider = info.CreateInstance(); ICmdletProviderSupportsHelp help = provider as ICmdletProviderSupportsHelp; if (help == null) { return(null); } if (str == null) { throw new ItemNotFoundException(this._requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); } provider.Start(info, context); string path = str; string helpMaml = help.GetHelpMaml(helpItemName, path); if (string.IsNullOrEmpty(helpMaml)) { return(null); } return(MamlCommandHelpInfo.Load(InternalDeserializer.LoadUnsafeXmlDocument(helpMaml, false, null).DocumentElement, HelpCategory.Provider)); }
/// <summary> /// Get provider specific help info. /// </summary> internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) { if (InternalTestHooks.BypassOnlineHelpRetrieval) { // By returning null, we force get-help to return generic help // which includes a helpUri that points to the fwlink defined in the cmdlet code. return(null); } // Get the provider. ProviderInfo providerInfo = null; PSDriveInfo driveInfo = null; string resolvedProviderPath = null; CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext); try { string psPath = _requestedPath; if (string.IsNullOrEmpty(_requestedPath)) { psPath = _pathIntrinsics.CurrentLocation.Path; } resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath( psPath, cmdletProviderContext, out providerInfo, out driveInfo); } // ignore exceptions caused by provider resolution catch (ArgumentNullException) { } catch (ProviderNotFoundException) { } catch (DriveNotFoundException) { } catch (ProviderInvocationException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (ItemNotFoundException) { } if (providerInfo == null) { return(null); } // Does the provider know how to generate MAML. CmdletProvider cmdletProvider = providerInfo.CreateInstance(); ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp; // Under JEA sessions the resolvedProviderPath will be null, we should allow get-help to continue. if (provider == null) { return(null); } bool isJEASession = false; if (this._executionContext.InitialSessionState != null && this._executionContext.InitialSessionState.Providers != null && providerInfo != null) { foreach ( Runspaces.SessionStateProviderEntry sessionStateProvider in this._executionContext.InitialSessionState.Providers[providerInfo.Name]) { if (sessionStateProvider.Visibility == SessionStateEntryVisibility.Private) { isJEASession = true; break; } } } if (resolvedProviderPath == null) { if (isJEASession) { return(null); } else { throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); } } // ok we have path and valid provider that supplys content..initialize the provider // and get the help content for the path. cmdletProvider.Start(providerInfo, cmdletProviderContext); // There should be exactly one resolved path. string providerPath = resolvedProviderPath; // Get the MAML help info. Don't catch exceptions thrown by provider. string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath); if (string.IsNullOrEmpty(mamlXmlString)) { return(null); } // process the MAML content only if it is non-empty. XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument( mamlXmlString, false, /* ignore whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider); return(providerSpecificHelpInfo); }
/// <summary> /// Get provider specific help info. /// </summary> internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) { // Get the provider. ProviderInfo providerInfo = null; PSDriveInfo driveInfo = null; string resolvedProviderPath = null; CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext); try { string psPath = _requestedPath; if (string.IsNullOrEmpty(_requestedPath)) { psPath = _pathIntrinsics.CurrentLocation.Path; } resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath( psPath, cmdletProviderContext, out providerInfo, out driveInfo); } // ignore exceptions caused by provider resolution catch (ArgumentNullException) { } catch (ProviderNotFoundException) { } catch (DriveNotFoundException) { } catch (ProviderInvocationException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (ItemNotFoundException) { } if (providerInfo == null) { return(null); } // Does the provider know how to generate MAML. CmdletProvider cmdletProvider = providerInfo.CreateInstance(); ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp; if (provider == null) { return(null); } if (resolvedProviderPath == null) { throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound); } // ok we have path and valid provider that supplys content..initialize the provider // and get the help content for the path. cmdletProvider.Start(providerInfo, cmdletProviderContext); // There should be exactly one resolved path. string providerPath = resolvedProviderPath; // Get the MAML help info. Don't catch exceptions thrown by provider. string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath); if (string.IsNullOrEmpty(mamlXmlString)) { return(null); } // process the MAML content only if it is non-empty. XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument( mamlXmlString, false, /* ignore whitespace, comments, etc. */ null); /* default maxCharactersInDocument */ MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider); return(providerSpecificHelpInfo); }