예제 #1
0
        protected override bool ExecuteHost(string fullCommand, string command, params object[] inputs)
        {
            SetSyncModeOnHost(false);
            try {
                Pipeline pipeline = Runspace.InvokeAsync(fullCommand, inputs, true, (sender, e) => {
                    switch (e.PipelineStateInfo.State)
                    {
                    case PipelineState.Completed:
                    case PipelineState.Failed:
                    case PipelineState.Stopped:
                        if (e.PipelineStateInfo.Reason != null)
                        {
                            ReportError(e.PipelineStateInfo.Reason);
                        }

                        OnExecuteCommandEnd();
                        ExecuteEnd.Raise(this, EventArgs.Empty);
                        break;
                    }
                });

                ExecutingPipeline = pipeline;
                return(true);
            }
            catch (RuntimeException e) {
                ReportError(e.ErrorRecord);
                ExceptionHelper.WriteToActivityLog(e);
            }
            catch (Exception e) {
                ReportError(e);
                ExceptionHelper.WriteToActivityLog(e);
            }

            return(false); // Error occured, command not executing
        }
예제 #2
0
        private void ConsoleCommandExecuteEnd(object sender, EventArgs e)
        {
            // Flush the change in console text buffer onto the output window for testability
            // If the VSOutputConsole could not be obtained, just ignore
            if (VSOutputConsole != null && _snapshot != null)
            {
                if (_previousPosition < _snapshot.Length)
                {
                    VSOutputConsole.WriteLine(_snapshot.GetText(_previousPosition, (_snapshot.Length - _previousPosition)));
                }
                _previousPosition = _snapshot.Length;
            }

            ((IAsyncHost)sender).ExecuteEnd -= ConsoleCommandExecuteEnd;
            WpfConsole.SetExecutionMode(false);

            // This does NOT imply that the command succeeded. It just indicates that the console is ready for input now
            VSOutputConsole.WriteLine(Resources.PackageManagerConsoleCommandExecuted);
            ExecuteEnd.Raise(this, EventArgs.Empty);
        }