Merge and move default tuple logic from CreateOutputFromIRCommand to WindowsInstallerBackendHelper.
Sean Hall committed
Apr 12, 2020 at 11:19 UTC
148ad02da05070245c8345d6650e2a70bd4706be
4 files changed
+31
-62
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+4
-1
@@ -33,6 +33,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
33
this.Messaging = context.ServiceProvider.GetService<IMessaging>();
34
35
this.BackendHelper = context.ServiceProvider.GetService<IBackendHelper>();
36
+ this.WindowsInstallerBackendHelper = context.ServiceProvider.GetService<IWindowsInstallerBackendHelper>();
37
38
this.PathResolver = this.ServiceProvider.GetService<IPathResolver>();
39
@@ -60,6 +61,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
61
62
private IBackendHelper BackendHelper { get; }
63
64
+ private IWindowsInstallerBackendHelper WindowsInstallerBackendHelper { get; }
65
+
66
private IPathResolver PathResolver { get; }
67
68
private int Codepage { get; }
@@ -343,7 +346,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
346
347
// Time to create the output object. Try to put as much above here as possible, updating the IR is better.
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);
350
command.Execute();
351
352
output = command.Output;
src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs
+11
-51
@@ -20,16 +20,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind
20
21
private static readonly char[] ColonCharacter = new[] { ':' };
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
{
25
this.Messaging = messaging;
26
this.Section = section;
27
this.TableDefinitions = tableDefinitions;
28
this.BackendExtensions = backendExtensions;
29
+ this.BackendHelper = backendHelper;
30
}
31
32
private IEnumerable<IWindowsInstallerBackendBinderExtension> BackendExtensions { get; }
33
34
+ private IWindowsInstallerBackendHelper BackendHelper { get; }
35
+
36
private IMessaging Messaging { get; }
37
38
private TableDefinitionCollection TableDefinitions { get; }
@@ -173,10 +176,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
176
this.AddShortcutTuple((ShortcutTuple)tuple);
177
break;
178
176
- case TupleDefinitionType.SummaryInformation:
177
- this.AddTupleDefaultly(tuple, tableName: "_SummaryInformation");
178
- break;
179
-
179
case TupleDefinitionType.TextStyle:
180
this.AddTextStyleTuple((TextStyleTuple)tuple);
181
break;
@@ -1034,48 +1033,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1033
{
1034
foreach (var extension in this.BackendExtensions)
1035
{
1037
- if (extension.TryAddTupleToOutput(tuple, this.Output))
1036
+ if (extension.TryAddTupleToOutput(this.Section, tuple, this.Output, this.TableDefinitions))
1037
{
1038
break;
1039
}
1040
}
1041
}
1042
1044
- private void AddTupleDefaultly(IntermediateTuple tuple, string tableName = null)
1045
- {
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
- }
1043
+ private void AddTupleDefaultly(IntermediateTuple tuple) =>
1044
+ this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(this.Section, tuple, this.Output, this.TableDefinitions);
1045
1046
private static OutputType SectionTypeToOutputType(SectionType type)
1047
{
@@ -1097,17 +1063,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1063
}
1064
}
1065
1100
- private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) => this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]);
1101
-
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;
1066
+ private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) =>
1067
+ this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]);
1068
1109
- return row;
1110
- }
1069
+ private Row CreateRow(IntermediateTuple tuple, TableDefinition tableDefinition) =>
1070
+ this.BackendHelper.CreateRow(this.Section, tuple, this.Output, tableDefinition);
1071
1072
private static string GetMsiFilenameValue(string shortName, string longName)
1073
{
src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs
+12
-5
@@ -2,7 +2,6 @@
2
3
namespace WixToolset.Core.ExtensibilityServices
4
{
5
- using System.Collections.Generic;
5
using System.Linq;
6
using WixToolset.Data;
7
using WixToolset.Data.WindowsInstaller;
@@ -10,17 +9,25 @@ namespace WixToolset.Core.ExtensibilityServices
9
10
internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper
11
{
13
- public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, WindowsInstallerData output, IEnumerable<TableDefinition> tableDefinitions)
12
+ public Row CreateRow(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinition tableDefinition)
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
+ }
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);
25
if (tableDefinition == null)
26
{
27
return false;
28
}
29
22
- var table = output.EnsureTable(tableDefinition);
23
- var row = table.CreateRow(tuple.SourceLineNumbers);
30
+ var row = this.CreateRow(section, tuple, output, tableDefinition);
31
var rowOffset = 0;
32
33
if (tableDefinition.TupleIdIsPrimaryKey)
src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs
+4
-5
@@ -11,15 +11,14 @@ namespace Example.Extension
11
{
12
public override IEnumerable<TableDefinition> TableDefinitions => ExampleTableDefinitions.All;
13
14
- public override bool TryAddTupleToOutput(IntermediateTuple tuple, WindowsInstallerData output)
14
+ public override bool TryAddTupleToOutput(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions)
15
{
16
#if ALTERNATIVE_TO_USING_HELPER
17
switch (tuple.Definition.Name)
18
{
19
- case TupleDefinitions.ExampleName:
19
+ case ExampleTupleDefinitions.ExampleName:
20
{
21
- var table = output.EnsureTable(ExampleTableDefinitions.ExampleTable);
22
- var row = table.CreateRow(tuple.SourceLineNumbers);
21
+ var row = this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable);
22
row[0] = tuple[0].AsString();
23
row[1] = tuple[1].AsString();
24
}
@@ -28,7 +27,7 @@ namespace Example.Extension
27
28
return false;
29
#else
31
- return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, ExampleTableDefinitions.All);
30
+ return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(section, tuple, output, tableDefinitions);
31
#endif
32
}
33
}