diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-12 11:19:14 +1000 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-12 12:46:21 +1000 |
commit | 148ad02da05070245c8345d6650e2a70bd4706be (patch) | |
tree | 819c60d1c2b19848fb12bae9d9f7e009db387a43 /src | |
parent | 6d8b6f79b44b6a41a630aa3aad5a3c7f16701798 (diff) | |
download | wix-148ad02da05070245c8345d6650e2a70bd4706be.tar.gz wix-148ad02da05070245c8345d6650e2a70bd4706be.tar.bz2 wix-148ad02da05070245c8345d6650e2a70bd4706be.zip |
Merge and move default tuple logic from CreateOutputFromIRCommand to WindowsInstallerBackendHelper.
Diffstat (limited to 'src')
4 files changed, 31 insertions, 62 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 5d1e89ac..489fdacb 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs | |||
@@ -33,6 +33,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
33 | this.Messaging = context.ServiceProvider.GetService<IMessaging>(); | 33 | this.Messaging = context.ServiceProvider.GetService<IMessaging>(); |
34 | 34 | ||
35 | this.BackendHelper = context.ServiceProvider.GetService<IBackendHelper>(); | 35 | this.BackendHelper = context.ServiceProvider.GetService<IBackendHelper>(); |
36 | this.WindowsInstallerBackendHelper = context.ServiceProvider.GetService<IWindowsInstallerBackendHelper>(); | ||
36 | 37 | ||
37 | this.PathResolver = this.ServiceProvider.GetService<IPathResolver>(); | 38 | this.PathResolver = this.ServiceProvider.GetService<IPathResolver>(); |
38 | 39 | ||
@@ -60,6 +61,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
60 | 61 | ||
61 | private IBackendHelper BackendHelper { get; } | 62 | private IBackendHelper BackendHelper { get; } |
62 | 63 | ||
64 | private IWindowsInstallerBackendHelper WindowsInstallerBackendHelper { get; } | ||
65 | |||
63 | private IPathResolver PathResolver { get; } | 66 | private IPathResolver PathResolver { get; } |
64 | 67 | ||
65 | private int Codepage { get; } | 68 | private int Codepage { get; } |
@@ -343,7 +346,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
343 | 346 | ||
344 | // Time to create the output object. Try to put as much above here as possible, updating the IR is better. | 347 | // Time to create the output object. Try to put as much above here as possible, updating the IR is better. |
345 | { | 348 | { |
346 | var command = new CreateOutputFromIRCommand(this.Messaging, section, tableDefinitions, this.BackendExtensions); | 349 | var command = new CreateOutputFromIRCommand(this.Messaging, section, tableDefinitions, this.BackendExtensions, this.WindowsInstallerBackendHelper); |
347 | command.Execute(); | 350 | command.Execute(); |
348 | 351 | ||
349 | output = command.Output; | 352 | output = command.Output; |
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs index 15b53a55..c3bedfc7 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs | |||
@@ -20,16 +20,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
20 | 20 | ||
21 | private static readonly char[] ColonCharacter = new[] { ':' }; | 21 | private static readonly char[] ColonCharacter = new[] { ':' }; |
22 | 22 | ||
23 | public CreateOutputFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, IEnumerable<IWindowsInstallerBackendBinderExtension> backendExtensions) | 23 | public CreateOutputFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, IEnumerable<IWindowsInstallerBackendBinderExtension> backendExtensions, IWindowsInstallerBackendHelper backendHelper) |
24 | { | 24 | { |
25 | this.Messaging = messaging; | 25 | this.Messaging = messaging; |
26 | this.Section = section; | 26 | this.Section = section; |
27 | this.TableDefinitions = tableDefinitions; | 27 | this.TableDefinitions = tableDefinitions; |
28 | this.BackendExtensions = backendExtensions; | 28 | this.BackendExtensions = backendExtensions; |
29 | this.BackendHelper = backendHelper; | ||
29 | } | 30 | } |
30 | 31 | ||
31 | private IEnumerable<IWindowsInstallerBackendBinderExtension> BackendExtensions { get; } | 32 | private IEnumerable<IWindowsInstallerBackendBinderExtension> BackendExtensions { get; } |
32 | 33 | ||
34 | private IWindowsInstallerBackendHelper BackendHelper { get; } | ||
35 | |||
33 | private IMessaging Messaging { get; } | 36 | private IMessaging Messaging { get; } |
34 | 37 | ||
35 | private TableDefinitionCollection TableDefinitions { get; } | 38 | private TableDefinitionCollection TableDefinitions { get; } |
@@ -173,10 +176,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
173 | this.AddShortcutTuple((ShortcutTuple)tuple); | 176 | this.AddShortcutTuple((ShortcutTuple)tuple); |
174 | break; | 177 | break; |
175 | 178 | ||
176 | case TupleDefinitionType.SummaryInformation: | ||
177 | this.AddTupleDefaultly(tuple, tableName: "_SummaryInformation"); | ||
178 | break; | ||
179 | |||
180 | case TupleDefinitionType.TextStyle: | 179 | case TupleDefinitionType.TextStyle: |
181 | this.AddTextStyleTuple((TextStyleTuple)tuple); | 180 | this.AddTextStyleTuple((TextStyleTuple)tuple); |
182 | break; | 181 | break; |
@@ -1034,48 +1033,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
1034 | { | 1033 | { |
1035 | foreach (var extension in this.BackendExtensions) | 1034 | foreach (var extension in this.BackendExtensions) |
1036 | { | 1035 | { |
1037 | if (extension.TryAddTupleToOutput(tuple, this.Output)) | 1036 | if (extension.TryAddTupleToOutput(this.Section, tuple, this.Output, this.TableDefinitions)) |
1038 | { | 1037 | { |
1039 | break; | 1038 | break; |
1040 | } | 1039 | } |
1041 | } | 1040 | } |
1042 | } | 1041 | } |
1043 | 1042 | ||
1044 | private void AddTupleDefaultly(IntermediateTuple tuple, string tableName = null) | 1043 | private void AddTupleDefaultly(IntermediateTuple tuple) => |
1045 | { | 1044 | this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(this.Section, tuple, this.Output, this.TableDefinitions); |
1046 | if (!this.TableDefinitions.TryGet(tableName ?? tuple.Definition.Name, out var tableDefinition)) | ||
1047 | { | ||
1048 | return; | ||
1049 | } | ||
1050 | |||
1051 | var row = this.CreateRow(tuple, tableDefinition); | ||
1052 | var rowOffset = 0; | ||
1053 | |||
1054 | if (tableDefinition.TupleIdIsPrimaryKey) | ||
1055 | { | ||
1056 | row[0] = tuple.Id.Id; | ||
1057 | rowOffset = 1; | ||
1058 | } | ||
1059 | |||
1060 | for (var i = 0; i < tuple.Fields.Length; ++i) | ||
1061 | { | ||
1062 | if (i < tableDefinition.Columns.Length) | ||
1063 | { | ||
1064 | var column = tableDefinition.Columns[i + rowOffset]; | ||
1065 | |||
1066 | switch (column.Type) | ||
1067 | { | ||
1068 | case ColumnType.Number: | ||
1069 | row[i + rowOffset] = column.Nullable ? tuple.AsNullableNumber(i) : tuple.AsNumber(i); | ||
1070 | break; | ||
1071 | |||
1072 | default: | ||
1073 | row[i + rowOffset] = tuple.AsString(i); | ||
1074 | break; | ||
1075 | } | ||
1076 | } | ||
1077 | } | ||
1078 | } | ||
1079 | 1045 | ||
1080 | private static OutputType SectionTypeToOutputType(SectionType type) | 1046 | private static OutputType SectionTypeToOutputType(SectionType type) |
1081 | { | 1047 | { |
@@ -1097,17 +1063,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
1097 | } | 1063 | } |
1098 | } | 1064 | } |
1099 | 1065 | ||
1100 | private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) => this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]); | 1066 | private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) => |
1101 | 1067 | this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]); | |
1102 | private Row CreateRow(IntermediateTuple tuple, TableDefinition tableDefinition) | ||
1103 | { | ||
1104 | var table = this.Output.EnsureTable(tableDefinition); | ||
1105 | |||
1106 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
1107 | row.SectionId = this.Section.Id; | ||
1108 | 1068 | ||
1109 | return row; | 1069 | private Row CreateRow(IntermediateTuple tuple, TableDefinition tableDefinition) => |
1110 | } | 1070 | this.BackendHelper.CreateRow(this.Section, tuple, this.Output, tableDefinition); |
1111 | 1071 | ||
1112 | private static string GetMsiFilenameValue(string shortName, string longName) | 1072 | private static string GetMsiFilenameValue(string shortName, string longName) |
1113 | { | 1073 | { |
diff --git a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs index 80179d1c..753b8b34 100644 --- a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | namespace WixToolset.Core.ExtensibilityServices | 3 | namespace WixToolset.Core.ExtensibilityServices |
4 | { | 4 | { |
5 | using System.Collections.Generic; | ||
6 | using System.Linq; | 5 | using System.Linq; |
7 | using WixToolset.Data; | 6 | using WixToolset.Data; |
8 | using WixToolset.Data.WindowsInstaller; | 7 | using WixToolset.Data.WindowsInstaller; |
@@ -10,17 +9,25 @@ namespace WixToolset.Core.ExtensibilityServices | |||
10 | 9 | ||
11 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper | 10 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper |
12 | { | 11 | { |
13 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, WindowsInstallerData output, IEnumerable<TableDefinition> tableDefinitions) | 12 | public Row CreateRow(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinition tableDefinition) |
14 | { | 13 | { |
15 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.TupleDefinitionName == tuple.Definition.Name); | 14 | var table = output.EnsureTable(tableDefinition); |
15 | |||
16 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
17 | row.SectionId = section.Id; | ||
18 | |||
19 | return row; | ||
20 | } | ||
16 | 21 | ||
22 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) | ||
23 | { | ||
24 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.TupleDefinitionName == tuple.Definition.Name); | ||
17 | if (tableDefinition == null) | 25 | if (tableDefinition == null) |
18 | { | 26 | { |
19 | return false; | 27 | return false; |
20 | } | 28 | } |
21 | 29 | ||
22 | var table = output.EnsureTable(tableDefinition); | 30 | var row = this.CreateRow(section, tuple, output, tableDefinition); |
23 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
24 | var rowOffset = 0; | 31 | var rowOffset = 0; |
25 | 32 | ||
26 | if (tableDefinition.TupleIdIsPrimaryKey) | 33 | if (tableDefinition.TupleIdIsPrimaryKey) |
diff --git a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs index af9c8489..4ee682d3 100644 --- a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs +++ b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs | |||
@@ -11,15 +11,14 @@ namespace Example.Extension | |||
11 | { | 11 | { |
12 | public override IEnumerable<TableDefinition> TableDefinitions => ExampleTableDefinitions.All; | 12 | public override IEnumerable<TableDefinition> TableDefinitions => ExampleTableDefinitions.All; |
13 | 13 | ||
14 | public override bool TryAddTupleToOutput(IntermediateTuple tuple, WindowsInstallerData output) | 14 | public override bool TryAddTupleToOutput(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) |
15 | { | 15 | { |
16 | #if ALTERNATIVE_TO_USING_HELPER | 16 | #if ALTERNATIVE_TO_USING_HELPER |
17 | switch (tuple.Definition.Name) | 17 | switch (tuple.Definition.Name) |
18 | { | 18 | { |
19 | case TupleDefinitions.ExampleName: | 19 | case ExampleTupleDefinitions.ExampleName: |
20 | { | 20 | { |
21 | var table = output.EnsureTable(ExampleTableDefinitions.ExampleTable); | 21 | var row = this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable); |
22 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
23 | row[0] = tuple[0].AsString(); | 22 | row[0] = tuple[0].AsString(); |
24 | row[1] = tuple[1].AsString(); | 23 | row[1] = tuple[1].AsString(); |
25 | } | 24 | } |
@@ -28,7 +27,7 @@ namespace Example.Extension | |||
28 | 27 | ||
29 | return false; | 28 | return false; |
30 | #else | 29 | #else |
31 | return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, ExampleTableDefinitions.All); | 30 | return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(section, tuple, output, tableDefinitions); |
32 | #endif | 31 | #endif |
33 | } | 32 | } |
34 | } | 33 | } |