Example #1
0
 internal static void ThrowExceptionOnError(string errorId, Collection <string> errors, RunspaceConfigurationCategory category)
 {
     if (errors.Count != 0)
     {
         StringBuilder builder = new StringBuilder();
         builder.Append('\n');
         foreach (string str in errors)
         {
             builder.Append(str);
             builder.Append('\n');
         }
         string message = "";
         if (category == RunspaceConfigurationCategory.Types)
         {
             message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString());
         }
         else if (category == RunspaceConfigurationCategory.Formats)
         {
             message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString());
         }
         RuntimeException exception = new RuntimeException(message);
         exception.SetErrorId(errorId);
         throw exception;
     }
 }
Example #2
0
        internal static void ThrowExceptionOnError(
            string errorId,
            ConcurrentBag <string> errors,
            RunspaceConfigurationCategory category)
        {
            if (errors.Count == 0)
            {
                return;
            }

            StringBuilder allErrors = new StringBuilder();

            allErrors.Append('\n');
            foreach (string error in errors)
            {
                allErrors.Append(error);
                allErrors.Append('\n');
            }

            string message = "";

            if (category == RunspaceConfigurationCategory.Types)
            {
                message =
                    StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString());
            }
            else if (category == RunspaceConfigurationCategory.Formats)
            {
                message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString());
            }
            RuntimeException ex = new RuntimeException(message);

            ex.SetErrorId(errorId);
            throw ex;
        }
Example #3
0
        internal static void ThrowExceptionOnError(
            string errorId,
            Collection <string> independentErrors,
            Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection,
            Category category)
        {
            Collection <string> errors = new Collection <string>();

            if (independentErrors != null)
            {
                foreach (string error in independentErrors)
                {
                    errors.Add(error);
                }
            }

            foreach (PSSnapInTypeAndFormatErrors PSSnapinFiles in PSSnapinFilesCollection)
            {
                foreach (string error in PSSnapinFiles.Errors)
                {
                    errors.Add(error);
                }
            }

            if (errors.Count == 0)
            {
                return;
            }

            StringBuilder allErrors = new StringBuilder();

            allErrors.Append('\n');
            foreach (string error in errors)
            {
                allErrors.Append(error);
                allErrors.Append('\n');
            }

            string message = string.Empty;

            if (category == Category.Types)
            {
                message =
                    StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString());
            }
            else if (category == Category.Formats)
            {
                message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString());
            }

            RuntimeException ex = new RuntimeException(message);

            ex.SetErrorId(errorId);
            throw ex;
        }
        internal static void ThrowExceptionOnError(
            string errorId,
            Collection <string> independentErrors,
            Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection,
            RunspaceConfigurationCategory category)
        {
            Collection <string> collection = new Collection <string>();

            foreach (string independentError in independentErrors)
            {
                collection.Add(independentError);
            }
            foreach (PSSnapInTypeAndFormatErrors psSnapinFiles in PSSnapinFilesCollection)
            {
                foreach (string error in psSnapinFiles.Errors)
                {
                    collection.Add(error);
                }
            }
            if (collection.Count != 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append('\n');
                foreach (string str in collection)
                {
                    stringBuilder.Append(str);
                    stringBuilder.Append('\n');
                }
                string message = "";
                switch (category)
                {
                case RunspaceConfigurationCategory.Types:
                    message = ResourceManagerCache.FormatResourceString("ExtendedTypeSystem", "TypesXmlError", (object)stringBuilder.ToString());
                    break;

                case RunspaceConfigurationCategory.Formats:
                    message = XmlLoadingResourceManager.FormatString("FormatLoadingErrors", (object)stringBuilder.ToString());
                    break;
                }
                RuntimeException runtimeException = new RuntimeException(message);
                runtimeException.SetErrorId(errorId);
                throw runtimeException;
            }
        }
