Esempio n. 1
0
 /// <summary>
 /// Throws InternalErrorException.
 /// This is only for situations that would mean that there is a bug in MSBuild itself.
 /// </summary>
 internal static void ThrowInternalError(string message, Exception innerException, params object[] args)
 {
     if (s_throwExceptions)
     {
         throw new InternalErrorException(ResourceUtilities.FormatString(message, args), innerException);
     }
 }
Esempio n. 2
0
 internal static void VerifyThrowInternalError(bool condition, string message, params object[] args)
 {
     if (s_throwExceptions && !condition)
     {
         throw new InternalErrorException(ResourceUtilities.FormatString(message, args));
     }
 }
Esempio n. 3
0
 private void VerifyStack
 (
     bool condition,
     string unformattedMessage,
     params object[] args
 )
 {
     if (!condition && !ignoreLoggerErrors)
     {
         string errorMessage = "INTERNAL CONSOLE LOGGER ERROR. " + ResourceUtilities.FormatString(unformattedMessage, args);
         ErrorUtilities.ThrowInternalError(errorMessage);
     }
 }
        internal static void VerifyThrow(bool condition, string messageResourceName, string invalidSwitch, params object[] args)
        {
            if (!condition)
            {
                string errorMessage = AssemblyResources.GetString(messageResourceName);

                ErrorUtilities.VerifyThrow(errorMessage != null, "The resource string must exist.");

                errorMessage = ResourceUtilities.FormatString(errorMessage, args);

                InitializationException.Throw(errorMessage, invalidSwitch);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Generates the message event corresponding to a particular resource string and set of args
        /// </summary>
        private void LogMessageFromResource(MessageImportance importance, string messageResource, params object[] messageArgs)
        {
            ErrorUtilities.VerifyThrow(_currentConfiguration != null, "We should never have a null configuration when we're trying to log messages!");

            // Using the CLR 2 build event because this class is shared between MSBuildTaskHost.exe (CLR2) and MSBuild.exe (CLR4+)
            BuildMessageEventArgs message = new BuildMessageEventArgs
                                            (
                ResourceUtilities.FormatString(AssemblyResources.GetString(messageResource), messageArgs),
                null,
                _currentConfiguration.TaskName,
                importance
                                            );

            LogMessageEvent(message);
        }
 /// <summary>
 /// Logs errors from TaskLoader
 /// </summary>
 private void LogErrorDelegate(string taskLocation, int taskLine, int taskColumn, string message, params object[] messageArgs)
 {
     buildEngine.LogErrorEvent(new BuildErrorEventArgs(
                                   null,
                                   null,
                                   taskLocation,
                                   taskLine,
                                   taskColumn,
                                   0,
                                   0,
                                   ResourceUtilities.FormatString(AssemblyResources.GetString(message), messageArgs),
                                   null,
                                   taskName
                                   )
                               );
 }
        /// <summary>
        /// Throws the exception using the given exception context.
        /// </summary>
        /// <param name="messageResourceName"></param>
        /// <param name="invalidSwitch"></param>
        /// <param name="e"></param>
        /// <param name="showStackTrace"></param>
        internal static void Throw(string messageResourceName, string invalidSwitch, Exception e, bool showStackTrace)
        {
            string errorMessage = AssemblyResources.GetString(messageResourceName);

            ErrorUtilities.VerifyThrow(errorMessage != null, "The resource string must exist.");

            if (showStackTrace)
            {
                errorMessage += Environment.NewLine + e.ToString();
            }
            else
            {
                // the exception message can contain a format item i.e. "{0}" to hold the given exception's message
                errorMessage = ResourceUtilities.FormatString(errorMessage, ((e == null) ? String.Empty : e.Message));
            }

            InitializationException.Throw(errorMessage, invalidSwitch);
        }
Esempio n. 8
0
        /// <summary>
        /// Checks the condition passed in.  If it's false, it emits an error message to the console
        /// indicating that there's a problem with the console logger.  These "problems" should
        /// never occur in the real world after we ship, unless there's a bug in the MSBuild
        /// engine such that events aren't getting paired up properly.  So the messages don't
        /// really need to be localized here, since they're only for our own benefit, and have
        /// zero value to a customer.
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="unformattedMessage"></param>
        /// <param name="args"></param>
        /// <owner>RGoel</owner>
        private void VerifyStack
        (
            bool condition,
            string unformattedMessage,
            params object[] args
        )
        {
            if (!condition && !ignoreLoggerErrors)
            {
                string errorMessage            = "INTERNAL CONSOLE LOGGER ERROR. " + ResourceUtilities.FormatString(unformattedMessage, args);
                BuildErrorEventArgs errorEvent = new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0,
                                                                         errorMessage, null, null);

                Debug.Assert(false, errorMessage);

                ErrorHandler(null, errorEvent);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Generates the error event corresponding to a particular resource string and set of args
        /// </summary>
        private void LogWarningFromResource(string messageResource, params object[] messageArgs)
        {
            ErrorUtilities.VerifyThrow(_currentConfiguration != null, "We should never have a null configuration when we're trying to log warnings!");

            // Using the CLR 2 build event because this class is shared between MSBuildTaskHost.exe (CLR2) and MSBuild.exe (CLR4+)
            BuildWarningEventArgs warning = new BuildWarningEventArgs
                                            (
                null,
                null,
                ProjectFileOfTaskNode,
                LineNumberOfTaskNode,
                ColumnNumberOfTaskNode,
                0,
                0,
                ResourceUtilities.FormatString(AssemblyResources.GetString(messageResource), messageArgs),
                null,
                _currentConfiguration.TaskName
                                            );

            LogWarningEvent(warning);
        }
 public virtual string FormatString(string unformatted, params object[] args)
 {
     ErrorUtilities.VerifyThrowArgumentNull(unformatted, "unformatted");
     return(ResourceUtilities.FormatString(unformatted, args));
 }