public void EventArgsCtors()
 {
     CriticalBuildMessageEventArgs cbmea = new CriticalBuildMessageEventArgs2();
     cbmea = new CriticalBuildMessageEventArgs("Subcategory", "Code", "File", 1, 2, 3, 4, "Message", "HelpKeyword", "Sender");
     cbmea = new CriticalBuildMessageEventArgs("Subcategory", "Code", "File", 1, 2, 3, 4, "Message", "HelpKeyword", "Sender", DateTime.Now);
     cbmea = new CriticalBuildMessageEventArgs("Subcategory", "Code", "File", 1, 2, 3, 4, "{0}", "HelpKeyword", "Sender", DateTime.Now, "Message");
     cbmea = new CriticalBuildMessageEventArgs(null, null, null, 0, 0, 0, 0, null, null, null);
     cbmea = new CriticalBuildMessageEventArgs(null, null, null, 0, 0, 0, 0, null, null, null, DateTime.Now);
     cbmea = new CriticalBuildMessageEventArgs(null, null, null, 0, 0, 0, 0, null, null, null, DateTime.Now, null);
 }
        public void TestCriticalBuildMessageEventArgs()
        {
            // Test using reasonable messages
            CriticalBuildMessageEventArgs criticalMessageEvent = new CriticalBuildMessageEventArgs("SubCategory", "Code", "File", 1, 2, 3, 4, "Message", "HelpKeyword", "SenderName");
            criticalMessageEvent.BuildEventContext = new BuildEventContext(5, 4, 3, 2);

            // Serialize
            criticalMessageEvent.WriteToStream(_writer);
            long streamWriteEndPosition = _stream.Position;

            // Deserialize and Verify
            _stream.Position = 0;
            CriticalBuildMessageEventArgs newCriticalMessageEvent = new CriticalBuildMessageEventArgs(null, null, null, 0, 0, 0, 0, null, null, null);
            newCriticalMessageEvent.CreateFromStream(_reader, _eventArgVersion);
            long streamReadEndPosition = _stream.Position;
            Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
            VerifyMessageEventArg(criticalMessageEvent, newCriticalMessageEvent);

            // Test empty strings
            _stream.Position = 0;
            // Make sure empty strings are passed correctly
            criticalMessageEvent = new CriticalBuildMessageEventArgs(string.Empty, string.Empty, string.Empty, 1, 2, 3, 4, string.Empty, string.Empty, string.Empty);
            criticalMessageEvent.BuildEventContext = new BuildEventContext(5, 4, 3, 2);

            // Serialize
            criticalMessageEvent.WriteToStream(_writer);
            streamWriteEndPosition = _stream.Position;

            // Deserialize and Verify
            _stream.Position = 0;
            newCriticalMessageEvent = new CriticalBuildMessageEventArgs(null, null, null, 0, 0, 0, 0, null, null, null);
            newCriticalMessageEvent.CreateFromStream(_reader, _eventArgVersion);
            streamReadEndPosition = _stream.Position;
            Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
            VerifyMessageEventArg(criticalMessageEvent, newCriticalMessageEvent);

            // Test null strings
            _stream.Position = 0;
            // Make sure null string are passed correctly
            criticalMessageEvent = new CriticalBuildMessageEventArgs(null, null, null, 1, 2, 3, 4, null, null, null);
            criticalMessageEvent.BuildEventContext = null;

            // Serialize
            criticalMessageEvent.WriteToStream(_writer);
            streamWriteEndPosition = _stream.Position;

            // Deserialize and Verify
            _stream.Position = 0;
            newCriticalMessageEvent = new CriticalBuildMessageEventArgs("Something", "Something", "Something", 0, 0, 0, 0, "Something", "Something", "Something");
            newCriticalMessageEvent.CreateFromStream(_reader, _eventArgVersion);
            streamReadEndPosition = _stream.Position;
            Assert.IsTrue(streamWriteEndPosition == streamReadEndPosition, "Stream End Positions Should Match");
            VerifyMessageEventArg(criticalMessageEvent, newCriticalMessageEvent);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Logs a critical message using the specified string and other message details.
        /// Thread safe.
        /// </summary>
        /// <param name="subcategory">Description of the warning type (can be null).</param>
        /// <param name="code">Message code (can be null).</param>
        /// <param name="helpKeyword">The help keyword for the host IDE (can be null).</param>
        /// <param name="file">The path to the file causing the message (can be null).</param>
        /// <param name="lineNumber">The line in the file causing the message (set to zero if not available).</param>
        /// <param name="columnNumber">The column in the file causing the message (set to zero if not available).</param>
        /// <param name="endLineNumber">The last line of a range of lines in the file causing the message (set to zero if not available).</param>
        /// <param name="endColumnNumber">The last column of a range of columns in the file causing the message (set to zero if not available).</param>
        /// <param name="message">The message string.</param>
        /// <param name="messageArgs">Optional arguments for formatting the message string.</param>
        /// <exception cref="ArgumentNullException">Thrown when <c>message</c> is null.</exception>
        public void LogCriticalMessage
        (
            string subcategory,
            string code,
            string helpKeyword,
            string file,
            int lineNumber,
            int columnNumber,
            int endLineNumber,
            int endColumnNumber,
            string message,
            params object[] messageArgs
        )
        {
            // No lock needed, as BuildEngine methods from v4.5 onwards are thread safe.
            ErrorUtilities.VerifyThrowArgumentNull(message, "message");

            // If BuildEngine is null, task attempted to log before it was set on it,
            // presumably in its constructor. This is not allowed, and all
            // we can do is throw.
            ErrorUtilities.VerifyThrowInvalidOperation(BuildEngine != null, "LoggingBeforeTaskInitialization", message);

            // If the task has missed out all location information, add the location of the task invocation;
            // that gives the user something.
            bool fillInLocation = (String.IsNullOrEmpty(file) && (lineNumber == 0) && (columnNumber == 0));

            CriticalBuildMessageEventArgs e = new CriticalBuildMessageEventArgs
                (
                    subcategory,
                    code,
                    fillInLocation ? BuildEngine.ProjectFileOfTaskNode : file,
                    fillInLocation ? BuildEngine.LineNumberOfTaskNode : lineNumber,
                    fillInLocation ? BuildEngine.ColumnNumberOfTaskNode : columnNumber,
                    endLineNumber,
                    endColumnNumber,
                    message,
                    helpKeyword,
                    TaskName,
                    DateTime.UtcNow,
                    messageArgs
                );

            BuildEngine.LogMessageEvent(e);
        }