diff options
Diffstat (limited to 'src/WixToolset.Data/MessageEventArgs.cs')
-rw-r--r-- | src/WixToolset.Data/MessageEventArgs.cs | 176 |
1 files changed, 0 insertions, 176 deletions
diff --git a/src/WixToolset.Data/MessageEventArgs.cs b/src/WixToolset.Data/MessageEventArgs.cs deleted file mode 100644 index 472b5e95..00000000 --- a/src/WixToolset.Data/MessageEventArgs.cs +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
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 | |||
3 | namespace WixToolset.Data | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Diagnostics.CodeAnalysis; | ||
8 | using System.Globalization; | ||
9 | using System.Resources; | ||
10 | using System.Text; | ||
11 | |||
12 | /// <summary> | ||
13 | /// Event args for message events. | ||
14 | /// </summary> | ||
15 | public abstract class MessageEventArgs : EventArgs | ||
16 | { | ||
17 | private SourceLineNumber sourceLineNumbers; | ||
18 | private int id; | ||
19 | private string resourceName; | ||
20 | private object[] messageArgs; | ||
21 | private MessageLevel level; | ||
22 | |||
23 | /// <summary> | ||
24 | /// Creates a new MessageEventArgs. | ||
25 | /// </summary> | ||
26 | /// <param name="sourceLineNumbers">Source line numbers for the message.</param> | ||
27 | /// <param name="id">Id for the message.</param> | ||
28 | /// <param name="resourceName">Name of the resource.</param> | ||
29 | /// <param name="messageArgs">Arguments for the format string.</param> | ||
30 | protected MessageEventArgs(SourceLineNumber sourceLineNumbers, int id, string resourceName, params object[] messageArgs) | ||
31 | { | ||
32 | this.sourceLineNumbers = sourceLineNumbers; | ||
33 | this.id = id; | ||
34 | this.resourceName = resourceName; | ||
35 | this.messageArgs = messageArgs; | ||
36 | |||
37 | // Default to Nothing, since the default MessageEventArgs container | ||
38 | // classes define a level, and only WixErrorEventArgs previously | ||
39 | // determined that an error occured without throwing. | ||
40 | this.level = MessageLevel.Nothing; | ||
41 | } | ||
42 | |||
43 | /// <summary> | ||
44 | /// Gets the resource manager for this event args. | ||
45 | /// </summary> | ||
46 | /// <value>The resource manager for this event args.</value> | ||
47 | public ResourceManager ResourceManager { get; protected set; } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Gets the source line numbers. | ||
51 | /// </summary> | ||
52 | /// <value>The source line numbers.</value> | ||
53 | public SourceLineNumber SourceLineNumbers | ||
54 | { | ||
55 | get { return this.sourceLineNumbers; } | ||
56 | } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Gets the Id for the message. | ||
60 | /// </summary> | ||
61 | /// <value>The Id for the message.</value> | ||
62 | public int Id | ||
63 | { | ||
64 | get { return this.id; } | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Gets the name of the resource. | ||
69 | /// </summary> | ||
70 | /// <value>The name of the resource.</value> | ||
71 | public string ResourceName | ||
72 | { | ||
73 | get { return this.resourceName; } | ||
74 | } | ||
75 | |||
76 | /// <summary> | ||
77 | /// Gets or sets the <see cref="MessageLevel"/> for the message. | ||
78 | /// </summary> | ||
79 | /// <value>The <see cref="MessageLevel"/> for the message.</value> | ||
80 | /// <remarks> | ||
81 | /// The <see cref="MessageHandler"/> may set the level differently | ||
82 | /// depending on suppression and escalation of different message levels. | ||
83 | /// Message handlers should check the level to determine if an error | ||
84 | /// or other message level was raised. | ||
85 | /// </remarks> | ||
86 | public MessageLevel Level | ||
87 | { | ||
88 | get { return this.level; } | ||
89 | set { this.level = value; } | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Gets the arguments for the format string. | ||
94 | /// </summary> | ||
95 | /// <value>The arguments for the format string.</value> | ||
96 | [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] | ||
97 | public object[] MessageArgs | ||
98 | { | ||
99 | get { return this.messageArgs; } | ||
100 | } | ||
101 | |||
102 | /// <summary> | ||
103 | /// Creates a properly formatted message string. | ||
104 | /// </summary> | ||
105 | /// <param name="shortAppName">Optional short form of the application name that generated the message. Defaults to "WIX" if unspecified.</param> | ||
106 | /// <param name="longAppName">Optional long form of the application name that generated the message. Defaults to "WIX" if unspecified. Will be overridden by the processed filename if one was provided.</param> | ||
107 | /// <param name="overrideLevel">Optional override level of the message, as generated by MessageLevel(MessageEventArgs).</param> | ||
108 | /// <returns>String containing the formatted message.</returns> | ||
109 | public string GenerateMessageString(string shortAppName = null, string longAppName = null, MessageLevel overrideLevel = MessageLevel.Nothing) | ||
110 | { | ||
111 | MessageLevel messageLevel = MessageLevel.Nothing == overrideLevel ? this.Level : overrideLevel; | ||
112 | |||
113 | List<string> fileNames = new List<string>(); | ||
114 | string errorFileName = String.IsNullOrEmpty(longAppName) ? "WIX" : longAppName; | ||
115 | for (SourceLineNumber sln = this.SourceLineNumbers; null != sln; sln = sln.Parent) | ||
116 | { | ||
117 | if (String.IsNullOrEmpty(sln.FileName)) | ||
118 | { | ||
119 | continue; | ||
120 | } | ||
121 | else if (sln.LineNumber.HasValue) | ||
122 | { | ||
123 | if (0 == fileNames.Count) | ||
124 | { | ||
125 | errorFileName = String.Format(CultureInfo.CurrentUICulture, WixDataStrings.Format_FirstLineNumber, sln.FileName, sln.LineNumber); | ||
126 | } | ||
127 | |||
128 | fileNames.Add(String.Format(CultureInfo.CurrentUICulture, WixDataStrings.Format_LineNumber, sln.FileName, sln.LineNumber)); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | if (0 == fileNames.Count) | ||
133 | { | ||
134 | errorFileName = sln.FileName; | ||
135 | } | ||
136 | |||
137 | fileNames.Add(sln.FileName); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | string messageType = String.Empty; | ||
142 | if (MessageLevel.Warning == messageLevel) | ||
143 | { | ||
144 | messageType = WixDataStrings.MessageType_Warning; | ||
145 | } | ||
146 | else if (MessageLevel.Error == messageLevel) | ||
147 | { | ||
148 | messageType = WixDataStrings.MessageType_Error; | ||
149 | } | ||
150 | |||
151 | StringBuilder messageBuilder = new StringBuilder(); | ||
152 | string message = String.Format(CultureInfo.InvariantCulture, this.ResourceManager.GetString(this.ResourceName), this.MessageArgs); | ||
153 | if (MessageLevel.Information == messageLevel || MessageLevel.Verbose == messageLevel) | ||
154 | { | ||
155 | messageBuilder.AppendFormat(WixDataStrings.Format_InfoMessage, message); | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | messageBuilder.AppendFormat(WixDataStrings.Format_NonInfoMessage, errorFileName, messageType, String.IsNullOrEmpty(shortAppName) ? "WIX" : shortAppName, this.Id, message); | ||
160 | } | ||
161 | |||
162 | if (1 < fileNames.Count) | ||
163 | { | ||
164 | messageBuilder.AppendFormat(WixDataStrings.INF_SourceTrace, Environment.NewLine); | ||
165 | foreach (string fileName in fileNames) | ||
166 | { | ||
167 | messageBuilder.AppendFormat(WixDataStrings.INF_SourceTraceLocation, fileName, Environment.NewLine); | ||
168 | } | ||
169 | |||
170 | messageBuilder.Append(Environment.NewLine); | ||
171 | } | ||
172 | |||
173 | return messageBuilder.ToString(); | ||
174 | } | ||
175 | } | ||
176 | } | ||