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/Bind/FileResolver.cs | 2 +- .../Bind/ResolveDelayedFieldsCommand.cs | 10 ++++++--- src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | 9 +++++--- src/WixToolset.Core/Bind/TransferFilesCommand.cs | 26 +++++++++++++--------- 4 files changed, 29 insertions(+), 18 deletions(-) (limited to 'src/WixToolset.Core/Bind') diff --git a/src/WixToolset.Core/Bind/FileResolver.cs b/src/WixToolset.Core/Bind/FileResolver.cs index 8d624e6f..2142d261 100644 --- a/src/WixToolset.Core/Bind/FileResolver.cs +++ b/src/WixToolset.Core/Bind/FileResolver.cs @@ -221,7 +221,7 @@ namespace WixToolset.Core.Bind } catch (ArgumentException) { - throw new WixException(WixErrors.IllegalCharactersInPath(path)); + throw new WixException(ErrorMessages.IllegalCharactersInPath(path)); } } diff --git a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs index 4585b71a..3ded9a87 100644 --- a/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveDelayedFieldsCommand.cs @@ -7,6 +7,7 @@ namespace WixToolset.Core.Bind using System.Globalization; using WixToolset.Data; using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; /// /// Resolves the fields which had variables that needed to be resolved after the file information @@ -19,12 +20,15 @@ namespace WixToolset.Core.Bind /// /// The fields which had resolution delayed. /// The file information to use when resolving variables. - public ResolveDelayedFieldsCommand(IEnumerable delayedFields, Dictionary variableCache) + public ResolveDelayedFieldsCommand(IMessaging messaging, IEnumerable delayedFields, Dictionary variableCache) { + this.Messaging = messaging; this.DelayedFields = delayedFields; this.VariableCache = variableCache; } + private IMessaging Messaging { get; } + private IEnumerable DelayedFields { get;} private IDictionary VariableCache { get; } @@ -58,7 +62,7 @@ namespace WixToolset.Core.Bind } catch (WixException we) { - Messaging.Instance.OnMessage(we.Error); + this.Messaging.Write(we.Error); continue; } } @@ -103,7 +107,7 @@ namespace WixToolset.Core.Bind } catch (WixException we) { - Messaging.Instance.OnMessage(we.Error); + this.Messaging.Write(we.Error); } } } diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs index 9253f352..e8c90956 100644 --- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs @@ -7,12 +7,15 @@ namespace WixToolset.Core.Bind using WixToolset.Data; using WixToolset.Data.Bind; using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; /// /// Resolve source fields in the tables included in the output /// internal class ResolveFieldsCommand { + public IMessaging Messaging { private get; set; } + public bool BuildingPatch { private get; set; } public IBindVariableResolver BindVariableResolver { private get; set; } @@ -75,7 +78,7 @@ namespace WixToolset.Core.Bind } // Move to next row if we've hit an error resolving variables. - if (Messaging.Instance.EncounteredError) // TODO: make this error handling more specific to just the failure to resolve variables in this field. + if (this.Messaging.EncounteredError) // TODO: make this error handling more specific to just the failure to resolve variables in this field. { continue; } @@ -151,7 +154,7 @@ namespace WixToolset.Core.Bind catch (WixFileNotFoundException) { // display the error with source line information - Messaging.Instance.OnMessage(WixErrors.FileNotFound(row.SourceLineNumbers, objectField.Path)); + this.Messaging.Write(ErrorMessages.FileNotFound(row.SourceLineNumbers, objectField.Path)); } } @@ -208,7 +211,7 @@ namespace WixToolset.Core.Bind catch (WixFileNotFoundException) { // display the error with source line information - Messaging.Instance.OnMessage(WixErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.PreviousData)); + Messaging.Instance.Write(WixErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.PreviousData)); } } } diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs index f116569c..68d8b129 100644 --- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs +++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs @@ -9,18 +9,22 @@ namespace WixToolset.Core.Bind using WixToolset.Data; using WixToolset.Data.Bind; using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; internal class TransferFilesCommand { - public TransferFilesCommand(IEnumerable bindPaths, IEnumerable extensions, IEnumerable fileTransfers, bool suppressAclReset) + public TransferFilesCommand(IMessaging messaging, IEnumerable bindPaths, IEnumerable extensions, IEnumerable fileTransfers, bool suppressAclReset) { this.FileResolver = new FileResolver(bindPaths, extensions); + this.Messaging = messaging; this.FileTransfers = fileTransfers; this.SuppressAclReset = suppressAclReset; } private FileResolver FileResolver { get; } + private IMessaging Messaging { get; } + private IEnumerable FileTransfers { get; } private bool SuppressAclReset { get; } @@ -47,12 +51,12 @@ namespace WixToolset.Core.Bind { if (fileTransfer.Move) { - Messaging.Instance.OnMessage(WixVerboses.MoveFile(fileSource, fileTransfer.Destination)); + this.Messaging.Write(VerboseMessages.MoveFile(fileSource, fileTransfer.Destination)); this.TransferFile(true, fileSource, fileTransfer.Destination); } else { - Messaging.Instance.OnMessage(WixVerboses.CopyFile(fileSource, fileTransfer.Destination)); + this.Messaging.Write(VerboseMessages.CopyFile(fileSource, fileTransfer.Destination)); this.TransferFile(false, fileSource, fileTransfer.Destination); } @@ -61,7 +65,7 @@ namespace WixToolset.Core.Bind } catch (FileNotFoundException e) { - throw new WixFileNotFoundException(e.FileName); + throw new WixFileNotFoundException(fileTransfer.SourceLineNumbers, e.FileName); } catch (DirectoryNotFoundException) { @@ -72,7 +76,7 @@ namespace WixToolset.Core.Bind } string directory = Path.GetDirectoryName(fileTransfer.Destination); - Messaging.Instance.OnMessage(WixVerboses.CreateDirectory(directory)); + this.Messaging.Write(VerboseMessages.CreateDirectory(directory)); Directory.CreateDirectory(directory); retry = true; } @@ -86,7 +90,7 @@ namespace WixToolset.Core.Bind if (File.Exists(fileTransfer.Destination)) { - Messaging.Instance.OnMessage(WixVerboses.RemoveDestinationFile(fileTransfer.Destination)); + this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); // try to ensure the file is not read-only FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); @@ -96,7 +100,7 @@ namespace WixToolset.Core.Bind } catch (ArgumentException) // thrown for unauthorized access errors { - throw new WixException(WixErrors.UnauthorizedAccess(fileTransfer.Destination)); + throw new WixException(ErrorMessages.UnauthorizedAccess(fileTransfer.Destination)); } // try to delete the file @@ -106,7 +110,7 @@ namespace WixToolset.Core.Bind } catch (IOException) { - throw new WixException(WixErrors.FileInUse(null, fileTransfer.Destination)); + throw new WixException(ErrorMessages.FileInUse(null, fileTransfer.Destination)); } retry = true; @@ -126,7 +130,7 @@ namespace WixToolset.Core.Bind if (File.Exists(fileTransfer.Destination)) { - Messaging.Instance.OnMessage(WixVerboses.RemoveDestinationFile(fileTransfer.Destination)); + this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); // ensure the file is not read-only, then delete it FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); @@ -137,7 +141,7 @@ namespace WixToolset.Core.Bind } catch (IOException) { - throw new WixException(WixErrors.FileInUse(null, fileTransfer.Destination)); + throw new WixException(ErrorMessages.FileInUse(null, fileTransfer.Destination)); } retry = true; @@ -168,7 +172,7 @@ namespace WixToolset.Core.Bind } catch { - Messaging.Instance.OnMessage(WixWarnings.UnableToResetAcls()); + this.Messaging.Write(WarningMessages.UnableToResetAcls()); } } } -- cgit v1.2.3-55-g6feb