From 148ad02da05070245c8345d6650e2a70bd4706be Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 12 Apr 2020 11:19:14 +1000 Subject: Merge and move default tuple logic from CreateOutputFromIRCommand to WindowsInstallerBackendHelper. --- .../Bind/BindDatabaseCommand.cs | 5 +- .../Bind/CreateOutputFromIRCommand.cs | 62 ++++------------------ 2 files changed, 15 insertions(+), 52 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller') 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 this.Messaging = context.ServiceProvider.GetService(); this.BackendHelper = context.ServiceProvider.GetService(); + this.WindowsInstallerBackendHelper = context.ServiceProvider.GetService(); this.PathResolver = this.ServiceProvider.GetService(); @@ -60,6 +61,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IBackendHelper BackendHelper { get; } + private IWindowsInstallerBackendHelper WindowsInstallerBackendHelper { get; } + private IPathResolver PathResolver { get; } private int Codepage { get; } @@ -343,7 +346,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Time to create the output object. Try to put as much above here as possible, updating the IR is better. { - var command = new CreateOutputFromIRCommand(this.Messaging, section, tableDefinitions, this.BackendExtensions); + var command = new CreateOutputFromIRCommand(this.Messaging, section, tableDefinitions, this.BackendExtensions, this.WindowsInstallerBackendHelper); command.Execute(); 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 private static readonly char[] ColonCharacter = new[] { ':' }; - public CreateOutputFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, IEnumerable backendExtensions) + public CreateOutputFromIRCommand(IMessaging messaging, IntermediateSection section, TableDefinitionCollection tableDefinitions, IEnumerable backendExtensions, IWindowsInstallerBackendHelper backendHelper) { this.Messaging = messaging; this.Section = section; this.TableDefinitions = tableDefinitions; this.BackendExtensions = backendExtensions; + this.BackendHelper = backendHelper; } private IEnumerable BackendExtensions { get; } + private IWindowsInstallerBackendHelper BackendHelper { get; } + private IMessaging Messaging { get; } private TableDefinitionCollection TableDefinitions { get; } @@ -173,10 +176,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.AddShortcutTuple((ShortcutTuple)tuple); break; - case TupleDefinitionType.SummaryInformation: - this.AddTupleDefaultly(tuple, tableName: "_SummaryInformation"); - break; - case TupleDefinitionType.TextStyle: this.AddTextStyleTuple((TextStyleTuple)tuple); break; @@ -1034,48 +1033,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind { foreach (var extension in this.BackendExtensions) { - if (extension.TryAddTupleToOutput(tuple, this.Output)) + if (extension.TryAddTupleToOutput(this.Section, tuple, this.Output, this.TableDefinitions)) { break; } } } - private void AddTupleDefaultly(IntermediateTuple tuple, string tableName = null) - { - if (!this.TableDefinitions.TryGet(tableName ?? tuple.Definition.Name, out var tableDefinition)) - { - return; - } - - var row = this.CreateRow(tuple, tableDefinition); - var rowOffset = 0; - - if (tableDefinition.TupleIdIsPrimaryKey) - { - row[0] = tuple.Id.Id; - rowOffset = 1; - } - - for (var i = 0; i < tuple.Fields.Length; ++i) - { - if (i < tableDefinition.Columns.Length) - { - var column = tableDefinition.Columns[i + rowOffset]; - - switch (column.Type) - { - case ColumnType.Number: - row[i + rowOffset] = column.Nullable ? tuple.AsNullableNumber(i) : tuple.AsNumber(i); - break; - - default: - row[i + rowOffset] = tuple.AsString(i); - break; - } - } - } - } + private void AddTupleDefaultly(IntermediateTuple tuple) => + this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(this.Section, tuple, this.Output, this.TableDefinitions); private static OutputType SectionTypeToOutputType(SectionType type) { @@ -1097,17 +1063,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind } } - private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) => this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]); - - private Row CreateRow(IntermediateTuple tuple, TableDefinition tableDefinition) - { - var table = this.Output.EnsureTable(tableDefinition); - - var row = table.CreateRow(tuple.SourceLineNumbers); - row.SectionId = this.Section.Id; + private Row CreateRow(IntermediateTuple tuple, string tableDefinitionName) => + this.CreateRow(tuple, this.TableDefinitions[tableDefinitionName]); - return row; - } + private Row CreateRow(IntermediateTuple tuple, TableDefinition tableDefinition) => + this.BackendHelper.CreateRow(this.Section, tuple, this.Output, tableDefinition); private static string GetMsiFilenameValue(string shortName, string longName) { -- cgit v1.2.3-55-g6feb