Пример #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);
            }
        }
Пример #2
0
 public void WriteError(ErrorRecord errorRecord)
 {
     if (CommandRuntime == null)
     {
         throw new NotImplementedException("WriteError");
     }
     CommandRuntime.WriteError(errorRecord);
 }
Пример #3
0
        /// <summary>
        /// In this phase, the "ProcessRecord" method of the command will be called for each
        /// object from the input pipeline, but at least once. Doing so, the input object
        /// will be bound as parameters, but only for the specific invocation.
        /// </summary>
        public override void ProcessRecords()
        {
            // check if we already called BeginProcessing for this command
            if (!_beganProcessing)
            {
                // this can happen if the previous element in the pipeline produces output in the BeginProcessing phase
                // than this command is asked to process the records but wasn't in the BeginProcessing phase, yet.
                BeginProcessing();
            }
            var inputObjects = CommandRuntime.InputStream.Read();

            foreach (var curInput in inputObjects)
            {
                // TODO: determine the correct second arg: true if this commandProcessor is the first command in pipeline
                try
                {
                    _argumentBinder.BindPipelineParameters(curInput, true);
                }
                catch (ParameterBindingException e)
                {
                    // if we failed to bind this parameter, we only skip this one record and continue
                    CommandRuntime.WriteError(e.ErrorRecord);
                    continue;
                }

                try
                {
                    Command.DoProcessRecord();
                }
                catch (Exception e)
                {
                    HandleInvocationException(e);
                }
            }
            _argumentBinder.RestoreCommandLineParameterValues();
        }