Exemple #1
0
        void PollForResults(bool drainQueues = false)
        {
            ShouldProcessPrompt process;

            while (_process.TryDequeue(out process))
            {
                process.Completer.TrySetResult(CommandRuntime.ShouldProcess(process.Target, process.Message));
            }

            ShouldContinuePrompt shouldContinue;

            while (_continue.TryDequeue(out shouldContinue))
            {
                shouldContinue.Completer.TrySetResult(CommandRuntime.ShouldContinue(shouldContinue.Query, shouldContinue.Caption));
            }

            ErrorRecord exception;

            while (_error.TryDequeue(out exception))
            {
                CommandRuntime.WriteError(exception);
            }

            CmdletOutput output;

            while (_output.TryDequeue(out output))
            {
                CommandRuntime.WriteObject(output.Output, output.Enumerate);
            }

            string logMessage;

            while (_warning.TryDequeue(out logMessage))
            {
                CommandRuntime.WriteWarning(logMessage);
            }

            while (_verbose.TryDequeue(out logMessage))
            {
                CommandRuntime.WriteVerbose(logMessage);
            }

            while (_debug.TryDequeue(out logMessage))
            {
                CommandRuntime.WriteDebug(logMessage);
            }

            ProgressRecord progress;

            while (_progress.TryDequeue(out progress))
            {
                CommandRuntime.WriteProgress(progress);
            }

            foreach (var progressItem in _progressTasks.Keys)
            {
                ReportTaskProgress(progressItem);
            }
        }
Exemple #2
0
 public void WriteWarning(string text)
 {
     if (CommandRuntime == null)
     {
         throw new NotImplementedException("WriteWarning");
     }
     CommandRuntime.WriteWarning(text);
 }
Exemple #3
0
        /// <summary>
        /// Execute BeginProcessing part of command.
        /// </summary>
        internal override void DoBegin()
        {
            if (!RanBeginAlready && CmdletParameterBinderController.ObsoleteParameterWarningList != null)
            {
                using (CommandRuntime.AllowThisCommandToWrite(false))
                {
                    // Write out warning messages for the bound obsolete parameters.
                    // The warning message are generated during parameter binding, but we delay writing
                    // them out until now so that the -WarningAction will be respected as expected.
                    foreach (WarningRecord warningRecord in CmdletParameterBinderController.ObsoleteParameterWarningList)
                    {
                        CommandRuntime.WriteWarning(warningRecord);
                    }
                }

                // Clear up the warning message list
                CmdletParameterBinderController.ObsoleteParameterWarningList.Clear();
            }

            base.DoBegin();
        }
Exemple #4
0
        /// <summary>
        /// This calls the command.  It assumes that Prepare() has already been called.
        /// JonN     2003-04-02 Split from Execute()
        /// </summary>
        /// <exception cref="PipelineStoppedException">
        /// a terminating error occurred, or the pipeline was otherwise stopped
        /// </exception>
        internal override void ProcessRecord()
        {
            // Invoke the Command method with the request object

            if (!this.RanBeginAlready)
            {
                RanBeginAlready = true;
                try
                {
                    // NOTICE-2004/06/08-JonN 959638
                    using (commandRuntime.AllowThisCommandToWrite(true))
                    {
                        if (Context._debuggingMode > 0 && Command is not PSScriptCmdlet)
                        {
                            Context.Debugger.CheckCommand(this.Command.MyInvocation);
                        }

                        Command.DoBeginProcessing();
                    }
                }
                // 2004/03/18-JonN This is understood to be
                // an FXCOP violation, cleared by KCwalina.
                catch (Exception e)  // Catch-all OK, 3rd party callout.
                {
                    // This cmdlet threw an exception, so
                    // wrap it and bubble it up.
                    throw ManageInvocationException(e);
                }
            }

            Debug.Assert(this.Command.MyInvocation.PipelineIterationInfo != null); // this should have been allocated when the pipeline was started

            while (Read())
            {
                Pipe      oldErrorOutputPipe = _context.ShellFunctionErrorOutputPipe;
                Exception exceptionToThrow   = null;
                try
                {
                    //
                    // On V1 the output pipe was redirected to the command's output pipe only when it
                    // was already redirected. This is the original comment explaining this behaviour:
                    //
                    //      NTRAID#Windows Out of Band Releases-926183-2005-12-15
                    //      MonadTestHarness has a bad dependency on an artifact of the current implementation
                    //      The following code only redirects the output pipe if it's already redirected
                    //      to preserve the artifact. The test suites need to be fixed and then this
                    //      the check can be removed and the assignment always done.
                    //
                    // However, this makes the hosting APIs behave differently than commands executed
                    // from the command-line host (for example, see bugs Win7:415915 and Win7:108670).
                    // The RedirectShellErrorOutputPipe flag is used by the V2 hosting API to force the
                    // redirection.
                    //
                    if (this.RedirectShellErrorOutputPipe || _context.ShellFunctionErrorOutputPipe != null)
                    {
                        _context.ShellFunctionErrorOutputPipe = this.commandRuntime.ErrorOutputPipe;
                    }

                    // NOTICE-2004/06/08-JonN 959638
                    using (commandRuntime.AllowThisCommandToWrite(true))
                    {
                        if (CmdletParameterBinderController.ObsoleteParameterWarningList != null &&
                            CmdletParameterBinderController.ObsoleteParameterWarningList.Count > 0)
                        {
                            // Write out warning messages for the pipeline-value-bound obsolete parameters.
                            // The warning message are generated during parameter binding, but we delay writing
                            // them out until now so that the -WarningAction will be respected as expected.
                            foreach (WarningRecord warningRecord in CmdletParameterBinderController.ObsoleteParameterWarningList)
                            {
                                CommandRuntime.WriteWarning(warningRecord);
                            }

                            // Clear up the warning message list
                            CmdletParameterBinderController.ObsoleteParameterWarningList.Clear();
                        }

                        this.Command.MyInvocation.PipelineIterationInfo[this.Command.MyInvocation.PipelinePosition]++;

                        Command.DoProcessRecord();
                    }
                }
                catch (RuntimeException rte)
                {
                    // Most exceptions get wrapped here, but an exception that originated from
                    // a throw statement should not get wrapped, so it is just rethrown.
                    if (rte.WasThrownFromThrowStatement)
                    {
                        throw;
                    }

                    exceptionToThrow = rte;
                }
                catch (LoopFlowException)
                {
                    // Win8:84066 - Don't wrap LoopFlowException, we incorrectly raise a PipelineStoppedException
                    // which gets caught by a script try/catch if we wrap here.
                    throw;
                }
                // 2004/03/18-JonN This is understood to be
                // an FXCOP violation, cleared by KCwalina.
                catch (Exception e) // Catch-all OK, 3rd party callout.
                {
                    exceptionToThrow = e;
                }
                finally
                {
                    _context.ShellFunctionErrorOutputPipe = oldErrorOutputPipe;
                }

                if (exceptionToThrow != null)
                {
                    // This cmdlet threw an exception, so
                    // wrap it and bubble it up.
                    throw ManageInvocationException(exceptionToThrow);
                }
            }
        }