From f92c72546326fb9b893bb7760691ee67ec7ab832 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 10 Apr 2020 10:17:26 +1000 Subject: Modernize HttpCompiler and tuples. --- .../WixToolsetTest.Http/HttpExtensionFixture.cs | 4 +- src/wixext/HttpCompiler.cs | 57 ++++++++++++---------- src/wixext/HttpTableDefinitions.cs | 42 ++++++++++++++++ .../HttpWindowsInstallerBackendBinderExtension.cs | 18 +------ src/wixext/Tuples/WixHttpUrlAceTuple.cs | 18 ++----- src/wixext/Tuples/WixHttpUrlReservationTuple.cs | 18 ++----- src/wixext/WixToolset.Http.wixext.csproj | 1 - src/wixext/tables.xml | 28 ----------- 8 files changed, 86 insertions(+), 100 deletions(-) create mode 100644 src/wixext/HttpTableDefinitions.cs delete mode 100644 src/wixext/tables.xml diff --git a/src/test/WixToolsetTest.Http/HttpExtensionFixture.cs b/src/test/WixToolsetTest.Http/HttpExtensionFixture.cs index 5658b657..947daec9 100644 --- a/src/test/WixToolsetTest.Http/HttpExtensionFixture.cs +++ b/src/test/WixToolsetTest.Http/HttpExtensionFixture.cs @@ -11,7 +11,7 @@ namespace WixToolsetTest.Http public class HttpExtensionFixture { [Fact] - public void CanBuildUsingMessageQueue() + public void CanBuildUsingUrlReservation() { var folder = TestData.Get(@"TestData\UsingUrlReservation"); var build = new Builder(folder, typeof(HttpExtensionFactory), new[] { folder }); @@ -21,7 +21,7 @@ namespace WixToolsetTest.Http { "WixHttpUrlAce:ace3u9zYtPm8dLIoYgB0bARb0dbB9w\turlt8sDcF469vDrZNldk0moxI25IGM\tNT SERVICE\\TestService\t268435456", "WixHttpUrlReservation:urlt8sDcF469vDrZNldk0moxI25IGM\t0\t\thttp://+:80/vroot/\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo", - }, results.OrderBy(s => s).ToArray()); + }, results); } private static void Build(string[] args) diff --git a/src/wixext/HttpCompiler.cs b/src/wixext/HttpCompiler.cs index 094f5594..e47990db 100644 --- a/src/wixext/HttpCompiler.cs +++ b/src/wixext/HttpCompiler.cs @@ -28,9 +28,9 @@ namespace WixToolset.Http switch (parentElement.Name.LocalName) { case "ServiceInstall": - string serviceInstallName = context["ServiceInstallName"]; - string serviceUser = String.IsNullOrEmpty(serviceInstallName) ? null : String.Concat("NT SERVICE\\", serviceInstallName); - string serviceComponentId = context["ServiceInstallComponentId"]; + var serviceInstallName = context["ServiceInstallName"]; + var serviceUser = String.IsNullOrEmpty(serviceInstallName) ? null : String.Concat("NT SERVICE\\", serviceInstallName); + var serviceComponentId = context["ServiceInstallComponentId"]; switch (element.Name.LocalName) { @@ -69,15 +69,14 @@ namespace WixToolset.Http /// The security principal of the parent element (null if nested under Component). private void ParseUrlReservationElement(Intermediate intermediate, IntermediateSection section, XElement node, string componentId, string securityPrincipal) { - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); Identifier id = null; - int handleExisting = HttpConstants.heReplace; - string handleExistingValue = null; + var handleExisting = HttpConstants.heReplace; string sddl = null; string url = null; - bool foundACE = false; + var foundACE = false; - foreach (XAttribute attrib in node.Attributes()) + foreach (var attrib in node.Attributes()) { if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) { @@ -87,7 +86,7 @@ namespace WixToolset.Http id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); break; case "HandleExisting": - handleExistingValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + var handleExistingValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); switch (handleExistingValue) { case "replace": @@ -128,7 +127,7 @@ namespace WixToolset.Http } // Parse UrlAce children. - foreach (XElement child in node.Elements()) + foreach (var child in node.Elements()) { if (this.Namespace == child.Name.Namespace) { @@ -170,23 +169,25 @@ namespace WixToolset.Http if (!this.Messaging.EncounteredError) { - var row = (WixHttpUrlReservationTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixHttpUrlReservation", id); - row.HandleExisting = handleExisting; - row.Sddl = sddl; - row.Url = url; - row.Component_ = componentId; + section.AddTuple(new WixHttpUrlReservationTuple(sourceLineNumbers, id) + { + HandleExisting = handleExisting, + Sddl = sddl, + Url = url, + ComponentRef = componentId, + }); if (this.Context.Platform == Platform.ARM) { // Ensure ARM version of the CA is referenced. - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall_ARM"); - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall_ARM"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsInstall_ARM"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsUninstall_ARM"); } else { // All other supported platforms use x86. - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall"); - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsInstall"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsUninstall"); } } } @@ -199,13 +200,13 @@ namespace WixToolset.Http /// The default security principal. private void ParseUrlAceElement(Intermediate intermediate, IntermediateSection section, XElement node, string urlReservationId, string defaultSecurityPrincipal) { - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); Identifier id = null; - string securityPrincipal = defaultSecurityPrincipal; - int rights = HttpConstants.GENERIC_ALL; + var securityPrincipal = defaultSecurityPrincipal; + var rights = HttpConstants.GENERIC_ALL; string rightsValue = null; - foreach (XAttribute attrib in node.Attributes()) + foreach (var attrib in node.Attributes()) { if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) { @@ -262,10 +263,12 @@ namespace WixToolset.Http if (!this.Messaging.EncounteredError) { - var row = (WixHttpUrlAceTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixHttpUrlAce", id); - row.WixHttpUrlReservation_ = urlReservationId; - row.SecurityPrincipal = securityPrincipal; - row.Rights = rights; + section.AddTuple(new WixHttpUrlAceTuple(sourceLineNumbers, id) + { + WixHttpUrlReservationRef = urlReservationId, + SecurityPrincipal = securityPrincipal, + Rights = rights, + }); } } } diff --git a/src/wixext/HttpTableDefinitions.cs b/src/wixext/HttpTableDefinitions.cs new file mode 100644 index 00000000..57422475 --- /dev/null +++ b/src/wixext/HttpTableDefinitions.cs @@ -0,0 +1,42 @@ +// 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.Http +{ + using WixToolset.Data.WindowsInstaller; + + public static class HttpTableDefinitions + { + public static readonly TableDefinition WixHttpUrlReservation = new TableDefinition( + "WixHttpUrlReservation", + new[] + { + new ColumnDefinition("WixHttpUrlReservation", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("HandleExisting", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 2, description: "The behavior when trying to install a URL reservation and it already exists."), + new ColumnDefinition("Sddl", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Security descriptor for the URL reservation.", modularizeType: ColumnModularizeType.Property), + new ColumnDefinition("Url", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "URL to be reserved.", modularizeType: ColumnModularizeType.Property), + new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key into the Component table referencing the component that controls the URL reservation.", modularizeType: ColumnModularizeType.Column), + }, + tupleDefinitionName: HttpTupleDefinitions.WixHttpUrlReservation.Name, + tupleIdIsPrimaryKey: true + ); + + public static readonly TableDefinition WixHttpUrlAce = new TableDefinition( + "WixHttpUrlAce", + new[] + { + new ColumnDefinition("WixHttpUrlAce", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("WixHttpUrlReservation_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "WixHttpUrlReservation", keyColumn: 1, description: "Foreign key into the WixHttpUrlReservation table.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("SecurityPrincipal", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "The security principal for this ACE.", modularizeType: ColumnModularizeType.Property), + new ColumnDefinition("Rights", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 1073741824, description: "The rights for this ACE."), + }, + tupleDefinitionName: HttpTupleDefinitions.WixHttpUrlAce.Name, + tupleIdIsPrimaryKey: true + ); + + public static readonly TableDefinition[] All = new[] + { + WixHttpUrlReservation, + WixHttpUrlAce, + }; + } +} diff --git a/src/wixext/HttpWindowsInstallerBackendBinderExtension.cs b/src/wixext/HttpWindowsInstallerBackendBinderExtension.cs index f8dd1838..7a94257b 100644 --- a/src/wixext/HttpWindowsInstallerBackendBinderExtension.cs +++ b/src/wixext/HttpWindowsInstallerBackendBinderExtension.cs @@ -1,27 +1,13 @@ -// 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. +// 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.Http { using System.Collections.Generic; - using System.Linq; - using System.Xml; using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility; public class HttpWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension { - private static readonly TableDefinition[] Tables = LoadTables(); - - public override IEnumerable TableDefinitions => Tables; - - private static TableDefinition[] LoadTables() - { - using (var resourceStream = typeof(HttpWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.Http.tables.xml")) - using (var reader = XmlReader.Create(resourceStream)) - { - var tables = TableDefinitionCollection.Load(reader); - return tables.ToArray(); - } - } + public override IEnumerable TableDefinitions => HttpTableDefinitions.All; } } diff --git a/src/wixext/Tuples/WixHttpUrlAceTuple.cs b/src/wixext/Tuples/WixHttpUrlAceTuple.cs index 3e0006a0..f605c217 100644 --- a/src/wixext/Tuples/WixHttpUrlAceTuple.cs +++ b/src/wixext/Tuples/WixHttpUrlAceTuple.cs @@ -11,8 +11,7 @@ namespace WixToolset.Http HttpTupleDefinitionType.WixHttpUrlAce.ToString(), new[] { - new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlAce), IntermediateFieldType.String), - new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlReservation_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlReservationRef), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.SecurityPrincipal), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.Rights), IntermediateFieldType.Number), }, @@ -26,8 +25,7 @@ namespace WixToolset.Http.Tuples public enum WixHttpUrlAceTupleFields { - WixHttpUrlAce, - WixHttpUrlReservation_, + WixHttpUrlReservationRef, SecurityPrincipal, Rights, } @@ -44,16 +42,10 @@ namespace WixToolset.Http.Tuples public IntermediateField this[WixHttpUrlAceTupleFields index] => this.Fields[(int)index]; - public string WixHttpUrlAce + public string WixHttpUrlReservationRef { - get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlAce].AsString(); - set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlAce, value); - } - - public string WixHttpUrlReservation_ - { - get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlReservation_].AsString(); - set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlReservation_, value); + get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlReservationRef].AsString(); + set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlReservationRef, value); } public string SecurityPrincipal diff --git a/src/wixext/Tuples/WixHttpUrlReservationTuple.cs b/src/wixext/Tuples/WixHttpUrlReservationTuple.cs index 7a251f3d..d7dbb0a5 100644 --- a/src/wixext/Tuples/WixHttpUrlReservationTuple.cs +++ b/src/wixext/Tuples/WixHttpUrlReservationTuple.cs @@ -11,11 +11,10 @@ namespace WixToolset.Http HttpTupleDefinitionType.WixHttpUrlReservation.ToString(), new[] { - new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.WixHttpUrlReservation), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.HandleExisting), IntermediateFieldType.Number), new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Sddl), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Url), IntermediateFieldType.String), - new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Component_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.ComponentRef), IntermediateFieldType.String), }, typeof(WixHttpUrlReservationTuple)); } @@ -27,11 +26,10 @@ namespace WixToolset.Http.Tuples public enum WixHttpUrlReservationTupleFields { - WixHttpUrlReservation, HandleExisting, Sddl, Url, - Component_, + ComponentRef, } public class WixHttpUrlReservationTuple : IntermediateTuple @@ -46,12 +44,6 @@ namespace WixToolset.Http.Tuples public IntermediateField this[WixHttpUrlReservationTupleFields index] => this.Fields[(int)index]; - public string WixHttpUrlReservation - { - get => this.Fields[(int)WixHttpUrlReservationTupleFields.WixHttpUrlReservation].AsString(); - set => this.Set((int)WixHttpUrlReservationTupleFields.WixHttpUrlReservation, value); - } - public int HandleExisting { get => this.Fields[(int)WixHttpUrlReservationTupleFields.HandleExisting].AsNumber(); @@ -70,10 +62,10 @@ namespace WixToolset.Http.Tuples set => this.Set((int)WixHttpUrlReservationTupleFields.Url, value); } - public string Component_ + public string ComponentRef { - get => this.Fields[(int)WixHttpUrlReservationTupleFields.Component_].AsString(); - set => this.Set((int)WixHttpUrlReservationTupleFields.Component_, value); + get => this.Fields[(int)WixHttpUrlReservationTupleFields.ComponentRef].AsString(); + set => this.Set((int)WixHttpUrlReservationTupleFields.ComponentRef, value); } } } \ No newline at end of file diff --git a/src/wixext/WixToolset.Http.wixext.csproj b/src/wixext/WixToolset.Http.wixext.csproj index c681e308..59c278e6 100644 --- a/src/wixext/WixToolset.Http.wixext.csproj +++ b/src/wixext/WixToolset.Http.wixext.csproj @@ -14,7 +14,6 @@ - diff --git a/src/wixext/tables.xml b/src/wixext/tables.xml deleted file mode 100644 index 576fc2a7..00000000 --- a/src/wixext/tables.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-55-g6feb