diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-18 14:43:31 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-18 21:31:28 +1000 |
| commit | a6091afa5bd24fe65e7fc20f179ed888301afdf8 (patch) | |
| tree | 020cf8336d4f282bac818d2d7a5d2a6b0ae10ff0 | |
| parent | c7f9ef7e7bcceb670b56a70fc9aa92152fd55573 (diff) | |
| download | wix-a6091afa5bd24fe65e7fc20f179ed888301afdf8.tar.gz wix-a6091afa5bd24fe65e7fc20f179ed888301afdf8.tar.bz2 wix-a6091afa5bd24fe65e7fc20f179ed888301afdf8.zip | |
Test ability for an extension to have a custom strongly typed row during binding.
7 files changed, 85 insertions, 33 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs index ea6e4f31..ffe26249 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs | |||
| @@ -307,7 +307,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 307 | 307 | ||
| 308 | // process modified and unmodified rows | 308 | // process modified and unmodified rows |
| 309 | var modifiedRow = false; | 309 | var modifiedRow = false; |
| 310 | var targetRow = new Row(null, table.Definition); | 310 | var targetRow = table.Definition.CreateRow(null); |
| 311 | var updatedRow = row; | 311 | var updatedRow = row; |
| 312 | for (var i = 0; i < row.Fields.Length; i++) | 312 | for (var i = 0; i < row.Fields.Length; i++) |
| 313 | { | 313 | { |
diff --git a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs index ea9cac07..560b5437 100644 --- a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs +++ b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs | |||
| @@ -747,7 +747,7 @@ namespace WixToolset.Core.WindowsInstaller | |||
| 747 | property.Id = id; | 747 | property.Id = id; |
| 748 | 748 | ||
| 749 | // create a dummy row for indexing | 749 | // create a dummy row for indexing |
| 750 | var row = new Row(null, this.tableDefinitions["Property"]); | 750 | var row = this.tableDefinitions["Property"].CreateRow(null); |
| 751 | row[0] = id; | 751 | row[0] = id; |
| 752 | 752 | ||
| 753 | this.core.RootElement.AddChild(property); | 753 | this.core.RootElement.AddChild(property); |
diff --git a/src/test/Example.Extension/ExampleExtensionData.cs b/src/test/Example.Extension/ExampleExtensionData.cs index b38eb2a2..2ba94397 100644 --- a/src/test/Example.Extension/ExampleExtensionData.cs +++ b/src/test/Example.Extension/ExampleExtensionData.cs | |||
| @@ -16,21 +16,7 @@ namespace Example.Extension | |||
| 16 | 16 | ||
| 17 | public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) | 17 | public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) |
| 18 | { | 18 | { |
| 19 | switch (name) | 19 | tupleDefinition = ExampleTupleDefinitions.ByName(name); |
| 20 | { | ||
| 21 | case "Example": | ||
| 22 | tupleDefinition = ExampleTupleDefinitions.Example; | ||
| 23 | break; | ||
| 24 | |||
| 25 | case "ExampleSearch": | ||
| 26 | tupleDefinition = ExampleTupleDefinitions.ExampleSearch; | ||
| 27 | break; | ||
| 28 | |||
| 29 | default: | ||
| 30 | tupleDefinition = null; | ||
| 31 | break; | ||
| 32 | } | ||
| 33 | |||
| 34 | return tupleDefinition != null; | 20 | return tupleDefinition != null; |
| 35 | } | 21 | } |
| 36 | } | 22 | } |
diff --git a/src/test/Example.Extension/ExampleRow.cs b/src/test/Example.Extension/ExampleRow.cs new file mode 100644 index 00000000..fc20c6c9 --- /dev/null +++ b/src/test/Example.Extension/ExampleRow.cs | |||
| @@ -0,0 +1,32 @@ | |||
| 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 Example.Extension | ||
| 4 | { | ||
| 5 | using WixToolset.Data; | ||
| 6 | using WixToolset.Data.WindowsInstaller; | ||
| 7 | |||
| 8 | public class ExampleRow : Row | ||
| 9 | { | ||
| 10 | public ExampleRow(SourceLineNumber sourceLineNumbers, Table table) | ||
| 11 | : base(sourceLineNumbers, table) | ||
| 12 | { | ||
| 13 | } | ||
| 14 | |||
| 15 | public ExampleRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDefinition) | ||
| 16 | : base(sourceLineNumbers, tableDefinition) | ||
| 17 | { | ||
| 18 | } | ||
| 19 | |||
| 20 | public string Example | ||
| 21 | { | ||
| 22 | get { return (string)this.Fields[0].Data; } | ||
| 23 | set { this.Fields[0].Data = value; } | ||
| 24 | } | ||
| 25 | |||
| 26 | public string Value | ||
| 27 | { | ||
| 28 | get { return (string)this.Fields[1].Data; } | ||
| 29 | set { this.Fields[1].Data = value; } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/src/test/Example.Extension/ExampleTableDefinitions.cs b/src/test/Example.Extension/ExampleTableDefinitions.cs index f204e5b6..4901cc09 100644 --- a/src/test/Example.Extension/ExampleTableDefinitions.cs +++ b/src/test/Example.Extension/ExampleTableDefinitions.cs | |||
| @@ -14,6 +14,7 @@ namespace Example.Extension | |||
| 14 | new ColumnDefinition("Example", ColumnType.String, 72, true, false, ColumnCategory.Identifier), | 14 | new ColumnDefinition("Example", ColumnType.String, 72, true, false, ColumnCategory.Identifier), |
| 15 | new ColumnDefinition("Value", ColumnType.String, 0, false, false, ColumnCategory.Formatted), | 15 | new ColumnDefinition("Value", ColumnType.String, 0, false, false, ColumnCategory.Formatted), |
| 16 | }, | 16 | }, |
| 17 | strongRowType: typeof(ExampleRow), | ||
| 17 | tupleIdIsPrimaryKey: true | 18 | tupleIdIsPrimaryKey: true |
| 18 | ); | 19 | ); |
| 19 | 20 | ||
diff --git a/src/test/Example.Extension/ExampleTupleDefinitions.cs b/src/test/Example.Extension/ExampleTupleDefinitions.cs index dd8b5bbf..446c2c45 100644 --- a/src/test/Example.Extension/ExampleTupleDefinitions.cs +++ b/src/test/Example.Extension/ExampleTupleDefinitions.cs | |||
| @@ -2,15 +2,20 @@ | |||
| 2 | 2 | ||
| 3 | namespace Example.Extension | 3 | namespace Example.Extension |
| 4 | { | 4 | { |
| 5 | using System; | ||
| 5 | using WixToolset.Data; | 6 | using WixToolset.Data; |
| 6 | using WixToolset.Data.Burn; | 7 | using WixToolset.Data.Burn; |
| 7 | 8 | ||
| 8 | public static class ExampleTupleDefinitions | 9 | public enum ExampleTupleDefinitionType |
| 9 | { | 10 | { |
| 10 | public const string ExampleName = "Example"; | 11 | Example, |
| 12 | ExampleSearch, | ||
| 13 | } | ||
| 11 | 14 | ||
| 15 | public static class ExampleTupleDefinitions | ||
| 16 | { | ||
| 12 | public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( | 17 | public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( |
| 13 | ExampleName, | 18 | ExampleTupleDefinitionType.Example.ToString(), |
| 14 | new[] | 19 | new[] |
| 15 | { | 20 | { |
| 16 | new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), | 21 | new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), |
| @@ -18,7 +23,7 @@ namespace Example.Extension | |||
| 18 | typeof(ExampleTuple)); | 23 | typeof(ExampleTuple)); |
| 19 | 24 | ||
| 20 | public static readonly IntermediateTupleDefinition ExampleSearch = new IntermediateTupleDefinition( | 25 | public static readonly IntermediateTupleDefinition ExampleSearch = new IntermediateTupleDefinition( |
| 21 | nameof(ExampleSearch), | 26 | ExampleTupleDefinitionType.ExampleSearch.ToString(), |
| 22 | new[] | 27 | new[] |
| 23 | { | 28 | { |
| 24 | new IntermediateFieldDefinition(nameof(ExampleSearchTupleFields.SearchFor), IntermediateFieldType.String), | 29 | new IntermediateFieldDefinition(nameof(ExampleSearchTupleFields.SearchFor), IntermediateFieldType.String), |
| @@ -29,5 +34,34 @@ namespace Example.Extension | |||
| 29 | { | 34 | { |
| 30 | ExampleSearch.AddTag(BurnConstants.BundleExtensionSearchTupleDefinitionTag); | 35 | ExampleSearch.AddTag(BurnConstants.BundleExtensionSearchTupleDefinitionTag); |
| 31 | } | 36 | } |
| 37 | |||
| 38 | public static bool TryGetTupleType(string name, out ExampleTupleDefinitionType type) | ||
| 39 | { | ||
| 40 | return Enum.TryParse(name, out type); | ||
| 41 | } | ||
| 42 | |||
| 43 | public static IntermediateTupleDefinition ByName(string name) | ||
| 44 | { | ||
| 45 | if (!TryGetTupleType(name, out var type)) | ||
| 46 | { | ||
| 47 | return null; | ||
| 48 | } | ||
| 49 | return ByType(type); | ||
| 50 | } | ||
| 51 | |||
| 52 | public static IntermediateTupleDefinition ByType(ExampleTupleDefinitionType type) | ||
| 53 | { | ||
| 54 | switch (type) | ||
| 55 | { | ||
| 56 | case ExampleTupleDefinitionType.Example: | ||
| 57 | return ExampleTupleDefinitions.Example; | ||
| 58 | |||
| 59 | case ExampleTupleDefinitionType.ExampleSearch: | ||
| 60 | return ExampleTupleDefinitions.ExampleSearch; | ||
| 61 | |||
| 62 | default: | ||
| 63 | throw new ArgumentOutOfRangeException(nameof(type)); | ||
| 64 | } | ||
| 65 | } | ||
| 32 | } | 66 | } |
| 33 | } | 67 | } |
diff --git a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs index 4ee682d3..2818cde4 100644 --- a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs +++ b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs | |||
| @@ -13,22 +13,21 @@ namespace Example.Extension | |||
| 13 | 13 | ||
| 14 | public override bool TryAddTupleToOutput(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) | 14 | public override bool TryAddTupleToOutput(IntermediateSection section, IntermediateTuple tuple, WindowsInstallerData output, TableDefinitionCollection tableDefinitions) |
| 15 | { | 15 | { |
| 16 | #if ALTERNATIVE_TO_USING_HELPER | 16 | if (ExampleTupleDefinitions.TryGetTupleType(tuple.Definition.Name, out var tupleType)) |
| 17 | switch (tuple.Definition.Name) | ||
| 18 | { | 17 | { |
| 19 | case ExampleTupleDefinitions.ExampleName: | 18 | switch (tupleType) |
| 20 | { | 19 | { |
| 21 | var row = this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable); | 20 | case ExampleTupleDefinitionType.Example: |
| 22 | row[0] = tuple[0].AsString(); | 21 | { |
| 23 | row[1] = tuple[1].AsString(); | 22 | var row = (ExampleRow)this.BackendHelper.CreateRow(section, tuple, output, ExampleTableDefinitions.ExampleTable); |
| 24 | } | 23 | row.Example = tuple.Id.Id; |
| 25 | return true; | 24 | row.Value = tuple[0].AsString(); |
| 25 | } | ||
| 26 | return true; | ||
| 27 | } | ||
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | return false; | ||
| 29 | #else | ||
| 30 | return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(section, tuple, output, tableDefinitions); | 30 | return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(section, tuple, output, tableDefinitions); |
| 31 | #endif | ||
| 32 | } | 31 | } |
| 33 | } | 32 | } |
| 34 | } | 33 | } |
