Esempio n. 1
0
 internal ConsoleLineOutput(PSHostUserInterface hostConsole, bool paging, bool lineWrap, TerminatingErrorContext errorContext)
 {
     if (hostConsole == null)
     {
         throw PSTraceSource.NewArgumentNullException("hostConsole");
     }
     if (errorContext == null)
     {
         throw PSTraceSource.NewArgumentNullException("errorContext");
     }
     this.console = hostConsole;
     this.errorContext = errorContext;
     if (paging)
     {
         tracer.WriteLine("paging is needed", new object[0]);
         string s = StringUtil.Format(FormatAndOut_out_xxx.ConsoleLineOutput_PagingPrompt, new object[0]);
         this.prompt = new PromptHandler(s, this);
     }
     PSHostRawUserInterface rawUI = this.console.RawUI;
     if (rawUI != null)
     {
         tracer.WriteLine("there is a valid raw interface", new object[0]);
         this._displayCellsPSHost = new DisplayCellsPSHost(rawUI);
     }
     WriteLineHelper.WriteCallback wlc = new WriteLineHelper.WriteCallback(this.OnWriteLine);
     WriteLineHelper.WriteCallback wc = new WriteLineHelper.WriteCallback(this.OnWrite);
     if (this.forceNewLine)
     {
         this.writeLineHelper = new WriteLineHelper(lineWrap, wlc, null, this.DisplayCells);
     }
     else
     {
         this.writeLineHelper = new WriteLineHelper(lineWrap, wlc, wc, this.DisplayCells);
     }
 }
 private HostIoInterceptor()
 {
     this.externalUi = null;
     this.subscribers = new List<WeakReference>();
     this.writeCache = new StringBuilder();
     this.paused = false;
 }
Esempio n. 3
0
		internal static SecureString PromptForSecureString(PSHostUserInterface hostUI, string prompt)
		{
			hostUI.Write(prompt);
			SecureString secureString = hostUI.ReadLineAsSecureString();
			hostUI.WriteLine("");
			return secureString;
		}
 private HostIOInterceptor()
 {
     externalUI = null;
     subscribers = new List<WeakReference>();
     writeCache = new StringBuilder();
     paused = false;
     host = null;
 }
Esempio n. 5
0
        internal Host(PoshConsole control, Panel progress, Options options)
        {
            PoshConsole = control;
            _options = options;
            _UI = new HostUI(PoshConsole, progress);

            MakeConsole();
        }
Esempio n. 6
0
 public Host(string name, Version version, PSHostUserInterface hostUI,
             RunspaceConfiguration runspaceConfiguration)
 {
     _pushedRunspaces = new Stack<Runspace>();
     _name = name;
     _version = version;
     _hostUI = hostUI;
     _runspaceConfiguration = runspaceConfiguration;
     _exitEvent = new ManualResetEvent(false);
 }
Esempio n. 7
0
 public AEMHelper(Action<ErrorRecord> errorAction, Action<string> verboseAction, Action<string> warningAction,
     PSHostUserInterface ui, StorageManagementClient storageClient, AzureSubscription subscription)
 {
     this._ErrorAction = errorAction;
     this._VerboseAction = verboseAction;
     this._WarningAction = warningAction;
     this._UI = ui;
     this._StorageClient = storageClient;
     this._Subscription = subscription;
 }
Esempio n. 8
0
        public GoosePSHost()
        {
            this.culture = System.Threading.Thread.CurrentThread.CurrentCulture;
            this.uiCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            this.instanceId = Guid.NewGuid();
            this.Output = new List<string>();
            this.Error = new List<string>();
            this.Other = new List<string>();

            this.ui = new GoosePSHostUserInterface(this.Output, this.Other, this.Error, this.Other, this.Other);
        }
        public PSTraceEvent(TraceEvent traceEvent, PSHostUserInterface hostUI)
        {
            this.hostUI = hostUI;

            Source = traceEvent;

            TimeStamp = Source.TimeStamp;
            ProcessName = Process.GetProcessById(Source.ProcessID)?.ProcessName ?? "";
            ProviderName = Source.ProviderName;
            EventName = Source.EventName;
            Level = Source.Level;
            PayloadOrMessage = Source.DumpPayloadOrMessage();
        }