Example #5
0
        internal static void ThrowExceptionOnError(string errorId, Collection <string> independentErrors, Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category)
        {
            Collection <string> collection = new Collection <string>();

            if (independentErrors != null)
            {
                foreach (string str in independentErrors)
                {
                    collection.Add(str);
                }
            }
            foreach (PSSnapInTypeAndFormatErrors errors in PSSnapinFilesCollection)
            {
                foreach (string str2 in errors.Errors)
                {
                    collection.Add(str2);
                }
            }
            if (collection.Count != 0)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append('\n');
                foreach (string str3 in collection)
                {
                    builder.Append(str3);
                    builder.Append('\n');
                }
                string message = "";
                if (category == RunspaceConfigurationCategory.Types)
                {
                    message = StringUtil.Format(ExtendedTypeSystem.TypesXmlError, builder.ToString());
                }
                else if (category == RunspaceConfigurationCategory.Formats)
                {
                    message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, builder.ToString());
                }
                RuntimeException exception = new RuntimeException(message);
                exception.SetErrorId(errorId);
                throw exception;
            }
        }
        internal static void ThrowExceptionOnError(
            string errorId,
            ConcurrentBag<string> errors,
            RunspaceConfigurationCategory category)
        {
            if (errors.Count == 0)
            {
                return;
            }

            StringBuilder allErrors = new StringBuilder();

            allErrors.Append('\n');
            foreach (string error in errors)
            {
                allErrors.Append(error);
                allErrors.Append('\n');
            }

            string message = "";
            if (category == RunspaceConfigurationCategory.Types)
            {
                message =
                    StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString());
            }
            else if (category == RunspaceConfigurationCategory.Formats)
            {
                message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString());
            }
            RuntimeException ex = new RuntimeException(message);
            ex.SetErrorId(errorId);
            throw ex;
        }
        internal static void ThrowExceptionOnError(
            string errorId,
            Collection<string> independentErrors,
            Collection<PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection,
            RunspaceConfigurationCategory category)
        {
            Collection<string> errors = new Collection<string>();
            if (independentErrors != null)
            {
                foreach (string error in independentErrors)
                {
                    errors.Add(error);
                }
            }

            foreach (PSSnapInTypeAndFormatErrors PSSnapinFiles in PSSnapinFilesCollection)
            {
                foreach (string error in PSSnapinFiles.Errors)
                {
                    errors.Add(error);
                }
            }

            if (errors.Count == 0)
            {
                return;
            }

            StringBuilder allErrors = new StringBuilder();

            allErrors.Append('\n');
            foreach (string error in errors)
            {
                allErrors.Append(error);
                allErrors.Append('\n');
            }

            string message = "";
            if (category == RunspaceConfigurationCategory.Types)
            {
                message =
                    StringUtil.Format(ExtendedTypeSystem.TypesXmlError, allErrors.ToString());
            }
            else if (category == RunspaceConfigurationCategory.Formats)
            {
                message = StringUtil.Format(FormatAndOutXmlLoadingStrings.FormatLoadingErrors, allErrors.ToString());
            }
            RuntimeException ex = new RuntimeException(message);
            ex.SetErrorId(errorId);
            throw ex;
        }
Example #8
0
        /// <summary>
        /// Implements DoComplete as a stand-alone function for completing
        /// the execution of a steppable pipeline.
        /// </summary>
        /// <returns>The results of the execution</returns>
        internal Array DoComplete()
        {
            if (Stopping)
            {
                throw new PipelineStoppedException();
            }

            if (!_executionStarted)
            {
                throw PSTraceSource.NewInvalidOperationException(
                    PipelineStrings.PipelineNotStarted);
            }

            ExceptionDispatchInfo toRethrowInfo;
            try
            {
                DoCompleteCore(null);

                return RetrieveResults();
            }
            catch (RuntimeException e)
            {
                // The error we want to report is the first terminating error
                // which occurred during pipeline execution, regardless
                // of whether other errors occurred afterward.
                toRethrowInfo = _firstTerminatingError ?? ExceptionDispatchInfo.Capture(e);
                this.LogExecutionException(toRethrowInfo.SourceException);
            }
            // NTRAID#Windows Out Of Band Releases-929020-2006/03/14-JonN
            catch (System.Runtime.InteropServices.InvalidComObjectException comException)
            {
                // The error we want to report is the first terminating error
                // which occurred during pipeline execution, regardless
                // of whether other errors occurred afterward.
                if (null != _firstTerminatingError)
                {
                    toRethrowInfo = _firstTerminatingError;
                }
                else
                {
                    string message = StringUtil.Format(ParserStrings.InvalidComObjectException, comException.Message);
                    var rte = new RuntimeException(message, comException);
                    rte.SetErrorId("InvalidComObjectException");
                    toRethrowInfo = ExceptionDispatchInfo.Capture(rte);
                }

                this.LogExecutionException(toRethrowInfo.SourceException);
            }
            finally
            {
                DisposeCommands();
            }

            // By rethrowing the exception outside of the handler,
            // we allow the CLR on X64/IA64 to free from the stack
            // the exception records related to this exception.

            // The only reason we should get here is if
            // an exception should be rethrown.
            Diagnostics.Assert(null != toRethrowInfo, "Alternate protocol path failure");
            toRethrowInfo.Throw();
            return null; // UNREACHABLE
        } // internal Array DoComplete()
