diff options
Diffstat (limited to 'src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs')
-rw-r--r-- | src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs new file mode 100644 index 00000000..3b41fdf1 --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs | |||
@@ -0,0 +1,53 @@ | |||
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.ExtensibilityServices | ||
4 | { | ||
5 | using System; | ||
6 | using System.Linq; | ||
7 | using WixToolset.Data; | ||
8 | using WixToolset.Data.WindowsInstaller; | ||
9 | using WixToolset.Extensibility.Services; | ||
10 | |||
11 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper | ||
12 | { | ||
13 | public WindowsInstallerBackendHelper(IServiceProvider serviceProvider) | ||
14 | { | ||
15 | this.ServiceProvider = serviceProvider; | ||
16 | } | ||
17 | |||
18 | private IServiceProvider ServiceProvider { get; } | ||
19 | |||
20 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions) | ||
21 | { | ||
22 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.Name == tuple.Definition.Name); | ||
23 | |||
24 | if (tableDefinition == null) | ||
25 | { | ||
26 | return false; | ||
27 | } | ||
28 | |||
29 | var table = output.EnsureTable(tableDefinition); | ||
30 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
31 | for (var i = 0; i < tuple.Fields.Length; ++i) | ||
32 | { | ||
33 | if (i < tableDefinition.Columns.Count) | ||
34 | { | ||
35 | var column = tableDefinition.Columns[i]; | ||
36 | |||
37 | switch (column.Type) | ||
38 | { | ||
39 | case ColumnType.Number: | ||
40 | row[i] = tuple.AsNumber(i); | ||
41 | break; | ||
42 | |||
43 | default: | ||
44 | row[i] = tuple.AsString(i); | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | return true; | ||
51 | } | ||
52 | } | ||
53 | } | ||