Esempio n. 10
0
 internal InternalHostUserInterface(PSHostUserInterface externalUI, InternalHost parentHost)
 {
     this.externalUI = externalUI;
     if (parentHost == null)
     {
         throw PSTraceSource.NewArgumentNullException("parentHost");
     }
     this.parent = parentHost;
     PSHostRawUserInterface externalRawUI = null;
     if (externalUI != null)
     {
         externalRawUI = externalUI.RawUI;
     }
     this.internalRawUI = new InternalHostRawUserInterface(externalRawUI, this.parent);
 }
Esempio n. 11
0
        InternalHostUserInterface(PSHostUserInterface externalUI, InternalHost parentHost)
        {
            // externalUI may be null

            _externalUI = externalUI;

            // parent may not be null, however

            Dbg.Assert(parentHost != null, "parent may not be null");
            if (parentHost == null)
            {
                throw PSTraceSource.NewArgumentNullException("parentHost");
            }
            _parent = parentHost;

            PSHostRawUserInterface rawui = null;

            if (externalUI != null)
            {
                rawui = externalUI.RawUI;
            }

            _internalRawUI = new InternalHostRawUserInterface(rawui, _parent);
        }
Esempio n. 12
0
 public TestHost(TestHostUserInterface ui)
 {
     // TODO: Complete member initialization
     this._ui = ui;
 }
Esempio n. 13
0
            internal PromptResponse PromptUser(PSHostUserInterface console)
            {
                char ch = char.MinValue;
                for (int i = 0; i < this.actualPrompt.Count; i++)
                {
                    if (i < (this.actualPrompt.Count - 1))
                    {
                        console.WriteLine(this.actualPrompt[i]);
                    }
                    else
                    {
                        console.Write(this.actualPrompt[i]);
                    }
                }
                do
                {
                    this.callingCmdlet.CheckStopProcessing();
                    switch (console.RawUI.ReadKey(ReadKeyOptions.IncludeKeyUp | ReadKeyOptions.NoEcho).Character)
                    {
                        case 'q':
                        case 'Q':
                            console.WriteLine();
                            return PromptResponse.Quit;

                        case ' ':
                            console.WriteLine();
                            return PromptResponse.NextPage;
                    }
                }
                while (ch != '\r');
                console.WriteLine();
                return PromptResponse.NextLine;
            }
        public void AttachToHost(PSHost host)
        {
            if (this.host != null) { return; }
            if (host == null) { return; }

            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;

            object uiRef = host.GetType().GetField("internalUIRef", flags).GetValue(host);
            object ui = uiRef.GetType().GetProperty("Value", flags).GetValue(uiRef, null);

            FieldInfo externalUIField = ui.GetType().GetField("externalUI", flags);

            externalUI = (PSHostUserInterface)externalUIField.GetValue(ui);
            externalUIField.SetValue(ui, this);
            this.host = host;
        }
Esempio n. 15
0
 /// <summary>
 /// Construct an instance of this PSHost implementation.
 /// Keep a reference to the hosting application object.
 /// </summary>
 /// <param name="ui">Host UI.</param>
 internal FarHost(PSHostUserInterface ui)
 {
     _UI = ui;
 }
Esempio n. 16
0
        public WorkerHostUI(PSHostUserInterface ui, int workerId)
        {
            if (ui == null)
                throw new ArgumentNullException("ui");

            _ui       = ui;
            _workerId = workerId;
            _bol      = true;
        }
Esempio n. 17
0
 public PowerShellHost(PSHostUserInterface userInterface, ApplicationInformation applicationInformation)
 {
     this.userInterface = userInterface;
     this.applicationInformation = applicationInformation;
 }
Esempio n. 18
0
 public LocalHost()
 {
     localHostUserInterface = new LocalHostUserInterface(this);
 }
Esempio n. 19
0
            /// <summary>
            /// do the actual prompting
            /// </summary>
            /// <param name="console">PSHostUserInterface instance to prompt to</param>
            internal PromptResponse PromptUser(PSHostUserInterface console)
            {
                // NOTE: assume the values passed to ComputePromptLines are still valid

                // write out the prompt line(s). The last one will not have a new line
                // at the end because we leave the prompt at the end of the line
                for (int k = 0; k < _actualPrompt.Count; k++)
                {
                    if (k < (_actualPrompt.Count - 1))
                        console.WriteLine(_actualPrompt[k]); // intermediate line(s)
                    else
                        console.Write(_actualPrompt[k]); // last line
                }

                while (true)
                {
                    _callingCmdlet.CheckStopProcessing();
                    KeyInfo ki = console.RawUI.ReadKey(ReadKeyOptions.IncludeKeyUp | ReadKeyOptions.NoEcho);
                    char key = ki.Character;
                    if (key == 'q' || key == 'Q')
                    {
                        // need to move to the next line since we accepted input, add a newline
                        console.WriteLine();
                        return PromptResponse.Quit;
                    }
                    else if (key == ' ')
                    {
                        // need to move to the next line since we accepted input, add a newline
                        console.WriteLine();
                        return PromptResponse.NextPage;
                    }
                    else if (key == '\r')
                    {
                        // need to move to the next line since we accepted input, add a newline
                        console.WriteLine();
                        return PromptResponse.NextLine;
                    }
                }
            }
