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.WindowsInstaller/Validator.cs | 42 +++++++++-------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller/Validator.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/Validator.cs b/src/WixToolset.Core.WindowsInstaller/Validator.cs index eb17d8af..d553cc71 100644 --- a/src/WixToolset.Core.WindowsInstaller/Validator.cs +++ b/src/WixToolset.Core.WindowsInstaller/Validator.cs @@ -22,7 +22,7 @@ namespace WixToolset.Core.WindowsInstaller /// /// Runs internal consistency evaluators (ICEs) from cub files against a database. /// - public sealed class Validator : IMessageHandler + public sealed class Validator { private string actionName; private StringCollection cubeFiles; @@ -30,15 +30,17 @@ namespace WixToolset.Core.WindowsInstaller private Output output; private InstallUIHandler validationUIHandler; private bool validationSessionComplete; + private readonly IMessaging messaging; /// /// Instantiate a new Validator. /// - public Validator() + public Validator(IMessaging messaging) { this.cubeFiles = new StringCollection(); - this.extension = new ValidatorExtension(); + this.extension = new ValidatorExtension(messaging); this.validationUIHandler = new InstallUIHandler(this.ValidationUIHandler); + this.messaging = messaging; } /// @@ -127,7 +129,7 @@ namespace WixToolset.Core.WindowsInstaller { if (!mutex.WaitOne(0, false)) { - this.OnMessage(WixVerboses.ValidationSerialized()); + this.messaging.Write(VerboseMessages.ValidationSerialized()); mutex.WaitOne(); } @@ -176,7 +178,7 @@ namespace WixToolset.Core.WindowsInstaller { if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED { - throw new WixException(WixErrors.CubeFileNotFound(cubeFile)); + throw new WixException(ErrorMessages.CubeFileNotFound(cubeFile)); } throw; @@ -248,7 +250,7 @@ namespace WixToolset.Core.WindowsInstaller } catch (Win32Exception e) { - if (!Messaging.Instance.EncounteredError) + if (!this.messaging.EncounteredError) { throw e; } @@ -270,7 +272,7 @@ namespace WixToolset.Core.WindowsInstaller catch (Win32Exception e) { // avoid displaying errors twice since one may have already occurred in the UI handler - if (!Messaging.Instance.EncounteredError) + if (!this.messaging.EncounteredError) { if (0x6E == e.NativeErrorCode) // ERROR_OPEN_FAILED { @@ -278,23 +280,23 @@ namespace WixToolset.Core.WindowsInstaller // this would be the temporary copy and there would be // no final output since the error occured; during smoke // they should know the path passed into smoke - this.OnMessage(WixErrors.ValidationFailedToOpenDatabase()); + this.messaging.Write(ErrorMessages.ValidationFailedToOpenDatabase()); } else if (0x64D == e.NativeErrorCode) { - this.OnMessage(WixErrors.ValidationFailedDueToLowMsiEngine()); + this.messaging.Write(ErrorMessages.ValidationFailedDueToLowMsiEngine()); } else if (0x654 == e.NativeErrorCode) { - this.OnMessage(WixErrors.ValidationFailedDueToInvalidPackage()); + this.messaging.Write(ErrorMessages.ValidationFailedDueToInvalidPackage()); } else if (0x658 == e.NativeErrorCode) { - this.OnMessage(WixErrors.ValidationFailedDueToMultilanguageMergeModule()); + this.messaging.Write(ErrorMessages.ValidationFailedDueToMultilanguageMergeModule()); } else if (0x659 == e.NativeErrorCode) { - this.OnMessage(WixWarnings.ValidationFailedDueToSystemPolicy()); + this.messaging.Write(WarningMessages.ValidationFailedDueToSystemPolicy()); } else { @@ -305,7 +307,7 @@ namespace WixToolset.Core.WindowsInstaller msgTemp = String.Concat("Action - '", this.actionName, "' ", e.Message); } - this.OnMessage(WixErrors.Win32Exception(e.NativeErrorCode, msgTemp)); + this.messaging.Write(ErrorMessages.Win32Exception(e.NativeErrorCode, msgTemp)); } } } @@ -322,16 +324,6 @@ namespace WixToolset.Core.WindowsInstaller } } - /// - /// Sends a message to the message delegate if there is one. - /// - /// Message event arguments. - public void OnMessage(MessageEventArgs e) - { - Messaging.Instance.OnMessage(e); - this.extension.OnMessage(e); - } - public static Validator CreateFromContext(IBindContext context, string cubeFilename) { Validator validator = null; @@ -339,7 +331,7 @@ namespace WixToolset.Core.WindowsInstaller // Tell the binder about the validator if validation isn't suppressed if (!context.SuppressValidation) { - validator = new Validator(); + validator = new Validator(context.Messaging); validator.IntermediateFolder = Path.Combine(context.IntermediateFolder, "validate"); // set the default cube file @@ -378,7 +370,7 @@ namespace WixToolset.Core.WindowsInstaller } catch (WixException ex) { - this.OnMessage(ex.Error); + this.messaging.Write(ex.Error); } return 1; -- cgit v1.2.3-55-g6feb