Example #9
0
        } // AddCommand( CommandProcessorBase commandProcessor, int readFromCommand, bool readErrorQueue )

        // 2005/03/08-JonN: This is an internal API
        /// <summary>
        /// Execute the accumulated commands and clear the pipeline.
        /// SynchronousExecute does not return until all commands have
        /// completed.  There is no asynchronous variant; instead, once the
        /// pipeline is set up, the caller can spawn a thread and call
        /// SynchronousExecute from that thread.  This does not mean that
        /// PipelineProcessor is thread-safe; once SynchronousExecute is
        /// running, PipelineProcessor should not be accessed through any
        /// other means. This variant of the routine looks at it's input
        /// object to see if it's enumerable or not.
        /// </summary>
        /// <param name="input">
        /// Input objects for first stage. If this is AutomationNull.Value, the
        /// first cmdlet is the beginning of the pipeline.
        /// </param>
        /// <returns>
        /// Results from last pipeline stage.  This will be empty if
        /// ExternalSuccessOutput is set.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// ExecutionAlreadyStarted: pipeline has already started or completed
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// PipelineExecuteRequiresAtLeastOneCommand
        /// </exception>
        /// <exception cref="CmdletInvocationException">
        /// A cmdlet encountered a terminating error
        /// </exception>
        /// <exception cref="PipelineStoppedException">
        /// The pipeline was stopped asynchronously
        /// </exception>
        /// <exception cref="ActionPreferenceStopException">
        /// The ActionPreference.Stop or ActionPreference.Inquire policy
        /// triggered a terminating error.
        /// </exception>
        /// <exception cref="ParameterBindingException">
        /// If any parameters fail to bind,
        /// or
        /// If any mandatory parameters are missing.
        /// </exception>
        /// <exception cref="MetadataException">
        /// If there is an error generating the metadata for dynamic parameters.
        /// </exception>
        /// <exception cref="ExtendedTypeSystemException">
        /// An error occurred clearing the error variable.
        /// </exception>
        /// <exception cref="HaltCommandException">
        /// HaltCommandException will cause the command
        /// to stop, but should not be reported as an error.
        /// </exception>
        internal Array SynchronousExecuteEnumerate(object input)
        {
            if (Stopping)
            {
                throw new PipelineStoppedException();
            }

            ExceptionDispatchInfo toRethrowInfo;
            try
            {
                CommandProcessorBase commandRequestingUpstreamCommandsToStop = null;
                try
                {
                    // If the caller specified an input object array,
                    // we run assuming there is an incoming "stream"
                    // of objects. This will prevent the one default call
                    // to ProcessRecord on the first command.
                    Start(input != AutomationNull.Value);

                    // Start has already validated firstcommandProcessor
                    CommandProcessorBase firstCommandProcessor = _commands[0];

                    // Add any input to the first command.
                    if (null != ExternalInput)
                    {
                        firstCommandProcessor.CommandRuntime.InputPipe.ExternalReader
                            = ExternalInput;
                    }
                    Inject(input, enumerate: true);
                }
                catch (PipelineStoppedException)
                {
                    StopUpstreamCommandsException stopUpstreamCommandsException =
                        _firstTerminatingError != null
                            ? _firstTerminatingError.SourceException as StopUpstreamCommandsException
                            : null;
                    if (stopUpstreamCommandsException == null)
                    {
                        throw;
                    }
                    else
                    {
                        _firstTerminatingError = null;
                        commandRequestingUpstreamCommandsToStop = stopUpstreamCommandsException.RequestingCommandProcessor;
                    }
                }

                DoCompleteCore(commandRequestingUpstreamCommandsToStop);

                // By this point, we are sure all commandProcessors hosted by the current pipelineProcess are done execution,
                // so if there are any redirection pipelineProcessors associated with any of those commandProcessors, we should
                // call DoComplete on them.
                if (_redirectionPipes != null)
                {
                    foreach (PipelineProcessor redirectPipelineProcessor in _redirectionPipes)
                    {
                        redirectPipelineProcessor.DoCompleteCore(null);
                    }
                }

                return RetrieveResults();
            }
            catch (RuntimeException e)
            {
                // The error we want to report is the first terminating error
                // which occurred during pipeline execution, regardless
                // of whether other errors occurred afterward.
                toRethrowInfo = _firstTerminatingError ?? ExceptionDispatchInfo.Capture(e);
                this.LogExecutionException(toRethrowInfo.SourceException);
            }
            // NTRAID#Windows Out Of Band Releases-929020-2006/03/14-JonN
            catch (System.Runtime.InteropServices.InvalidComObjectException comException)
            {
                // The error we want to report is the first terminating error
                // which occurred during pipeline execution, regardless
                // of whether other errors occurred afterward.
                if (null != _firstTerminatingError)
                {
                    toRethrowInfo = _firstTerminatingError;
                }
                else
                {
                    string message = StringUtil.Format(ParserStrings.InvalidComObjectException, comException.Message);
                    var rte = new RuntimeException(message, comException);
                    rte.SetErrorId("InvalidComObjectException");
                    toRethrowInfo = ExceptionDispatchInfo.Capture(rte);
                }

                this.LogExecutionException(toRethrowInfo.SourceException);
            }
            finally
            {
                DisposeCommands();
            }

            // By rethrowing the exception outside of the handler,
            // we allow the CLR on X64/IA64 to free from the stack
            // the exception records related to this exception.

            // The only reason we should get here is if
            // an exception should be rethrown.
            Diagnostics.Assert(null != toRethrowInfo, "Alternate protocol path failure");
            toRethrowInfo.Throw();
            return null; // UNREACHABLE
        } // internal Array SynchronousExecuteEnumerate()