From 772ed422f3195c899246f16c9c2e5b5a839d06cd Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Fri, 17 Jan 2020 21:06:00 -0500 Subject: Let listeners adjust message levels; general messaging cleanup. --- .../TestMessageListener.cs | 5 +- .../ExtensibilityServices/Messaging.cs | 89 +--------------------- 2 files changed, 7 insertions(+), 87 deletions(-) diff --git a/src/WixToolset.Core.TestPackage/TestMessageListener.cs b/src/WixToolset.Core.TestPackage/TestMessageListener.cs index 246cddd8..b5863869 100644 --- a/src/WixToolset.Core.TestPackage/TestMessageListener.cs +++ b/src/WixToolset.Core.TestPackage/TestMessageListener.cs @@ -1,6 +1,7 @@ -using System.Collections.Generic; +using System.Collections.Generic; using WixToolset.Data; using WixToolset.Extensibility; +using WixToolset.Extensibility.Services; namespace WixToolset.Core.TestPackage { @@ -21,5 +22,7 @@ namespace WixToolset.Core.TestPackage { this.Messages.Add(new Message(null, MessageLevel.Information, 0, message)); } + + public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; } } diff --git a/src/WixToolset.Core/ExtensibilityServices/Messaging.cs b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs index f4673952..266d842a 100644 --- a/src/WixToolset.Core/ExtensibilityServices/Messaging.cs +++ b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs @@ -41,94 +41,9 @@ namespace WixToolset.Core.ExtensibilityServices this.suppressedWarnings.Add(warningNumber); } - public string FormatMessage(Message message) - { - var level = CalculateMessageLevel(message); - - if (level == MessageLevel.Nothing) - { - return String.Empty; - } - - var shortAppName = String.IsNullOrEmpty(this.listener?.ShortAppName) ? "WIX" : this.listener.ShortAppName; - var longAppName = String.IsNullOrEmpty(this.listener?.LongAppName) ? "WIX" : this.listener.LongAppName; - - var fileNames = new List(); - var errorFileName = longAppName; - for (var sln = message.SourceLineNumbers; null != sln; sln = sln.Parent) - { - if (String.IsNullOrEmpty(sln.FileName)) - { - continue; - } - else if (sln.LineNumber.HasValue) - { - if (fileNames.Count == 0) - { - errorFileName = String.Format(CultureInfo.CurrentUICulture, "{0}({1})", sln.FileName, sln.LineNumber); - } - - fileNames.Add(String.Format(CultureInfo.CurrentUICulture, "{0}: line {1}", sln.FileName, sln.LineNumber)); - } - else - { - if (fileNames.Count == 0) - { - errorFileName = sln.FileName; - } - - fileNames.Add(sln.FileName); - } - } - - var levelString = String.Empty; - if (MessageLevel.Warning == level) - { - levelString = "warning"; - } - else if (MessageLevel.Error == level) - { - levelString = "error"; - } - - string formatted; - if (message.ResourceManager == null) - { - formatted = String.Format(CultureInfo.InvariantCulture, message.ResourceNameOrFormat, message.MessageArgs); - } - else - { - formatted = String.Format(CultureInfo.InvariantCulture, message.ResourceManager.GetString(message.ResourceNameOrFormat), message.MessageArgs); - } - - var builder = new StringBuilder(); - if (level == MessageLevel.Information || level == MessageLevel.Verbose) - { - builder.Append(formatted); - } - else - { - builder.AppendFormat("{0} : {1} {2}{3:0000} : {4}", errorFileName, levelString, shortAppName, message.Id, formatted); - } - - if (fileNames.Count > 1) - { - builder.AppendFormat("Source trace:{0}", Environment.NewLine); - - foreach (var fileName in fileNames) - { - builder.AppendFormat("Source trace:{0}", fileName, Environment.NewLine); - } - - builder.AppendLine(); - } - - return builder.ToString(); - } - public void Write(Message message) { - var level = CalculateMessageLevel(message); + var level = this.CalculateMessageLevel(message); if (level == MessageLevel.Nothing) { @@ -188,6 +103,8 @@ namespace WixToolset.Core.ExtensibilityServices } } + level = this.listener?.CalculateMessageLevel(this, message, level) ?? level; + return level; } } -- cgit v1.2.3-55-g6feb