From 0185c2ea6e638dc7e1c5224739717ba2152bb510 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 23 Jun 2020 16:45:26 -0700 Subject: Move Windows Installer specific backend services to WindowsInstaller --- .../WindowsInstallerBackendHelper.cs | 61 ++++++++++++++++++++++ .../WixToolsetCoreServiceProviderExtensions.cs | 17 ++++++ .../WindowsInstallerBackendHelper.cs | 61 ---------------------- src/WixToolset.Core/WixToolsetServiceProvider.cs | 1 - 4 files changed, 78 insertions(+), 62 deletions(-) create mode 100644 src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs delete mode 100644 src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs diff --git a/src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs b/src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs new file mode 100644 index 00000000..a1df335c --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs @@ -0,0 +1,61 @@ +// 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.Core.WindowsInstaller.ExtensibilityServices +{ + using System.Linq; + using WixToolset.Data; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Services; + + internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper + { + public Row CreateRow(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinition tableDefinition) + { + var table = output.EnsureTable(tableDefinition); + + var row = table.CreateRow(tuple.SourceLineNumbers); + row.SectionId = section.Id; + + return row; + } + + public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) + { + var tableDefinition = tableDefinitions.FirstOrDefault(t => t.TupleDefinition?.Name == tuple.Definition.Name); + if (tableDefinition == null) + { + return false; + } + + var row = this.CreateRow(section, tuple, output, 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; + } + } + } + + return true; + } + } +} diff --git a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs index f3671332..15fbf679 100644 --- a/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs +++ b/src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs @@ -2,16 +2,33 @@ namespace WixToolset.Core.WindowsInstaller { + using System; + using System.Collections.Generic; + using WixToolset.Core.WindowsInstaller.ExtensibilityServices; using WixToolset.Extensibility.Services; public static class WixToolsetCoreServiceProviderExtensions { public static IWixToolsetCoreServiceProvider AddWindowsInstallerBackend(this IWixToolsetCoreServiceProvider coreProvider) { + AddServices(coreProvider); + var extensionManager = coreProvider.GetService(); extensionManager.Add(typeof(WindowsInstallerExtensionFactory).Assembly); return coreProvider; } + + private static void AddServices(IWixToolsetCoreServiceProvider coreProvider) + { + // Singletons. + coreProvider.AddService((provider, singletons) => AddSingleton(singletons, new WindowsInstallerBackendHelper())); + } + + private static T AddSingleton(Dictionary singletons, T service) where T : class + { + singletons.Add(typeof(T), service); + return service; + } } } diff --git a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs deleted file mode 100644 index a923a8cc..00000000 --- a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs +++ /dev/null @@ -1,61 +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.Core.ExtensibilityServices -{ - using System.Linq; - using WixToolset.Data; - using WixToolset.Data.WindowsInstaller; - using WixToolset.Extensibility.Services; - - internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper - { - public Row CreateRow(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinition tableDefinition) - { - var table = output.EnsureTable(tableDefinition); - - var row = table.CreateRow(tuple.SourceLineNumbers); - row.SectionId = section.Id; - - return row; - } - - public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) - { - var tableDefinition = tableDefinitions.FirstOrDefault(t => t.TupleDefinition?.Name == tuple.Definition.Name); - if (tableDefinition == null) - { - return false; - } - - var row = this.CreateRow(section, tuple, output, 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; - } - } - } - - return true; - } - } -} diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs index 1d475d00..d7a6171a 100644 --- a/src/WixToolset.Core/WixToolsetServiceProvider.cs +++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs @@ -25,7 +25,6 @@ namespace WixToolset.Core this.AddService((provider, singletons) => AddSingleton(singletons, new PreprocessHelper(provider))); this.AddService((provider, singletons) => AddSingleton(singletons, new BackendHelper(provider))); this.AddService((provider, singletons) => AddSingleton(singletons, new PathResolver())); - this.AddService((provider, singletons) => AddSingleton(singletons, new WindowsInstallerBackendHelper())); // Transients. this.AddService((provider, singletons) => new CommandLineArguments(provider)); -- cgit v1.2.3-55-g6feb