From a39985db85c67a8f5229767bb9ba34aaa26edd65 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 26 Jul 2018 23:49:18 -0700 Subject: Expose FileTransfer as interface This reduces the code in Extensiblity which is always a good thing. --- .../BaseBinderExtension.cs | 15 +++ src/WixToolset.Extensibility/Data/BindResult.cs | 2 +- src/WixToolset.Extensibility/Data/FileTransfer.cs | 114 --------------------- .../Data/FileTransferType.cs | 17 +++ src/WixToolset.Extensibility/Data/IFileTransfer.cs | 30 ++++++ .../Data/ILayoutContext.cs | 2 +- .../Services/IBackendHelper.cs | 23 +++++ 7 files changed, 87 insertions(+), 116 deletions(-) delete mode 100644 src/WixToolset.Extensibility/Data/FileTransfer.cs create mode 100644 src/WixToolset.Extensibility/Data/FileTransferType.cs create mode 100644 src/WixToolset.Extensibility/Data/IFileTransfer.cs create mode 100644 src/WixToolset.Extensibility/Services/IBackendHelper.cs (limited to 'src') diff --git a/src/WixToolset.Extensibility/BaseBinderExtension.cs b/src/WixToolset.Extensibility/BaseBinderExtension.cs index 51d63694..d533b0cb 100644 --- a/src/WixToolset.Extensibility/BaseBinderExtension.cs +++ b/src/WixToolset.Extensibility/BaseBinderExtension.cs @@ -3,6 +3,7 @@ namespace WixToolset.Extensibility { using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; /// /// Base class for creating a resolver extension. @@ -14,12 +15,26 @@ namespace WixToolset.Extensibility /// protected IBindContext Context { get; private set; } + /// + /// Messaging for use by the extension. + /// + protected IMessaging Messaging { get; private set; } + + /// + /// BackendHelper for use by the extension. + /// + protected IBackendHelper BackendHelper { get; private set; } + /// /// Called at the beginning of bind. /// public virtual void PreBind(IBindContext context) { this.Context = context; + + this.Messaging = context.ServiceProvider.GetService(); + + this.BackendHelper = context.ServiceProvider.GetService(); } /// diff --git a/src/WixToolset.Extensibility/Data/BindResult.cs b/src/WixToolset.Extensibility/Data/BindResult.cs index ec97154f..0ccaa08b 100644 --- a/src/WixToolset.Extensibility/Data/BindResult.cs +++ b/src/WixToolset.Extensibility/Data/BindResult.cs @@ -6,7 +6,7 @@ namespace WixToolset.Extensibility.Data public class BindResult { - public IEnumerable FileTransfers { get; set; } + public IEnumerable FileTransfers { get; set; } public IEnumerable ContentFilePaths { get; set; } } diff --git a/src/WixToolset.Extensibility/Data/FileTransfer.cs b/src/WixToolset.Extensibility/Data/FileTransfer.cs deleted file mode 100644 index 0356ac4c..00000000 --- a/src/WixToolset.Extensibility/Data/FileTransfer.cs +++ /dev/null @@ -1,114 +0,0 @@ -// 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. - -namespace WixToolset.Extensibility.Data -{ - using System; - using System.IO; - using WixToolset.Data; - - /// - /// Structure used for all file transfer information. - /// - public class FileTransfer - { - /// Source path to file. - public string Source { get; set; } - - /// Destination path for file. - public string Destination { get; set; } - - /// Flag if file should be moved (optimal). - public bool Move { get; set; } - - /// Optional source line numbers where this file transfer orginated. - public SourceLineNumber SourceLineNumbers { get; set; } - - /// Optional type of file this transfer is moving or copying. - public string Type { get; set; } - - /// Indicates whether the file transer was a built by this build or copied from other some build. - public bool Built { get; set; } - - /// Set during layout of media when the file transfer when the source and target resolve to the same path. - public bool Redundant { get; set; } - - /// - /// Prefer the TryCreate() method to create FileTransfer objects. - /// - /// Source path to file. - /// Destination path for file. - /// File if file should be moved (optimal). - /// Optional type of file this transfer is transferring. - /// Optional source line numbers wher this transfer originated. - public FileTransfer(string source, string destination, bool move, string type = null, SourceLineNumber sourceLineNumbers = null) - { - this.Source = source; - this.Destination = destination; - this.Move = move; - - this.Type = type; - this.SourceLineNumbers = sourceLineNumbers; - } - - /// - /// Creates a file transfer if the source and destination are different. - /// - /// Source path to file. - /// Destination path for file. - /// File if file should be moved (optimal). - /// Optional type of file this transfer is transferring. - /// Optional source line numbers where this transfer originated. - /// true if the source and destination are the different, false if no file transfer is created. - public static bool TryCreate(string source, string destination, bool move, string type, SourceLineNumber sourceLineNumbers, out FileTransfer transfer) - { - //string sourceFullPath = GetValidatedFullPath(sourceLineNumbers, source); - - //string fileLayoutFullPath = GetValidatedFullPath(sourceLineNumbers, destination); - - ////// if the current source path (where we know that the file already exists) and the resolved - ////// path as dictated by the Directory table are not the same, then propagate the file. The - ////// image that we create may have already been done by some other process other than the linker, so - ////// there is no reason to copy the files to the resolved source if they are already there. - ////if (String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase)) - ////{ - //// transfer = null; - //// return false; - ////} - - //transfer = new FileTransfer(source, destination, move, type, sourceLineNumbers); - //transfer.Redundant = String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase); - //return true; - throw new NotImplementedException(); - } - - //private static string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path) - //{ - // string result; - - // try - // { - // result = Path.GetFullPath(path); - - // var filename = Path.GetFileName(result); - - // foreach (var reservedName in Common.ReservedFileNames) - // { - // if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase)) - // { - // throw new WixException(ErrorMessages.InvalidFileName(sourceLineNumbers, path)); - // } - // } - // } - // catch (ArgumentException) - // { - // throw new WixException(ErrorMessages.InvalidFileName(sourceLineNumbers, path)); - // } - // catch (PathTooLongException) - // { - // throw new WixException(ErrorMessages.PathTooLong(sourceLineNumbers, path)); - // } - - // return result; - //} - } -} diff --git a/src/WixToolset.Extensibility/Data/FileTransferType.cs b/src/WixToolset.Extensibility/Data/FileTransferType.cs new file mode 100644 index 00000000..b00a00c4 --- /dev/null +++ b/src/WixToolset.Extensibility/Data/FileTransferType.cs @@ -0,0 +1,17 @@ +// 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. + +namespace WixToolset.Extensibility.Data +{ + public enum FileTransferType + { + /// + /// Transfer of a file built during this build. + /// + Built, + + /// + /// Transfer of a file contained in the output. + /// + Content, + } +} diff --git a/src/WixToolset.Extensibility/Data/IFileTransfer.cs b/src/WixToolset.Extensibility/Data/IFileTransfer.cs new file mode 100644 index 00000000..ca936219 --- /dev/null +++ b/src/WixToolset.Extensibility/Data/IFileTransfer.cs @@ -0,0 +1,30 @@ +// 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. + +namespace WixToolset.Extensibility.Data +{ + using WixToolset.Data; + + /// + /// Structure used for all file transfer information. + /// + public interface IFileTransfer + { + /// Destination path for file. + string Destination { get; set; } + + /// Flag if file should be moved (optimal). + bool Move { get; set; } + + /// Set during layout of media when the file transfer when the source and target resolve to the same path. + bool Redundant { get; set; } + + /// Source path to file. + string Source { get; set; } + + /// Optional source line numbers where this file transfer orginated. + SourceLineNumber SourceLineNumbers { get; set; } + + /// Type of file this transfer is moving or copying. + FileTransferType Type { get; set; } + } +} diff --git a/src/WixToolset.Extensibility/Data/ILayoutContext.cs b/src/WixToolset.Extensibility/Data/ILayoutContext.cs index c3555268..7011fcf6 100644 --- a/src/WixToolset.Extensibility/Data/ILayoutContext.cs +++ b/src/WixToolset.Extensibility/Data/ILayoutContext.cs @@ -13,7 +13,7 @@ namespace WixToolset.Extensibility.Data IEnumerable ContentFilePaths { get; set; } - IEnumerable FileTransfers { get; set; } + IEnumerable FileTransfers { get; set; } string ContentsFile { get; set; } diff --git a/src/WixToolset.Extensibility/Services/IBackendHelper.cs b/src/WixToolset.Extensibility/Services/IBackendHelper.cs new file mode 100644 index 00000000..83f57e35 --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IBackendHelper.cs @@ -0,0 +1,23 @@ +// 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. + +namespace WixToolset.Extensibility.Services +{ + using WixToolset.Data; + using WixToolset.Extensibility.Data; + + /// + /// Interface provided to help backend extensions. + /// + public interface IBackendHelper + { + /// + /// Creates a file transfer and marks it redundant if the source and destination are identical. + /// + /// Source for the file transfer. + /// Destiation for the file transfer. + /// Indicates whether to move or copy the source file. + /// Type of file transfer to create. + /// Optional source line numbers that requested the file transfer. + IFileTransfer CreateFileTransfer(string source, string destination, bool move, FileTransferType type, SourceLineNumber sourceLineNumbers = null); + } +} -- cgit v1.2.3-55-g6feb