public Collection <int> PromptForChoice(string caption, string message, Collection <ChoiceDescription> choices, IEnumerable <int> defaultChoices) { if (this.externalUI == null) { this.ThrowPromptNotInteractive(message); } IHostUISupportsMultipleChoiceSelection externalUI = this.externalUI as IHostUISupportsMultipleChoiceSelection; Collection <int> collection = null; try { if (externalUI == null) { return(this.EmulatePromptForMultipleChoice(caption, message, choices, defaultChoices)); } collection = externalUI.PromptForChoice(caption, message, choices, defaultChoices); } catch (PipelineStoppedException) { LocalPipeline currentlyRunningPipeline = (LocalPipeline)((RunspaceBase)this.parent.Context.CurrentRunspace).GetCurrentlyRunningPipeline(); if (currentlyRunningPipeline == null) { throw; } currentlyRunningPipeline.Stopper.Stop(); } return(collection); }
public Collection <int> PromptForChoice( string caption, string message, Collection <ChoiceDescription> choices, IEnumerable <int> defaultChoices) { using (InternalHostUserInterface.tracer.TraceMethod()) { if (this.externalUI == null) { this.ThrowNotInteractive(); } IHostUISupportsMultipleChoiceSelection externalUi = this.externalUI as IHostUISupportsMultipleChoiceSelection; Collection <int> collection = (Collection <int>)null; try { collection = externalUi != null?externalUi.PromptForChoice(caption, message, choices, defaultChoices) : this.EmulatePromptForMultipleChoice(caption, message, choices, defaultChoices); } catch (PipelineStoppedException ex) { LocalPipeline currentlyRunningPipeline = (LocalPipeline)this.parent.Context.CurrentRunspace.GetCurrentlyRunningPipeline(); if (currentlyRunningPipeline == null) { throw; } else { currentlyRunningPipeline.Stopper.Stop(); } } return(collection); } }
/// <summary> /// Presents a dialog allowing the user to choose options from a set of options. /// </summary> /// <param name="caption"> /// Caption to precede or title the prompt. E.g. "Parameters for get-foo (instance 1 of 2)" /// </param> /// <param name="message"> /// A message that describes what the choice is for. /// </param> /// <param name="choices"> /// An Collection of ChoiceDescription objects that describe each choice. /// </param> /// <param name="defaultChoices"> /// The index of the labels in the choices collection element to be presented to the user as /// the default choice(s). /// </param> /// <returns> /// The indices of the choice elements that corresponds to the options selected. /// </returns> /// <seealso cref="System.Management.Automation.Host.PSHostUserInterface.PromptForChoice"/> public Collection <int> PromptForChoice(string caption, string message, Collection <ChoiceDescription> choices, IEnumerable <int> defaultChoices) { if (_externalUI == null) { ThrowPromptNotInteractive(message); } IHostUISupportsMultipleChoiceSelection hostForMultipleChoices = _externalUI as IHostUISupportsMultipleChoiceSelection; Collection <int> result = null; try { if (hostForMultipleChoices == null) { // host did not implement this new interface.. // so work with V1 host API to get the behavior.. // this will allow Hosts that were developed with // V1 API to interact with PowerShell V2. result = EmulatePromptForMultipleChoice(caption, message, choices, defaultChoices); } else { result = hostForMultipleChoices.PromptForChoice(caption, message, choices, defaultChoices); } } catch (PipelineStoppedException) { // PipelineStoppedException is thrown by host when it wants // to stop the pipeline. LocalPipeline lpl = (LocalPipeline)((RunspaceBase)_parent.Context.CurrentRunspace).GetCurrentlyRunningPipeline(); if (lpl == null) { throw; } lpl.Stopper.Stop(); } return(result); }