Esempio n. 1
0
		public PoshHost(IPSUI psUi)
		{
			_buffer = psUi.Console;
			_tabExpander = new TabExpander(this);

			MakeConsole();

			Options = new PoshOptions(this, _buffer);
			_psUi = psUi;

			try
			{
				// we have to be careful here, because this is an interface member ...
				// but in the current implementation, _buffer.RawUI returns _buffer
				_rawUI = new PoshRawUI(_buffer.RawUI);
				_UI = new PoshUI(_rawUI, psUi);

				// pre-create this
				_outDefault = new Command("Out-Default");
				// for now, merge the errors with the rest of the output
				_outDefault.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
				_outDefault.MergeUnclaimedPreviousCommandResults = PipelineResultTypes.Error | PipelineResultTypes.Output;
			}
			catch (Exception ex)
			{
				MessageBox.Show(
					"Can't create PowerShell interface, are you sure PowerShell is installed? \n" + ex.Message + "\nAt:\n" +
						ex.Source, "Error Starting PoshConsole", MessageBoxButton.OK, MessageBoxImage.Stop);
				throw;
			}
			_buffer.CommandBox.IsEnabled = false;
			_buffer.Expander.TabComplete += _tabExpander.Expand;
			_buffer.Command += OnGotUserInput;

			// Some delegates we think we can get away with making only once...
			Properties.Settings.Default.PropertyChanged += SettingsPropertyChanged;

			_runner = new CommandRunner(this, Resources.Prompt);
			_runner.RunspaceReady += (source, args) => _buffer.Dispatcher.BeginInvoke((Action) (() =>
				{
					_buffer.CommandBox.IsEnabled = true;
					ExecutePromptFunction(null, PipelineState.Completed);
				}));

			_runner.ShouldExit += (source, args) => SetShouldExit(args);
		}
Esempio n. 2
0
		public PoshUI(PoshRawUI rawUI, IPSUI uiHelper)
        {
            myRawUi = rawUI;
            myConsole = uiHelper.Console;
            myPsHelper = uiHelper;
        }