Modernize HttpCompiler and tuples.
Sean Hall committed
Apr 10, 2020 at 10:17 UTC
f92c72546326fb9b893bb7760691ee67ec7ab832
8 files changed
+86
-100
src/test/WixToolsetTest.Http/HttpExtensionFixture.cs
+2
-2
@@ -11,7 +11,7 @@ namespace WixToolsetTest.Http
11
public class HttpExtensionFixture
12
{
13
[Fact]
14
- public void CanBuildUsingMessageQueue()
14
+ public void CanBuildUsingUrlReservation()
15
{
16
var folder = TestData.Get(@"TestData\UsingUrlReservation");
17
var build = new Builder(folder, typeof(HttpExtensionFactory), new[] { folder });
@@ -21,7 +21,7 @@ namespace WixToolsetTest.Http
21
{
22
"WixHttpUrlAce:ace3u9zYtPm8dLIoYgB0bARb0dbB9w\turlt8sDcF469vDrZNldk0moxI25IGM\tNT SERVICE\\TestService\t268435456",
23
"WixHttpUrlReservation:urlt8sDcF469vDrZNldk0moxI25IGM\t0\t\thttp://+:80/vroot/\tfilF5_pLhBuF5b4N9XEo52g_hUM5Lo",
24
- }, results.OrderBy(s => s).ToArray());
24
+ }, results);
25
}
26
27
private static void Build(string[] args)
src/wixext/HttpCompiler.cs
+30
-27
@@ -28,9 +28,9 @@ namespace WixToolset.Http
28
switch (parentElement.Name.LocalName)
29
{
30
case "ServiceInstall":
31
- string serviceInstallName = context["ServiceInstallName"];
32
- string serviceUser = String.IsNullOrEmpty(serviceInstallName) ? null : String.Concat("NT SERVICE\\", serviceInstallName);
33
- string serviceComponentId = context["ServiceInstallComponentId"];
31
+ var serviceInstallName = context["ServiceInstallName"];
32
+ var serviceUser = String.IsNullOrEmpty(serviceInstallName) ? null : String.Concat("NT SERVICE\\", serviceInstallName);
33
+ var serviceComponentId = context["ServiceInstallComponentId"];
34
35
switch (element.Name.LocalName)
36
{
@@ -69,15 +69,14 @@ namespace WixToolset.Http
69
/// <param name="securityPrincipal">The security principal of the parent element (null if nested under Component).</param>
70
private void ParseUrlReservationElement(Intermediate intermediate, IntermediateSection section, XElement node, string componentId, string securityPrincipal)
71
{
72
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
72
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
73
Identifier id = null;
74
- int handleExisting = HttpConstants.heReplace;
75
- string handleExistingValue = null;
74
+ var handleExisting = HttpConstants.heReplace;
75
string sddl = null;
76
string url = null;
78
- bool foundACE = false;
77
+ var foundACE = false;
78
80
- foreach (XAttribute attrib in node.Attributes())
79
+ foreach (var attrib in node.Attributes())
80
{
81
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
82
{
@@ -87,7 +86,7 @@ namespace WixToolset.Http
86
id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib);
87
break;
88
case "HandleExisting":
90
- handleExistingValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
89
+ var handleExistingValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
90
switch (handleExistingValue)
91
{
92
case "replace":
@@ -128,7 +127,7 @@ namespace WixToolset.Http
127
}
128
129
// Parse UrlAce children.
131
- foreach (XElement child in node.Elements())
130
+ foreach (var child in node.Elements())
131
{
132
if (this.Namespace == child.Name.Namespace)
133
{
@@ -170,23 +169,25 @@ namespace WixToolset.Http
169
170
if (!this.Messaging.EncounteredError)
171
{
173
- var row = (WixHttpUrlReservationTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixHttpUrlReservation", id);
174
- row.HandleExisting = handleExisting;
175
- row.Sddl = sddl;
176
- row.Url = url;
177
- row.Component_ = componentId;
172
+ section.AddTuple(new WixHttpUrlReservationTuple(sourceLineNumbers, id)
173
+ {
174
+ HandleExisting = handleExisting,
175
+ Sddl = sddl,
176
+ Url = url,
177
+ ComponentRef = componentId,
178
+ });
179
180
if (this.Context.Platform == Platform.ARM)
181
{
182
// Ensure ARM version of the CA is referenced.
182
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall_ARM");
183
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall_ARM");
183
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsInstall_ARM");
184
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsUninstall_ARM");
185
}
186
else
187
{
188
// All other supported platforms use x86.
188
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsInstall");
189
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedHttpUrlReservationsUninstall");
189
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsInstall");
190
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedHttpUrlReservationsUninstall");
191
}
192
}
193
}
@@ -199,13 +200,13 @@ namespace WixToolset.Http
200
/// <param name="defaultSecurityPrincipal">The default security principal.</param>
201
private void ParseUrlAceElement(Intermediate intermediate, IntermediateSection section, XElement node, string urlReservationId, string defaultSecurityPrincipal)
202
{
202
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
203
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
204
Identifier id = null;
204
- string securityPrincipal = defaultSecurityPrincipal;
205
- int rights = HttpConstants.GENERIC_ALL;
205
+ var securityPrincipal = defaultSecurityPrincipal;
206
+ var rights = HttpConstants.GENERIC_ALL;
207
string rightsValue = null;
208
208
- foreach (XAttribute attrib in node.Attributes())
209
+ foreach (var attrib in node.Attributes())
210
{
211
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
212
{
@@ -262,10 +263,12 @@ namespace WixToolset.Http
263
264
if (!this.Messaging.EncounteredError)
265
{
265
- var row = (WixHttpUrlAceTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixHttpUrlAce", id);
266
- row.WixHttpUrlReservation_ = urlReservationId;
267
- row.SecurityPrincipal = securityPrincipal;
268
- row.Rights = rights;
266
+ section.AddTuple(new WixHttpUrlAceTuple(sourceLineNumbers, id)
267
+ {
268
+ WixHttpUrlReservationRef = urlReservationId,
269
+ SecurityPrincipal = securityPrincipal,
270
+ Rights = rights,
271
+ });
272
}
273
}
274
}
src/wixext/HttpTableDefinitions.cs
new
+42
@@ -0,0 +1,42 @@
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.Http
4
+{
5
+ using WixToolset.Data.WindowsInstaller;
6
+
7
+ public static class HttpTableDefinitions
8
+ {
9
+ public static readonly TableDefinition WixHttpUrlReservation = new TableDefinition(
10
+ "WixHttpUrlReservation",
11
+ new[]
12
+ {
13
+ new ColumnDefinition("WixHttpUrlReservation", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
14
+ 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."),
15
+ new ColumnDefinition("Sddl", ColumnType.String, 0, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Security descriptor for the URL reservation.", modularizeType: ColumnModularizeType.Property),
16
+ new ColumnDefinition("Url", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "URL to be reserved.", modularizeType: ColumnModularizeType.Property),
17
+ 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),
18
+ },
19
+ tupleDefinitionName: HttpTupleDefinitions.WixHttpUrlReservation.Name,
20
+ tupleIdIsPrimaryKey: true
21
+ );
22
+
23
+ public static readonly TableDefinition WixHttpUrlAce = new TableDefinition(
24
+ "WixHttpUrlAce",
25
+ new[]
26
+ {
27
+ new ColumnDefinition("WixHttpUrlAce", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The non-localized primary key for the table.", modularizeType: ColumnModularizeType.Column),
28
+ 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),
29
+ new ColumnDefinition("SecurityPrincipal", ColumnType.String, 0, primaryKey: false, nullable: false, ColumnCategory.Formatted, description: "The security principal for this ACE.", modularizeType: ColumnModularizeType.Property),
30
+ new ColumnDefinition("Rights", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 1073741824, description: "The rights for this ACE."),
31
+ },
32
+ tupleDefinitionName: HttpTupleDefinitions.WixHttpUrlAce.Name,
33
+ tupleIdIsPrimaryKey: true
34
+ );
35
+
36
+ public static readonly TableDefinition[] All = new[]
37
+ {
38
+ WixHttpUrlReservation,
39
+ WixHttpUrlAce,
40
+ };
41
+ }
42
+}
src/wixext/HttpWindowsInstallerBackendBinderExtension.cs
+2
-16
@@ -1,27 +1,13 @@
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.
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.Http
4
{
5
using System.Collections.Generic;
6
- using System.Linq;
7
- using System.Xml;
6
using WixToolset.Data.WindowsInstaller;
7
using WixToolset.Extensibility;
8
9
public class HttpWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension
10
{
13
- private static readonly TableDefinition[] Tables = LoadTables();
14
-
15
- public override IEnumerable<TableDefinition> TableDefinitions => Tables;
16
-
17
- private static TableDefinition[] LoadTables()
18
- {
19
- using (var resourceStream = typeof(HttpWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.Http.tables.xml"))
20
- using (var reader = XmlReader.Create(resourceStream))
21
- {
22
- var tables = TableDefinitionCollection.Load(reader);
23
- return tables.ToArray();
24
- }
25
- }
11
+ public override IEnumerable<TableDefinition> TableDefinitions => HttpTableDefinitions.All;
12
}
13
}
src/wixext/Tuples/WixHttpUrlAceTuple.cs
+5
-13
@@ -11,8 +11,7 @@ namespace WixToolset.Http
11
HttpTupleDefinitionType.WixHttpUrlAce.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlAce), IntermediateFieldType.String),
15
- new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlReservation_), IntermediateFieldType.String),
14
+ new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.WixHttpUrlReservationRef), IntermediateFieldType.String),
15
new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.SecurityPrincipal), IntermediateFieldType.String),
16
new IntermediateFieldDefinition(nameof(WixHttpUrlAceTupleFields.Rights), IntermediateFieldType.Number),
17
},
@@ -26,8 +25,7 @@ namespace WixToolset.Http.Tuples
25
26
public enum WixHttpUrlAceTupleFields
27
{
29
- WixHttpUrlAce,
30
- WixHttpUrlReservation_,
28
+ WixHttpUrlReservationRef,
29
SecurityPrincipal,
30
Rights,
31
}
@@ -44,16 +42,10 @@ namespace WixToolset.Http.Tuples
42
43
public IntermediateField this[WixHttpUrlAceTupleFields index] => this.Fields[(int)index];
44
47
- public string WixHttpUrlAce
45
+ public string WixHttpUrlReservationRef
46
{
49
- get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlAce].AsString();
50
- set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlAce, value);
51
- }
52
-
53
- public string WixHttpUrlReservation_
54
- {
55
- get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlReservation_].AsString();
56
- set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlReservation_, value);
47
+ get => this.Fields[(int)WixHttpUrlAceTupleFields.WixHttpUrlReservationRef].AsString();
48
+ set => this.Set((int)WixHttpUrlAceTupleFields.WixHttpUrlReservationRef, value);
49
}
50
51
public string SecurityPrincipal
src/wixext/Tuples/WixHttpUrlReservationTuple.cs
+5
-13
@@ -11,11 +11,10 @@ namespace WixToolset.Http
11
HttpTupleDefinitionType.WixHttpUrlReservation.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.WixHttpUrlReservation), IntermediateFieldType.String),
14
new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.HandleExisting), IntermediateFieldType.Number),
15
new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Sddl), IntermediateFieldType.String),
16
new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Url), IntermediateFieldType.String),
18
- new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.Component_), IntermediateFieldType.String),
17
+ new IntermediateFieldDefinition(nameof(WixHttpUrlReservationTupleFields.ComponentRef), IntermediateFieldType.String),
18
},
19
typeof(WixHttpUrlReservationTuple));
20
}
@@ -27,11 +26,10 @@ namespace WixToolset.Http.Tuples
26
27
public enum WixHttpUrlReservationTupleFields
28
{
30
- WixHttpUrlReservation,
29
HandleExisting,
30
Sddl,
31
Url,
34
- Component_,
32
+ ComponentRef,
33
}
34
35
public class WixHttpUrlReservationTuple : IntermediateTuple
@@ -46,12 +44,6 @@ namespace WixToolset.Http.Tuples
44
45
public IntermediateField this[WixHttpUrlReservationTupleFields index] => this.Fields[(int)index];
46
49
- public string WixHttpUrlReservation
50
- {
51
- get => this.Fields[(int)WixHttpUrlReservationTupleFields.WixHttpUrlReservation].AsString();
52
- set => this.Set((int)WixHttpUrlReservationTupleFields.WixHttpUrlReservation, value);
53
- }
54
-
47
public int HandleExisting
48
{
49
get => this.Fields[(int)WixHttpUrlReservationTupleFields.HandleExisting].AsNumber();
@@ -70,10 +62,10 @@ namespace WixToolset.Http.Tuples
62
set => this.Set((int)WixHttpUrlReservationTupleFields.Url, value);
63
}
64
73
- public string Component_
65
+ public string ComponentRef
66
{
75
- get => this.Fields[(int)WixHttpUrlReservationTupleFields.Component_].AsString();
76
- set => this.Set((int)WixHttpUrlReservationTupleFields.Component_, value);
67
+ get => this.Fields[(int)WixHttpUrlReservationTupleFields.ComponentRef].AsString();
68
+ set => this.Set((int)WixHttpUrlReservationTupleFields.ComponentRef, value);
69
}
70
}
71
}
\ No newline at end of file
src/wixext/WixToolset.Http.wixext.csproj
-1
@@ -14,7 +14,6 @@
14
<ItemGroup>
15
<Content Include="$(MSBuildThisFileName).targets" />
16
<Content Include="http.xsd" PackagePath="tools" />
17
- <EmbeddedResource Include="tables.xml" />
17
<EmbeddedResource Include="$(OutputPath)..\http.wixlib" />
18
</ItemGroup>
19
src/wixext/tables.xml
deleted
-28
@@ -1,28 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<!-- 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. -->
3
-
4
-
5
-<tableDefinitions xmlns="http://wixtoolset.org/schemas/v4/wi/tables">
6
- <tableDefinition name="WixHttpUrlReservation">
7
- <columnDefinition name="WixHttpUrlReservation" type="string" length="72" primaryKey="yes" modularize="column"
8
- category="identifier" description="The non-localized primary key for the table." />
9
- <columnDefinition name="HandleExisting" type="number" length="4" nullable="no"
10
- minValue="0" maxValue="2" description="The behavior when trying to install a URL reservation and it already exists." />
11
- <columnDefinition name="Sddl" type="string" length="0" modularize="property" nullable="yes"
12
- category="formatted" description="Security descriptor for the URL reservation." />
13
- <columnDefinition name="Url" type="string" length="0" modularize="property" nullable="no"
14
- category="formatted" description="URL to be reserved." />
15
- <columnDefinition name="Component_" type="string" length="72" modularize="column"
16
- keyTable="Component" keyColumn="1" category="identifier" description="Foreign key into the Component table referencing the component that controls the URL reservation." />
17
- </tableDefinition>
18
- <tableDefinition name="WixHttpUrlAce">
19
- <columnDefinition name="WixHttpUrlAce" type="string" length="72" primaryKey="yes" modularize="column"
20
- category="identifier" description="The non-localized primary key for the table." />
21
- <columnDefinition name="WixHttpUrlReservation_" type="string" length="72" keyTable="WixHttpUrlReservation" keyColumn="1" modularize="column"
22
- category="identifier" description="Foreign key into the WixHttpUrlReservation table." />
23
- <columnDefinition name="SecurityPrincipal" type="string" length="0" modularize="property"
24
- category="formatted" description="The security principal for this ACE." />
25
- <columnDefinition name="Rights" type="number" length="4" nullable="no"
26
- minValue="0" maxValue="1073741824" description="The rights for this ACE." />
27
- </tableDefinition>
28
-</tableDefinitions>