@joebigelow / wix-1 / commits / a39985db

Expose FileTransfer as interface

This reduces the code in Extensiblity which is always a good thing.

Rob Mensching committed Jul 26, 2018 at 23:49 UTC a39985db85c67a8f5229767bb9ba34aaa26edd65
7 files changed +87 -116
src/WixToolset.Extensibility/BaseBinderExtension.cs
+15
@@ -3,6 +3,7 @@
3 namespace WixToolset.Extensibility
4 {
5 using WixToolset.Extensibility.Data;
6 + using WixToolset.Extensibility.Services;
7
8 /// <summary>
9 /// Base class for creating a resolver extension.
@@ -14,12 +15,26 @@ namespace WixToolset.Extensibility
15 /// </summary>
16 protected IBindContext Context { get; private set; }
17
18 + /// <summary>
19 + /// Messaging for use by the extension.
20 + /// </summary>
21 + protected IMessaging Messaging { get; private set; }
22 +
23 + /// <summary>
24 + /// BackendHelper for use by the extension.
25 + /// </summary>
26 + protected IBackendHelper BackendHelper { get; private set; }
27 +
28 /// <summary>
29 /// Called at the beginning of bind.
30 /// </summary>
31 public virtual void PreBind(IBindContext context)
32 {
33 this.Context = context;
34 +
35 + this.Messaging = context.ServiceProvider.GetService<IMessaging>();
36 +
37 + this.BackendHelper = context.ServiceProvider.GetService<IBackendHelper>();
38 }
39
40 /// <summary>
src/WixToolset.Extensibility/Data/BindResult.cs
+1 -1
@@ -6,7 +6,7 @@ namespace WixToolset.Extensibility.Data
6
7 public class BindResult
8 {
9 - public IEnumerable<FileTransfer> FileTransfers { get; set; }
9 + public IEnumerable<IFileTransfer> FileTransfers { get; set; }
10
11 public IEnumerable<string> ContentFilePaths { get; set; }
12 }
src/WixToolset.Extensibility/Data/FileTransfer.cs deleted
-114
@@ -1,114 +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.Extensibility.Data
4 -{
5 - using System;
6 - using System.IO;
7 - using WixToolset.Data;
8 -
9 - /// <summary>
10 - /// Structure used for all file transfer information.
11 - /// </summary>
12 - public class FileTransfer
13 - {
14 - /// <summary>Source path to file.</summary>
15 - public string Source { get; set; }
16 -
17 - /// <summary>Destination path for file.</summary>
18 - public string Destination { get; set; }
19 -
20 - /// <summary>Flag if file should be moved (optimal).</summary>
21 - public bool Move { get; set; }
22 -
23 - /// <summary>Optional source line numbers where this file transfer orginated.</summary>
24 - public SourceLineNumber SourceLineNumbers { get; set; }
25 -
26 - /// <summary>Optional type of file this transfer is moving or copying.</summary>
27 - public string Type { get; set; }
28 -
29 - /// <summary>Indicates whether the file transer was a built by this build or copied from other some build.</summary>
30 - public bool Built { get; set; }
31 -
32 - /// <summary>Set during layout of media when the file transfer when the source and target resolve to the same path.</summary>
33 - public bool Redundant { get; set; }
34 -
35 - /// <summary>
36 - /// Prefer the TryCreate() method to create FileTransfer objects.
37 - /// </summary>
38 - /// <param name="source">Source path to file.</param>
39 - /// <param name="destination">Destination path for file.</param>
40 - /// <param name="move">File if file should be moved (optimal).</param>
41 - /// <param name="type">Optional type of file this transfer is transferring.</param>
42 - /// <param name="sourceLineNumbers">Optional source line numbers wher this transfer originated.</param>
43 - public FileTransfer(string source, string destination, bool move, string type = null, SourceLineNumber sourceLineNumbers = null)
44 - {
45 - this.Source = source;
46 - this.Destination = destination;
47 - this.Move = move;
48 -
49 - this.Type = type;
50 - this.SourceLineNumbers = sourceLineNumbers;
51 - }
52 -
53 - /// <summary>
54 - /// Creates a file transfer if the source and destination are different.
55 - /// </summary>
56 - /// <param name="source">Source path to file.</param>
57 - /// <param name="destination">Destination path for file.</param>
58 - /// <param name="move">File if file should be moved (optimal).</param>
59 - /// <param name="type">Optional type of file this transfer is transferring.</param>
60 - /// <param name="sourceLineNumbers">Optional source line numbers where this transfer originated.</param>
61 - /// <returns>true if the source and destination are the different, false if no file transfer is created.</returns>
62 - public static bool TryCreate(string source, string destination, bool move, string type, SourceLineNumber sourceLineNumbers, out FileTransfer transfer)
63 - {
64 - //string sourceFullPath = GetValidatedFullPath(sourceLineNumbers, source);
65 -
66 - //string fileLayoutFullPath = GetValidatedFullPath(sourceLineNumbers, destination);
67 -
68 - ////// if the current source path (where we know that the file already exists) and the resolved
69 - ////// path as dictated by the Directory table are not the same, then propagate the file. The
70 - ////// image that we create may have already been done by some other process other than the linker, so
71 - ////// there is no reason to copy the files to the resolved source if they are already there.
72 - ////if (String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase))
73 - ////{
74 - //// transfer = null;
75 - //// return false;
76 - ////}
77 -
78 - //transfer = new FileTransfer(source, destination, move, type, sourceLineNumbers);
79 - //transfer.Redundant = String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase);
80 - //return true;
81 - throw new NotImplementedException();
82 - }
83 -
84 - //private static string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path)
85 - //{
86 - // string result;
87 -
88 - // try
89 - // {
90 - // result = Path.GetFullPath(path);
91 -
92 - // var filename = Path.GetFileName(result);
93 -
94 - // foreach (var reservedName in Common.ReservedFileNames)
95 - // {
96 - // if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase))
97 - // {
98 - // throw new WixException(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
99 - // }
100 - // }
101 - // }
102 - // catch (ArgumentException)
103 - // {
104 - // throw new WixException(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
105 - // }
106 - // catch (PathTooLongException)
107 - // {
108 - // throw new WixException(ErrorMessages.PathTooLong(sourceLineNumbers, path));
109 - // }
110 -
111 - // return result;
112 - //}
113 - }
114 -}
src/WixToolset.Extensibility/Data/FileTransferType.cs new
+17
@@ -0,0 +1,17 @@
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.Extensibility.Data
4 +{
5 + public enum FileTransferType
6 + {
7 + /// <summary>
8 + /// Transfer of a file built during this build.
9 + /// </summary>
10 + Built,
11 +
12 + /// <summary>
13 + /// Transfer of a file contained in the output.
14 + /// </summary>
15 + Content,
16 + }
17 +}
src/WixToolset.Extensibility/Data/IFileTransfer.cs new
+30
@@ -0,0 +1,30 @@
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.Extensibility.Data
4 +{
5 + using WixToolset.Data;
6 +
7 + /// <summary>
8 + /// Structure used for all file transfer information.
9 + /// </summary>
10 + public interface IFileTransfer
11 + {
12 + /// <summary>Destination path for file.</summary>
13 + string Destination { get; set; }
14 +
15 + /// <summary>Flag if file should be moved (optimal).</summary>
16 + bool Move { get; set; }
17 +
18 + /// <summary>Set during layout of media when the file transfer when the source and target resolve to the same path.</summary>
19 + bool Redundant { get; set; }
20 +
21 + /// <summary>Source path to file.</summary>
22 + string Source { get; set; }
23 +
24 + /// <summary>Optional source line numbers where this file transfer orginated.</summary>
25 + SourceLineNumber SourceLineNumbers { get; set; }
26 +
27 + /// <summary>Type of file this transfer is moving or copying.</summary>
28 + FileTransferType Type { get; set; }
29 + }
30 +}
src/WixToolset.Extensibility/Data/ILayoutContext.cs
+1 -1
@@ -13,7 +13,7 @@ namespace WixToolset.Extensibility.Data
13
14 IEnumerable<string> ContentFilePaths { get; set; }
15
16 - IEnumerable<FileTransfer> FileTransfers { get; set; }
16 + IEnumerable<IFileTransfer> FileTransfers { get; set; }
17
18 string ContentsFile { get; set; }
19
src/WixToolset.Extensibility/Services/IBackendHelper.cs new
+23
@@ -0,0 +1,23 @@
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.Extensibility.Services
4 +{
5 + using WixToolset.Data;
6 + using WixToolset.Extensibility.Data;
7 +
8 + /// <summary>
9 + /// Interface provided to help backend extensions.
10 + /// </summary>
11 + public interface IBackendHelper
12 + {
13 + /// <summary>
14 + /// Creates a file transfer and marks it redundant if the source and destination are identical.
15 + /// </summary>
16 + /// <param name="source">Source for the file transfer.</param>
17 + /// <param name="destination">Destiation for the file transfer.</param>
18 + /// <param name="move">Indicates whether to move or copy the source file.</param>
19 + /// <param name="type">Type of file transfer to create.</param>
20 + /// <param name="sourceLineNumbers">Optional source line numbers that requested the file transfer.</param>
21 + IFileTransfer CreateFileTransfer(string source, string destination, bool move, FileTransferType type, SourceLineNumber sourceLineNumbers = null);
22 + }
23 +}