From 155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 19 Dec 2017 12:25:40 -0800 Subject: Integrate simplified message handling --- src/WixToolset.Core/Common.cs | 53 ++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'src/WixToolset.Core/Common.cs') diff --git a/src/WixToolset.Core/Common.cs b/src/WixToolset.Core/Common.cs index 9a0d3aec..ebcbd36f 100644 --- a/src/WixToolset.Core/Common.cs +++ b/src/WixToolset.Core/Common.cs @@ -14,6 +14,7 @@ namespace WixToolset.Core using System.Xml.Linq; using WixToolset.Data; using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; /// /// Common Wix utility methods and types. @@ -111,7 +112,7 @@ namespace WixToolset.Core /// The temporary directory to delete. /// The message handler. /// True if all files were deleted, false otherwise. - internal static bool DeleteTempFiles(string path, IMessageHandler messageHandler) + internal static bool DeleteTempFiles(string path, IMessaging messageHandler) { // try three times and give up with a warning if the temp files aren't gone by then int retryLimit = 3; @@ -133,7 +134,7 @@ namespace WixToolset.Core } else { - messageHandler.OnMessage(WixWarnings.AccessDeniedForDeletion(null, path)); + messageHandler.Write(WarningMessages.AccessDeniedForDeletion(null, path)); return false; } } @@ -146,7 +147,7 @@ namespace WixToolset.Core { if (i == (retryLimit - 1)) // last try failed still, give up { - messageHandler.OnMessage(WixWarnings.DirectoryInUse(null, path)); + messageHandler.Write(WarningMessages.DirectoryInUse(null, path)); return false; } @@ -203,7 +204,7 @@ namespace WixToolset.Core codePage = encoding.CodePage; if (0 > codePage || Int16.MaxValue < codePage) { - throw new WixException(WixErrors.InvalidSummaryInfoCodePage(sourceLineNumbers, codePage)); + throw new WixException(ErrorMessages.InvalidSummaryInfoCodePage(sourceLineNumbers, codePage)); } } @@ -327,7 +328,7 @@ namespace WixToolset.Core case "true": return true; default: - throw new WixException(WixErrors.IllegalAttributeValue(sourceLineNumbers, elementName, attributeName, value, "no", "yes")); + throw new WixException(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, elementName, attributeName, value, "no", "yes")); } } @@ -433,7 +434,7 @@ namespace WixToolset.Core /// The FileAttribute to change on each file. /// The message handler. /// If true, add the attribute to each file. If false, remove it. - private static void RecursiveFileAttributes(string path, FileAttributes fileAttribute, bool markAttribute, IMessageHandler messageHandler) + private static void RecursiveFileAttributes(string path, FileAttributes fileAttribute, bool markAttribute, IMessaging messageHandler) { foreach (string subDirectory in Directory.GetDirectories(path)) { @@ -458,7 +459,7 @@ namespace WixToolset.Core } catch (UnauthorizedAccessException) { - messageHandler.OnMessage(WixWarnings.AccessDeniedForSettingAttributes(null, filePath)); + messageHandler.Write(WarningMessages.AccessDeniedForSettingAttributes(null, filePath)); } } } @@ -624,14 +625,14 @@ namespace WixToolset.Core /// A rule for the contents of the value. If the contents do not follow the rule, an error is thrown. /// A delegate that receives error messages. /// The attribute's value. - internal static string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule) + internal static string GetAttributeValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule) { string value = attribute.Value; if ((emptyRule == EmptyRule.MustHaveNonWhitespaceCharacters && String.IsNullOrEmpty(value.Trim())) || (emptyRule == EmptyRule.CanBeWhitespaceOnly && String.IsNullOrEmpty(value))) { - Messaging.Instance.OnMessage(WixErrors.IllegalEmptyAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); + messaging.Write(ErrorMessages.IllegalEmptyAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); return String.Empty; } @@ -663,15 +664,15 @@ namespace WixToolset.Core /// The attribute containing the value to get. /// A delegate that receives error messages. /// The attribute's identifier value or a special value if an error occurred. - internal static string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) + internal static string GetAttributeIdentifierValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) { - string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); + string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); if (Common.IsIdentifier(value)) { if (72 < value.Length) { - Messaging.Instance.OnMessage(WixWarnings.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return value; @@ -680,11 +681,11 @@ namespace WixToolset.Core { if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal)) { - Messaging.Instance.OnMessage(WixErrors.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + messaging.Write(ErrorMessages.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } else { - Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return String.Empty; @@ -700,11 +701,11 @@ namespace WixToolset.Core /// The maximum legal value. /// A delegate that receives error messages. /// The attribute's integer value or a special value if an error occurred during conversion. - public static int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) + public static int GetAttributeIntegerValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) { Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing."); - string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); + string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); int integer = CompilerConstants.IllegalInteger; if (0 < value.Length) @@ -713,17 +714,17 @@ namespace WixToolset.Core { if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer) { - Messaging.Instance.OnMessage(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, integer)); + messaging.Write(ErrorMessages.IntegralValueSentinelCollision(sourceLineNumbers, integer)); } else if (minimum > integer || maximum < integer) { - Messaging.Instance.OnMessage(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum)); + messaging.Write(ErrorMessages.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum)); integer = CompilerConstants.IllegalInteger; } } else { - Messaging.Instance.OnMessage(WixErrors.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + messaging.Write(ErrorMessages.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } @@ -737,9 +738,9 @@ namespace WixToolset.Core /// The attribute containing the value to get. /// A delegate that receives error messages. /// The attribute's YesNoType value. - internal static YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) + internal static YesNoType GetAttributeYesNoValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) { - string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); + string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); YesNoType yesNo = YesNoType.IllegalValue; if ("yes".Equals(value) || "true".Equals(value)) @@ -752,7 +753,7 @@ namespace WixToolset.Core } else { - Messaging.Instance.OnMessage(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + messaging.Write(ErrorMessages.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return yesNo; @@ -776,13 +777,13 @@ namespace WixToolset.Core /// /// Source line information about the owner element. /// The attribute. - public static void UnexpectedAttribute(SourceLineNumber sourceLineNumbers, XAttribute attribute) + public static void UnexpectedAttribute(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) { // Ignore elements defined by the W3C because we'll assume they are always right. if (!((String.IsNullOrEmpty(attribute.Name.NamespaceName) && attribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || attribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) { - Messaging.Instance.OnMessage(WixErrors.UnexpectedAttribute(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); + messaging.Write(ErrorMessages.UnexpectedAttribute(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); } } @@ -791,13 +792,13 @@ namespace WixToolset.Core /// /// Source line information about the owner element. /// The extension attribute. - internal static void UnsupportedExtensionAttribute(SourceLineNumber sourceLineNumbers, XAttribute extensionAttribute) + internal static void UnsupportedExtensionAttribute(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute extensionAttribute) { // Ignore elements defined by the W3C because we'll assume they are always right. if (!((String.IsNullOrEmpty(extensionAttribute.Name.NamespaceName) && extensionAttribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || extensionAttribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) { - Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, extensionAttribute.Parent.Name.LocalName, extensionAttribute.Name.LocalName)); + messaging.Write(ErrorMessages.UnsupportedExtensionAttribute(sourceLineNumbers, extensionAttribute.Parent.Name.LocalName, extensionAttribute.Name.LocalName)); } } } -- cgit v1.2.3-55-g6feb