Пример #1
0
        /// <summary>
        /// Creates a new instance of the ConsoleService class.
        /// </summary>
        /// <param name="powerShellContext">
        /// The PowerShellContext that will be used for executing commands
        /// against a runspace.
        /// </param>
        /// <param name="defaultPromptHandlerContext">
        /// The default IPromptHandlerContext implementation to use for
        /// displaying prompts to the user.
        /// </param>
        public ConsoleService(
            PowerShellContext powerShellContext,
            IPromptHandlerContext defaultPromptHandlerContext)
        {
            // Register this instance as the IConsoleHost for the PowerShellContext
            this.powerShellContext             = powerShellContext;
            this.powerShellContext.ConsoleHost = this;

            // Set the default prompt handler factory or create
            // a default if one is not provided
            if (defaultPromptHandlerContext == null)
            {
                defaultPromptHandlerContext =
                    new ConsolePromptHandlerContext(this);
            }

            this.promptHandlerContextStack.Push(
                defaultPromptHandlerContext);
        }
Пример #2
0
        private TPromptHandler GetPromptHandler <TPromptHandler>(
            Func <IPromptHandlerContext, TPromptHandler> factoryInvoker)
            where TPromptHandler : PromptHandler
        {
            if (this.activePromptHandler != null)
            {
                Logger.Write(
                    LogLevel.Error,
                    "Prompt handler requested while another prompt is already active.");
            }

            // Get the topmost prompt handler factory
            IPromptHandlerContext promptHandlerContext =
                this.promptHandlerContextStack.Peek();

            TPromptHandler promptHandler = factoryInvoker(promptHandlerContext);

            this.activePromptHandler = promptHandler;
            this.activePromptHandler.PromptCancelled += activePromptHandler_PromptCancelled;

            return(promptHandler);
        }
Пример #3
0
 /// <summary>
 /// Pushes a new IPromptHandlerContext onto the stack.  This
 /// is used when a prompt handler context is only needed for
 /// a short series of command executions.
 /// </summary>
 /// <param name="promptHandlerContext">
 /// The IPromptHandlerContext instance to push onto the stack.
 /// </param>
 public void PushPromptHandlerContext(IPromptHandlerContext promptHandlerContext)
 {
     // Push a new prompt handler factory for future prompts
     this.promptHandlerContextStack.Push(promptHandlerContext);
 }