diff options
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/ExtensibilityServices/WindowsInstallerBackendHelper.cs | 61 | ||||
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs | 17 |
2 files changed, 78 insertions, 0 deletions
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 @@ | |||
| 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.Core.WindowsInstaller.ExtensibilityServices | ||
| 4 | { | ||
| 5 | using System.Linq; | ||
| 6 | using WixToolset.Data; | ||
| 7 | using WixToolset.Data.WindowsInstaller; | ||
| 8 | using WixToolset.Extensibility.Services; | ||
| 9 | |||
| 10 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper | ||
| 11 | { | ||
| 12 | public Row CreateRow(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinition tableDefinition) | ||
| 13 | { | ||
| 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.TupleDefinition?.Name == tuple.Definition.Name); | ||
| 25 | if (tableDefinition == null) | ||
| 26 | { | ||
| 27 | return false; | ||
| 28 | } | ||
| 29 | |||
| 30 | var row = this.CreateRow(section, tuple, output, tableDefinition); | ||
| 31 | var rowOffset = 0; | ||
| 32 | |||
| 33 | if (tableDefinition.TupleIdIsPrimaryKey) | ||
| 34 | { | ||
| 35 | row[0] = tuple.Id.Id; | ||
| 36 | rowOffset = 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | for (var i = 0; i < tuple.Fields.Length; ++i) | ||
| 40 | { | ||
| 41 | if (i < tableDefinition.Columns.Length) | ||
| 42 | { | ||
| 43 | var column = tableDefinition.Columns[i + rowOffset]; | ||
| 44 | |||
| 45 | switch (column.Type) | ||
| 46 | { | ||
| 47 | case ColumnType.Number: | ||
| 48 | row[i + rowOffset] = column.Nullable ? tuple.AsNullableNumber(i) : tuple.AsNumber(i); | ||
| 49 | break; | ||
| 50 | |||
| 51 | default: | ||
| 52 | row[i + rowOffset] = tuple.AsString(i); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | return true; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
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 @@ | |||
| 2 | 2 | ||
| 3 | namespace WixToolset.Core.WindowsInstaller | 3 | namespace WixToolset.Core.WindowsInstaller |
| 4 | { | 4 | { |
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using WixToolset.Core.WindowsInstaller.ExtensibilityServices; | ||
| 5 | using WixToolset.Extensibility.Services; | 8 | using WixToolset.Extensibility.Services; |
| 6 | 9 | ||
| 7 | public static class WixToolsetCoreServiceProviderExtensions | 10 | public static class WixToolsetCoreServiceProviderExtensions |
| 8 | { | 11 | { |
| 9 | public static IWixToolsetCoreServiceProvider AddWindowsInstallerBackend(this IWixToolsetCoreServiceProvider coreProvider) | 12 | public static IWixToolsetCoreServiceProvider AddWindowsInstallerBackend(this IWixToolsetCoreServiceProvider coreProvider) |
| 10 | { | 13 | { |
| 14 | AddServices(coreProvider); | ||
| 15 | |||
| 11 | var extensionManager = coreProvider.GetService<IExtensionManager>(); | 16 | var extensionManager = coreProvider.GetService<IExtensionManager>(); |
| 12 | extensionManager.Add(typeof(WindowsInstallerExtensionFactory).Assembly); | 17 | extensionManager.Add(typeof(WindowsInstallerExtensionFactory).Assembly); |
| 13 | 18 | ||
| 14 | return coreProvider; | 19 | return coreProvider; |
| 15 | } | 20 | } |
| 21 | |||
| 22 | private static void AddServices(IWixToolsetCoreServiceProvider coreProvider) | ||
| 23 | { | ||
| 24 | // Singletons. | ||
| 25 | coreProvider.AddService((provider, singletons) => AddSingleton<IWindowsInstallerBackendHelper>(singletons, new WindowsInstallerBackendHelper())); | ||
| 26 | } | ||
| 27 | |||
| 28 | private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class | ||
| 29 | { | ||
| 30 | singletons.Add(typeof(T), service); | ||
| 31 | return service; | ||
| 32 | } | ||
| 16 | } | 33 | } |
| 17 | } | 34 | } |
