internal OutWindowProxy(string title, OutputModeOption outPutMode, OutGridViewCommand parentCmdlet) { this.title = title; this.outputMode = outPutMode; this.parentCmdlet = parentCmdlet; this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(parentCmdlet, "Microsoft.Management.UI.Internal.OutGridViewWindow"); }
/// <summary> /// Initializes a new instance of the OutWindowProxy class. /// </summary> internal OutWindowProxy(string title, OutputModeOption outPutMode, OutGridViewCommand parentCmdlet) { _title = title; _outputMode = outPutMode; _parentCmdlet = parentCmdlet; _graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(parentCmdlet, OutWindowProxy.OutGridViewWindowClassName); }
internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName, string featureName) { GraphicalHostReflectionWrapper wrapper = new GraphicalHostReflectionWrapper(); if (IsInputFromRemoting(parentCmdlet)) { ErrorRecord errorRecord = new ErrorRecord(new NotSupportedException(StringUtil.Format(HelpErrors.RemotingNotSupportedForFeature, featureName)), "RemotingNotSupported", ErrorCategory.InvalidOperation, parentCmdlet); parentCmdlet.ThrowTerminatingError(errorRecord); } AssemblyName assemblyRef = new AssemblyName { Name = "Microsoft.PowerShell.GraphicalHost", Version = new Version(3, 0, 0, 0), CultureInfo = new CultureInfo(string.Empty) }; assemblyRef.SetPublicKeyToken(new byte[] { 0x31, 0xbf, 0x38, 0x56, 0xad, 0x36, 0x4e, 0x35 }); try { wrapper.graphicalHostAssembly = Assembly.Load(assemblyRef); } catch (FileNotFoundException exception) { string message = StringUtil.Format(HelpErrors.GraphicalHostAssemblyIsNotFound, featureName, exception.Message); parentCmdlet.ThrowTerminatingError(new ErrorRecord(new NotSupportedException(message, exception), "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, assemblyRef)); } catch (Exception exception2) { CommandProcessorBase.CheckForSevereException(exception2); parentCmdlet.ThrowTerminatingError(new ErrorRecord(exception2, "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, assemblyRef)); } wrapper.graphicalHostHelperType = wrapper.graphicalHostAssembly.GetType(graphicalHostHelperTypeName); ConstructorInfo info = wrapper.graphicalHostHelperType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null); if (info != null) { wrapper.graphicalHostHelperObject = info.Invoke(new object[0]); } return wrapper; }
internal ShowCommandProxy(ShowCommandCommand cmdlet) { _cmdlet = cmdlet; _graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(cmdlet, ShowCommandProxy.ShowCommandHelperName); }
protected override void ProcessRecord() { try { if (this.ShowWindow != 0) { this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper"); } base.Context.HelpSystem.OnProgress += new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress); bool failed = false; HelpCategory cat = this.ToHelpCategory(this._category, ref failed); if (!failed) { this.ValidateAndThrowIfError(cat); HelpRequest helpRequest = new HelpRequest(this.Name, cat) { Provider = this._provider, Component = this._component, Role = this._role, Functionality = this._functionality, ProviderContext = new ProviderContext(this.Path, base.Context.Engine.Context, base.SessionState.Path), CommandOrigin = base.MyInvocation.CommandOrigin }; IEnumerable<HelpInfo> help = base.Context.HelpSystem.GetHelp(helpRequest); HelpInfo helpInfo = null; int num = 0; foreach (HelpInfo info2 in help) { if (base.IsStopping) { return; } if (num == 0) { helpInfo = info2; } else { if (helpInfo != null) { this.WriteObjectsOrShowOnlineHelp(helpInfo, false); helpInfo = null; } this.WriteObjectsOrShowOnlineHelp(info2, false); } num++; } if (1 == num) { this.WriteObjectsOrShowOnlineHelp(helpInfo, true); } else if (this.showOnlineHelp && (num > 1)) { throw PSTraceSource.NewInvalidOperationException("HelpErrors", "MultipleOnlineTopicsNotSupported", new object[] { "Online" }); } if ((((num == 0) && !WildcardPattern.ContainsWildcardCharacters(helpRequest.Target)) || base.Context.HelpSystem.VerboseHelpErrors) && (base.Context.HelpSystem.LastErrors.Count > 0)) { foreach (ErrorRecord record in base.Context.HelpSystem.LastErrors) { base.WriteError(record); } } } } finally { base.Context.HelpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(this.HelpSystem_OnProgress); base.Context.HelpSystem.ClearScriptBlockTokenCache(); } }
internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName, string featureName) { GraphicalHostReflectionWrapper returnValue = new GraphicalHostReflectionWrapper(); if (GraphicalHostReflectionWrapper.IsInputFromRemoting(parentCmdlet)) { ErrorRecord error = new ErrorRecord( new NotSupportedException(StringUtil.Format(HelpErrors.RemotingNotSupportedForFeature, featureName)), "RemotingNotSupported", ErrorCategory.InvalidOperation, parentCmdlet); parentCmdlet.ThrowTerminatingError(error); } // Prepare the full assembly name. AssemblyName graphicalHostAssemblyName = new AssemblyName(); graphicalHostAssemblyName.Name = "Microsoft.PowerShell.GraphicalHost"; graphicalHostAssemblyName.Version = new Version(3, 0, 0, 0); graphicalHostAssemblyName.CultureInfo = new CultureInfo(string.Empty); // Neutral culture graphicalHostAssemblyName.SetPublicKeyToken(new byte[] { 0x31, 0xbf, 0x38, 0x56, 0xad, 0x36, 0x4e, 0x35 }); try { returnValue._graphicalHostAssembly = Assembly.Load(graphicalHostAssemblyName); } catch (FileNotFoundException fileNotFoundEx) { // This exception is thrown if the Microsoft.PowerShell.GraphicalHost.dll could not be found (was not installed). string errorMessage = StringUtil.Format( HelpErrors.GraphicalHostAssemblyIsNotFound, featureName, fileNotFoundEx.Message); parentCmdlet.ThrowTerminatingError( new ErrorRecord( new NotSupportedException(errorMessage, fileNotFoundEx), "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, graphicalHostAssemblyName)); } catch (Exception e) { parentCmdlet.ThrowTerminatingError( new ErrorRecord( e, "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, graphicalHostAssemblyName)); } returnValue._graphicalHostHelperType = returnValue._graphicalHostAssembly.GetType(graphicalHostHelperTypeName); Diagnostics.Assert(returnValue._graphicalHostHelperType != null, "the type exists in Microsoft.PowerShell.GraphicalHost"); ConstructorInfo constructor = returnValue._graphicalHostHelperType.GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, Array.Empty <Type>(), null); if (constructor != null) { returnValue._graphicalHostHelperObject = constructor.Invoke(Array.Empty <object>()); Diagnostics.Assert(returnValue._graphicalHostHelperObject != null, "the constructor does not throw anything"); } return(returnValue); }
/// <summary> /// Retrieves a wrapper used to invoke members of the type with name <paramref name="graphicalHostHelperTypeName"/> /// in Microsoft.PowerShell.GraphicalHost.dll. /// </summary> /// <param name="parentCmdlet">The cmdlet requesting the wrapper (used to throw terminating errors).</param> /// <param name="graphicalHostHelperTypeName">The type name we want to invoke members from.</param> /// <returns> /// wrapper used to invoke members of the type with name <paramref name="graphicalHostHelperTypeName"/> /// in Microsoft.PowerShell.GraphicalHost.dll /// </returns> /// <exception cref="RuntimeException">When it was not possible to load Microsoft.PowerShell.GraphicalHost.dlly.</exception> internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName) { return(GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(parentCmdlet, graphicalHostHelperTypeName, parentCmdlet.CommandInfo.Name)); }
internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName, string featureName) { GraphicalHostReflectionWrapper returnValue = new GraphicalHostReflectionWrapper(); if (GraphicalHostReflectionWrapper.IsInputFromRemoting(parentCmdlet)) { ErrorRecord error = new ErrorRecord( new NotSupportedException(StringUtil.Format(HelpErrors.RemotingNotSupportedForFeature, featureName)), "RemotingNotSupported", ErrorCategory.InvalidOperation, parentCmdlet); parentCmdlet.ThrowTerminatingError(error); } // Prepare the full assembly name. AssemblyName graphicalHostAssemblyName = new AssemblyName(); graphicalHostAssemblyName.Name = "Microsoft.PowerShell.GraphicalHost"; graphicalHostAssemblyName.Version = new Version(3, 0, 0, 0); graphicalHostAssemblyName.CultureInfo = new CultureInfo(String.Empty); // Neutral culture graphicalHostAssemblyName.SetPublicKeyToken(new byte[] { 0x31, 0xbf, 0x38, 0x56, 0xad, 0x36, 0x4e, 0x35 }); try { returnValue._graphicalHostAssembly = Assembly.Load(graphicalHostAssemblyName); } catch (FileNotFoundException fileNotFoundEx) { // This exception is thrown if the Microsoft.PowerShell.GraphicalHost.dll could not be found (was not installed). string errorMessage = StringUtil.Format( HelpErrors.GraphicalHostAssemblyIsNotFound, featureName, fileNotFoundEx.Message); parentCmdlet.ThrowTerminatingError( new ErrorRecord( new NotSupportedException(errorMessage, fileNotFoundEx), "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, graphicalHostAssemblyName)); } catch (Exception e) { CommandProcessorBase.CheckForSevereException(e); parentCmdlet.ThrowTerminatingError( new ErrorRecord( e, "ErrorLoadingAssembly", ErrorCategory.ObjectNotFound, graphicalHostAssemblyName)); } returnValue._graphicalHostHelperType = returnValue._graphicalHostAssembly.GetType(graphicalHostHelperTypeName); Diagnostics.Assert(returnValue._graphicalHostHelperType != null, "the type exists in Microsoft.PowerShell.GraphicalHost"); ConstructorInfo constructor = returnValue._graphicalHostHelperType.GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null); if (constructor != null) { returnValue._graphicalHostHelperObject = constructor.Invoke(new object[] { }); Diagnostics.Assert(returnValue._graphicalHostHelperObject != null, "the constructor does not throw anything"); } return returnValue; }
/// <summary> /// Implements the ProcessRecord() method for get-help command /// </summary> protected override void ProcessRecord() { try { #if !CORECLR if (this.ShowWindow) { this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(this, "Microsoft.PowerShell.Commands.Internal.HelpWindowHelper"); } #endif this.Context.HelpSystem.OnProgress += new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress); bool failed = false; HelpCategory helpCategory = ToHelpCategory(Category, ref failed); if (failed) return; // Validate input parameters ValidateAndThrowIfError(helpCategory); HelpRequest helpRequest = new HelpRequest(this.Name, helpCategory); helpRequest.Provider = _provider; helpRequest.Component = Component; helpRequest.Role = Role; helpRequest.Functionality = Functionality; helpRequest.ProviderContext = new ProviderContext( this.Path, this.Context.Engine.Context, this.SessionState.Path); helpRequest.CommandOrigin = this.MyInvocation.CommandOrigin; // the idea is to use yield statement in the help lookup to speed up // perceived user experience....So HelpSystem.GetHelp returns an // IEnumerable.. IEnumerable<HelpInfo> helpInfos = this.Context.HelpSystem.GetHelp(helpRequest); // HelpCommand acts differently when there is just one help object and when // there are more than one object...so handling this behavior through // some variables. HelpInfo firstHelpInfoObject = null; int countOfHelpInfos = 0; foreach (HelpInfo helpInfo in helpInfos) { // honor Ctrl-C from user. if (IsStopping) { return; } if (0 == countOfHelpInfos) { firstHelpInfoObject = helpInfo; } else { // write first help object only once. if (null != firstHelpInfoObject) { WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, false); firstHelpInfoObject = null; } WriteObjectsOrShowOnlineHelp(helpInfo, false); } countOfHelpInfos++; } _timer.Stop(); if (!string.IsNullOrEmpty(Name)) Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.ReportGetHelpTelemetry(Name, countOfHelpInfos, _timer.ElapsedMilliseconds, _updatedHelp); // Write full help as there is only one help info object if (1 == countOfHelpInfos) { WriteObjectsOrShowOnlineHelp(firstHelpInfoObject, true); } else if (_showOnlineHelp && (countOfHelpInfos > 1)) { throw PSTraceSource.NewInvalidOperationException(HelpErrors.MultipleOnlineTopicsNotSupported, "Online"); } // show errors only if there is no wildcard search or VerboseHelpErrors is true. if (((countOfHelpInfos == 0) && (!WildcardPattern.ContainsWildcardCharacters(helpRequest.Target))) || this.Context.HelpSystem.VerboseHelpErrors) { // Check if there is any error happened. If yes, // pipe out errors. if (this.Context.HelpSystem.LastErrors.Count > 0) { foreach (ErrorRecord errorRecord in this.Context.HelpSystem.LastErrors) { WriteError(errorRecord); } } } } finally { this.Context.HelpSystem.OnProgress -= new HelpSystem.HelpProgressHandler(HelpSystem_OnProgress); // finally clear the ScriptBlockAst -> Token[] cache this.Context.HelpSystem.ClearScriptBlockTokenCache(); } }
internal ShowCommandProxy(ShowCommandCommand cmdlet) { this.cmdlet = cmdlet; this.graphicalHostReflectionWrapper = GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(cmdlet, "Microsoft.PowerShell.Commands.ShowCommandInternal.ShowCommandHelper"); }