diff options
| author | Bob Arnson <bob@firegiant.com> | 2020-01-17 21:51:39 -0500 |
|---|---|---|
| committer | Bob Arnson <bob@firegiant.com> | 2020-01-17 21:55:21 -0500 |
| commit | 487f0f8afcb3431420e2106819cb7fd0afe4e118 (patch) | |
| tree | 719d77f3ad02f3a74eecbc136135a7055c26a9e9 /src/WixToolset.Tools.Core | |
| parent | 8a6725ecd90da93e063e57f79f2910936ec16133 (diff) | |
| download | wix-487f0f8afcb3431420e2106819cb7fd0afe4e118.tar.gz wix-487f0f8afcb3431420e2106819cb7fd0afe4e118.tar.bz2 wix-487f0f8afcb3431420e2106819cb7fd0afe4e118.zip | |
Let listeners adjust message levels; general messaging cleanup.
Diffstat (limited to 'src/WixToolset.Tools.Core')
| -rw-r--r-- | src/WixToolset.Tools.Core/ConsoleMessageListener.cs | 72 |
1 files changed, 56 insertions, 16 deletions
diff --git a/src/WixToolset.Tools.Core/ConsoleMessageListener.cs b/src/WixToolset.Tools.Core/ConsoleMessageListener.cs index 5b1fb988..709fb576 100644 --- a/src/WixToolset.Tools.Core/ConsoleMessageListener.cs +++ b/src/WixToolset.Tools.Core/ConsoleMessageListener.cs | |||
| @@ -1,39 +1,54 @@ | |||
| 1 | using System; | 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | using System.Globalization; | ||
| 3 | using System.Text; | ||
| 4 | using System.Threading; | ||
| 5 | using WixToolset.Data; | ||
| 6 | using WixToolset.Extensibility; | ||
| 7 | 2 | ||
| 8 | namespace WixToolset.Tools.Core | 3 | namespace WixToolset.Tools.Core |
| 9 | { | 4 | { |
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Linq; | ||
| 8 | using System.Globalization; | ||
| 9 | using System.Text; | ||
| 10 | using System.Threading; | ||
| 11 | using WixToolset.Data; | ||
| 12 | using WixToolset.Extensibility; | ||
| 13 | using WixToolset.Extensibility.Services; | ||
| 14 | |||
| 10 | public sealed class ConsoleMessageListener : IMessageListener | 15 | public sealed class ConsoleMessageListener : IMessageListener |
| 11 | { | 16 | { |
| 12 | public ConsoleMessageListener(string shortName, string longName) | 17 | public ConsoleMessageListener(string prefix, string appName) |
| 13 | { | 18 | { |
| 14 | this.ShortAppName = shortName; | 19 | this.Prefix = prefix; |
| 15 | this.LongAppName = longName; | 20 | this.AppName = appName; |
| 16 | 21 | ||
| 17 | PrepareConsoleForLocalization(); | 22 | PrepareConsoleForLocalization(); |
| 18 | } | 23 | } |
| 19 | 24 | ||
| 20 | public string LongAppName { get; } | 25 | public string AppName { get; } |
| 21 | 26 | ||
| 22 | public string ShortAppName { get; } | 27 | public string Prefix { get; } |
| 23 | 28 | ||
| 24 | public void Write(Message message) | 29 | public void Write(Message message) |
| 25 | { | 30 | { |
| 26 | var filename = message.SourceLineNumbers?.FileName ?? this.LongAppName; | 31 | var filename = message.SourceLineNumbers?.FileName ?? this.AppName; |
| 27 | var line = message.SourceLineNumbers?.LineNumber ?? -1; | ||
| 28 | var type = message.Level.ToString().ToLowerInvariant(); | 32 | var type = message.Level.ToString().ToLowerInvariant(); |
| 29 | var output = message.Level >= MessageLevel.Warning ? Console.Out : Console.Error; | 33 | var output = message.Level >= MessageLevel.Warning ? Console.Out : Console.Error; |
| 30 | 34 | ||
| 31 | if (line > 0) | 35 | if (message.SourceLineNumbers?.LineNumber.HasValue == true) |
| 32 | { | 36 | { |
| 33 | filename = String.Concat(filename, "(", line, ")"); | 37 | filename = String.Concat(filename, "(", message.SourceLineNumbers?.LineNumber.Value, ")"); |
| 34 | } | 38 | } |
| 35 | 39 | ||
| 36 | output.WriteLine("{0} : {1} {2}{3:0000}: {4}", filename, type, this.ShortAppName, message.Id, message.ToString()); | 40 | output.WriteLine("{0} : {1} {2}{3:0000}: {4}", filename, type, this.Prefix, message.Id, message.ToString()); |
| 41 | |||
| 42 | var fileNames = GetFileNames(message.SourceLineNumbers); | ||
| 43 | if (fileNames.Any()) | ||
| 44 | { | ||
| 45 | output.WriteLine("Source trace:"); | ||
| 46 | |||
| 47 | foreach (var fileName in fileNames) | ||
| 48 | { | ||
| 49 | output.WriteLine("Source trace: {0}", fileName); | ||
| 50 | } | ||
| 51 | } | ||
| 37 | } | 52 | } |
| 38 | 53 | ||
| 39 | public void Write(string message) | 54 | public void Write(string message) |
| @@ -41,6 +56,31 @@ namespace WixToolset.Tools.Core | |||
| 41 | Console.Out.WriteLine(message); | 56 | Console.Out.WriteLine(message); |
| 42 | } | 57 | } |
| 43 | 58 | ||
| 59 | public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; | ||
| 60 | |||
| 61 | private static IList<string> GetFileNames(SourceLineNumber sourceLineNumbers) | ||
| 62 | { | ||
| 63 | var fileNames = new List<string>(); | ||
| 64 | |||
| 65 | for (var sln = sourceLineNumbers; null != sln; sln = sln.Parent) | ||
| 66 | { | ||
| 67 | if (String.IsNullOrEmpty(sln.FileName)) | ||
| 68 | { | ||
| 69 | continue; | ||
| 70 | } | ||
| 71 | else if (sln.LineNumber.HasValue) | ||
| 72 | { | ||
| 73 | fileNames.Add(String.Format(CultureInfo.CurrentUICulture, "{0}: line {1}", sln.FileName, sln.LineNumber)); | ||
| 74 | } | ||
| 75 | else | ||
| 76 | { | ||
| 77 | fileNames.Add(sln.FileName); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | return fileNames; | ||
| 82 | } | ||
| 83 | |||
| 44 | private static void PrepareConsoleForLocalization() | 84 | private static void PrepareConsoleForLocalization() |
| 45 | { | 85 | { |
| 46 | Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture(); | 86 | Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture(); |