Esempio n. 20
0
 private static void WriteBanner(PSHostUserInterface ui)
 {
     ui.WriteLine(ConsoleColor.White, ConsoleColor.Black, BannerText);
     ui.WriteLine();
 }
Esempio n. 21
0
 public LocalHost(bool interactiveIO)
 {
     localHostUserInterface = new LocalHostUserInterface(this, interactiveIO);
 }
        public void Setup()
        {
            var applicationInformation = ApplicationInformationProvider.GetApplicationInformation();

            var encodingProvider = new DefaultFileEncodingProvider();
            this.fileSystemAccessor = new PhysicalFilesystemAccessor(encodingProvider);

            this.userInterface = new Mock<IUserInterface>().Object;
            this.powerShellUserInterface = new NuDeployPowerShellUserInterface(this.userInterface);
            this.powerShellHost = new PowerShellHost(this.powerShellUserInterface, applicationInformation);

            this.powerShellSession = new PowerShellSession(this.powerShellHost, this.fileSystemAccessor);
        }
Esempio n. 23
0
 public ExposedUI(PSHostUserInterface ui, IntPtr handle)
 {
     _ui = ui;
     Handle = handle;
 }
Esempio n. 24
0
        /// <summary>
        /// constructor for the ConsoleLineOutput
        /// </summary>
        /// <param name="hostConsole">PSHostUserInterface to wrap</param>
        /// <param name="paging">true if we require prompting for page breaks</param>
        /// <param name="errorContext">error context to throw exceptions</param>
        internal ConsoleLineOutput(PSHostUserInterface hostConsole, bool paging, TerminatingErrorContext errorContext)
        {
            if (hostConsole == null)
                throw PSTraceSource.NewArgumentNullException("hostConsole");
            if (errorContext == null)
                throw PSTraceSource.NewArgumentNullException("errorContext");

            _console = hostConsole;
            _errorContext = errorContext;

            if (paging)
            {
                tracer.WriteLine("paging is needed");
                // if we need to do paging, instantiate a prompt handler
                // that will take care of the screen interaction
                string promptString = StringUtil.Format(FormatAndOut_out_xxx.ConsoleLineOutput_PagingPrompt);
                _prompt = new PromptHandler(promptString, this);
            }


            PSHostRawUserInterface raw = _console.RawUI;
            if (raw != null)
            {
                tracer.WriteLine("there is a valid raw interface");
#if TEST_MULTICELL_ON_SINGLE_CELL_LOCALE
                // create a test instance with fake behavior
                this._displayCellsPSHost = new DisplayCellsTest();
#else
                // set only if we have a valid raw interface
                _displayCellsPSHost = new DisplayCellsPSHost(raw);
#endif
            }

            // instantiate the helper to do the line processing when ILineOutput.WriteXXX() is called
            WriteLineHelper.WriteCallback wl = new WriteLineHelper.WriteCallback(this.OnWriteLine);
            WriteLineHelper.WriteCallback w = new WriteLineHelper.WriteCallback(this.OnWrite);

            if (_forceNewLine)
            {
                _writeLineHelper = new WriteLineHelper(/*lineWrap*/false, wl, null, this.DisplayCells);
            }
            else
            {
                _writeLineHelper = new WriteLineHelper(/*lineWrap*/false, wl, w, this.DisplayCells);
            }
        }
Esempio n. 25
0
 internal void SetHostUserInterface(PSHostUserInterface ui)
 {
     localHostUserInterface = ui;
 }
        public void DetachFromHost()
        {
            if (host == null) { return; }

            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;

            object uiRef = host.GetType().GetField("internalUIRef", flags).GetValue(host);
            object ui = uiRef.GetType().GetProperty("Value", flags).GetValue(uiRef, null);

            FieldInfo externalUIField = ui.GetType().GetField("externalUI", flags);

            if (externalUIField.GetValue(ui) == this)
            {
                externalUIField.SetValue(ui, externalUI);
            }

            externalUI = null;
            host = null;
        }