| |
| |
|
|
| using System.Management.Automation.Internal; |
| using System.Management.Automation.Provider; |
| using System.Xml; |
|
|
| using Dbg = System.Management.Automation.Diagnostics; |
|
|
| namespace System.Management.Automation |
| { |
| |
| |
| |
| internal class ProviderContext |
| { |
| |
| |
| |
| private readonly string _requestedPath; |
| private readonly ExecutionContext _executionContext; |
| private readonly PathIntrinsics _pathIntrinsics; |
|
|
| |
| |
| |
| internal string RequestedPath |
| { |
| get |
| { |
| return _requestedPath; |
| } |
| } |
|
|
| |
| |
| |
| internal ProviderContext( |
| string requestedPath, |
| ExecutionContext executionContext, |
| PathIntrinsics pathIntrinsics) |
| { |
| Dbg.Assert(executionContext != null, "ExecutionContext cannot be null."); |
| _requestedPath = requestedPath; |
| _executionContext = executionContext; |
| _pathIntrinsics = pathIntrinsics; |
| } |
|
|
| |
| |
| |
| internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName) |
| { |
| if (InternalTestHooks.BypassOnlineHelpRetrieval) |
| { |
| |
| |
| return null; |
| } |
|
|
| |
| 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); |
| } |
| |
| catch (ArgumentNullException) |
| { |
| } |
| catch (ProviderNotFoundException) |
| { |
| } |
| catch (DriveNotFoundException) |
| { |
| } |
| catch (ProviderInvocationException) |
| { |
| } |
| catch (NotSupportedException) |
| { |
| } |
| catch (InvalidOperationException) |
| { |
| } |
| catch (ItemNotFoundException) |
| { |
| } |
|
|
| if (providerInfo == null) |
| { |
| return null; |
| } |
|
|
| |
| CmdletProvider cmdletProvider = providerInfo.CreateInstance(); |
| if (!(cmdletProvider is ICmdletProviderSupportsHelp provider)) |
| { |
| |
| 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); |
| } |
| } |
|
|
| |
| |
| cmdletProvider.Start(providerInfo, cmdletProviderContext); |
| |
| string providerPath = resolvedProviderPath; |
| |
| string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath); |
| if (string.IsNullOrEmpty(mamlXmlString)) |
| { |
| return null; |
| } |
| |
| XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument( |
| mamlXmlString, |
| false, |
| null); |
| MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider); |
| return providerSpecificHelpInfo; |
| } |
| } |
| } |
|
|