Пример #1
0
        /// <summary>
        /// End processing.  Do work.
        /// </summary>
        protected override void EndProcessing()
        {
            switch (ParameterSetName)
            {
                case DebugJobCommand.JobParameterSet:
                    _job = Job;
                    break;

                case DebugJobCommand.JobNameParameterSet:
                    _job = GetJobByName(Name);
                    break;

                case DebugJobCommand.JobIdParameterSet:
                    _job = GetJobById(Id);
                    break;

                case DebugJobCommand.JobInstanceIdParameterSet:
                    _job = GetJobByInstanceId(InstanceId);
                    break;
            }

            if (!ShouldProcess(_job.Name, VerbsDiagnostic.Debug))
            {
                return;
            }

            Runspace runspace = LocalRunspace.DefaultRunspace;
            if (runspace == null || runspace.Debugger == null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSInvalidOperationException(RemotingErrorIdStrings.CannotDebugJobNoHostDebugger),
                        "DebugJobNoHostDebugger",
                        ErrorCategory.InvalidOperation,
                        this)
                    );
            }

            if ((runspace.Debugger.DebugMode == DebugModes.Default) || (runspace.Debugger.DebugMode == DebugModes.None))
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSInvalidOperationException(RemotingErrorIdStrings.CannotDebugJobInvalidDebuggerMode),
                        "DebugJobWrongDebugMode",
                        ErrorCategory.InvalidOperation,
                        this)
                    );
            }

            if (this.Host == null || this.Host.UI == null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSInvalidOperationException(RemotingErrorIdStrings.CannotDebugJobNoHostUI),
                        "DebugJobNoHostAvailable",
                        ErrorCategory.InvalidOperation,
                        this)
                    );
            }

            if (!CheckForDebuggableJob())
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSInvalidOperationException(DebuggerStrings.NoDebuggableJobsFound),
                        "DebugJobNoDebuggableJobsFound",
                        ErrorCategory.InvalidOperation,
                        this)
                    );
            }

            // Set up host script debugger to debug the job.
            _debugger = runspace.Debugger;
            _debugger.DebugJob(_job);

            // Blocking call.  Send job output to host UI while debugging and wait for Job completion.
            WaitAndReceiveJobOutput();
        }