Ejemplo n.º 1
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
                _argumentBinder.BindPipelineParameters(curInput, true);
                Command.DoProcessRecord();
            }
            _argumentBinder.RestoreCommandLineParameterValues();
        }
Ejemplo n.º 2
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();
        }