aboutsummaryrefslogtreecommitdiff
path: root/src/test/Example.Extension
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/Example.Extension')
-rw-r--r--src/test/Example.Extension/Data/example.txt1
-rw-r--r--src/test/Example.Extension/Data/example.wirbin0 -> 534 bytes
-rw-r--r--src/test/Example.Extension/Data/example.wxs8
-rw-r--r--src/test/Example.Extension/Example.Extension.csproj20
-rw-r--r--src/test/Example.Extension/ExampleCompilerExtension.cs81
-rw-r--r--src/test/Example.Extension/ExampleExtensionData.cs33
-rw-r--r--src/test/Example.Extension/ExampleExtensionFactory.cs43
-rw-r--r--src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs50
-rw-r--r--src/test/Example.Extension/ExampleTableDefinitions.cs20
-rw-r--r--src/test/Example.Extension/ExampleTuple.cs31
-rw-r--r--src/test/Example.Extension/ExampleTupleDefinitions.cs20
-rw-r--r--src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs32
12 files changed, 339 insertions, 0 deletions
diff --git a/src/test/Example.Extension/Data/example.txt b/src/test/Example.Extension/Data/example.txt
new file mode 100644
index 00000000..1b4ffe8a
--- /dev/null
+++ b/src/test/Example.Extension/Data/example.txt
@@ -0,0 +1 @@
This is example.txt. \ No newline at end of file
diff --git a/src/test/Example.Extension/Data/example.wir b/src/test/Example.Extension/Data/example.wir
new file mode 100644
index 00000000..674f63fc
--- /dev/null
+++ b/src/test/Example.Extension/Data/example.wir
Binary files differ
diff --git a/src/test/Example.Extension/Data/example.wxs b/src/test/Example.Extension/Data/example.wxs
new file mode 100644
index 00000000..53531e99
--- /dev/null
+++ b/src/test/Example.Extension/Data/example.wxs
@@ -0,0 +1,8 @@
1<?xml version='1.0'?>
2<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <Property Id="PropertyFromExampleWir" Value="FromWir" />
5
6 <Binary Id="BinFromWir" SourceFile="example.txt" />
7 </Fragment>
8</Wix>
diff --git a/src/test/Example.Extension/Example.Extension.csproj b/src/test/Example.Extension/Example.Extension.csproj
new file mode 100644
index 00000000..1dde5044
--- /dev/null
+++ b/src/test/Example.Extension/Example.Extension.csproj
@@ -0,0 +1,20 @@
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<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netstandard2.0</TargetFramework>
7 <IsPackable>false</IsPackable>
8 <DebugType>embedded</DebugType>
9 </PropertyGroup>
10
11 <ItemGroup>
12 <EmbeddedResource Include="Data\Example.wir" />
13 </ItemGroup>
14
15 <ItemGroup>
16 <ProjectReference Include="$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj" Condition=" '$(Configuration)' == 'Debug' And Exists('$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj') " />
17 <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" Condition=" '$(Configuration)' == 'Release' Or !Exists('$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj') " />
18 </ItemGroup>
19
20</Project>
diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs
new file mode 100644
index 00000000..cd9e1fb9
--- /dev/null
+++ b/src/test/Example.Extension/ExampleCompilerExtension.cs
@@ -0,0 +1,81 @@
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
3namespace Example.Extension
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml.Linq;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10
11 internal class ExampleCompilerExtension : BaseCompilerExtension
12 {
13 public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs";
14
15 public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
16 {
17 var processed = false;
18
19 switch (parentElement.Name.LocalName)
20 {
21 case "Component":
22 switch (element.Name.LocalName)
23 {
24 case "Example":
25 this.ParseExampleElement(intermediate, section, element);
26 processed = true;
27 break;
28 }
29 break;
30 }
31
32 if (!processed)
33 {
34 base.ParseElement(intermediate, section, parentElement, element, context);
35 }
36 }
37
38 private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element)
39 {
40 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
41 Identifier id = null;
42 string value = null;
43
44 foreach (var attrib in element.Attributes())
45 {
46 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
47 {
48 switch (attrib.Name.LocalName)
49 {
50 case "Id":
51 id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib);
52 break;
53
54 case "Value":
55 value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
56 break;
57
58 default:
59 this.ParseHelper.UnexpectedAttribute(element, attrib);
60 break;
61 }
62 }
63 else
64 {
65 this.ParseAttribute(intermediate, section, element, attrib, null);
66 }
67 }
68
69 if (null == id)
70 {
71 //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
72 }
73
74 if (!this.Messaging.EncounteredError)
75 {
76 var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id);
77 tuple.Set(1, value);
78 }
79 }
80 }
81}
diff --git a/src/test/Example.Extension/ExampleExtensionData.cs b/src/test/Example.Extension/ExampleExtensionData.cs
new file mode 100644
index 00000000..724f9eea
--- /dev/null
+++ b/src/test/Example.Extension/ExampleExtensionData.cs
@@ -0,0 +1,33 @@
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
3namespace Example.Extension
4{
5 using WixToolset.Data;
6 using WixToolset.Extensibility;
7
8 internal class ExampleExtensionData : IExtensionData
9 {
10 public string DefaultCulture => null;
11
12 public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions)
13 {
14 return Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions);
15 }
16
17 public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
18 {
19 switch (name)
20 {
21 case "Example":
22 tupleDefinition = ExampleTupleDefinitions.Example;
23 break;
24
25 default:
26 tupleDefinition = null;
27 break;
28 }
29
30 return tupleDefinition != null;
31 }
32 }
33} \ No newline at end of file
diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs
new file mode 100644
index 00000000..a081b758
--- /dev/null
+++ b/src/test/Example.Extension/ExampleExtensionFactory.cs
@@ -0,0 +1,43 @@
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
3namespace Example.Extension
4{
5 using System;
6 using WixToolset.Extensibility;
7
8 public class ExampleExtensionFactory : IExtensionFactory
9 {
10 private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension;
11
12 public bool TryCreateExtension(Type extensionType, out object extension)
13 {
14 if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension))
15 {
16 if (preprocessorExtension == null)
17 {
18 preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine();
19 }
20
21 extension = preprocessorExtension;
22 }
23 else if (extensionType == typeof(ICompilerExtension))
24 {
25 extension = new ExampleCompilerExtension();
26 }
27 else if (extensionType == typeof(IExtensionData))
28 {
29 extension = new ExampleExtensionData();
30 }
31 else if (extensionType == typeof(IWindowsInstallerBackendExtension))
32 {
33 extension = new ExampleWindowsInstallerBackendExtension();
34 }
35 else
36 {
37 extension = null;
38 }
39
40 return extension != null;
41 }
42 }
43}
diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs
new file mode 100644
index 00000000..6f86e20d
--- /dev/null
+++ b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs
@@ -0,0 +1,50 @@
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
3namespace Example.Extension
4{
5 using System;
6 using System.Collections.Generic;
7 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Services;
9
10 internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine
11 {
12 private string exampleValueFromCommandLine;
13
14 public IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => throw new NotImplementedException();
15
16 public ExamplePreprocessorExtensionAndCommandLine()
17 {
18 this.Prefixes = new[] { "ex" };
19 }
20
21 public void PreParse(ICommandLineContext context)
22 {
23 }
24
25 public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg)
26 {
27 if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase))
28 {
29 this.exampleValueFromCommandLine = parseCommandLine.GetNextArgumentOrError(arg);
30 return true;
31 }
32
33 return false;
34 }
35
36 public void PostParse()
37 {
38 }
39
40 public override string GetVariableValue(string prefix, string name)
41 {
42 if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase))
43 {
44 return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine;
45 }
46
47 return null;
48 }
49 }
50} \ No newline at end of file
diff --git a/src/test/Example.Extension/ExampleTableDefinitions.cs b/src/test/Example.Extension/ExampleTableDefinitions.cs
new file mode 100644
index 00000000..dbd6491b
--- /dev/null
+++ b/src/test/Example.Extension/ExampleTableDefinitions.cs
@@ -0,0 +1,20 @@
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
3namespace Example.Extension
4{
5 using WixToolset.Data.WindowsInstaller;
6
7 public static class ExampleTableDefinitions
8 {
9 public static readonly TableDefinition ExampleTable = new TableDefinition(
10 "Example",
11 new[]
12 {
13 new ColumnDefinition("Example", ColumnType.String, 72, true, false, ColumnCategory.Identifier),
14 new ColumnDefinition("Value", ColumnType.String, 0, false, false, ColumnCategory.Formatted),
15 }
16 );
17
18 public static readonly TableDefinition[] All = new[] { ExampleTable };
19 }
20}
diff --git a/src/test/Example.Extension/ExampleTuple.cs b/src/test/Example.Extension/ExampleTuple.cs
new file mode 100644
index 00000000..0fc0d82c
--- /dev/null
+++ b/src/test/Example.Extension/ExampleTuple.cs
@@ -0,0 +1,31 @@
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
3namespace Example.Extension
4{
5 using WixToolset.Data;
6
7 public enum ExampleTupleFields
8 {
9 Example,
10 Value,
11 }
12
13 public class ExampleTuple : IntermediateTuple
14 {
15 public ExampleTuple() : base(ExampleTupleDefinitions.Example, null, null)
16 {
17 }
18
19 public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(ExampleTupleDefinitions.Example, sourceLineNumber, id)
20 {
21 }
22
23 public IntermediateField this[ExampleTupleFields index] => this.Fields[(int)index];
24
25 public string Value
26 {
27 get => this.Fields[(int)ExampleTupleFields.Value]?.AsString();
28 set => this.Set((int)ExampleTupleFields.Value, value);
29 }
30 }
31}
diff --git a/src/test/Example.Extension/ExampleTupleDefinitions.cs b/src/test/Example.Extension/ExampleTupleDefinitions.cs
new file mode 100644
index 00000000..4775b827
--- /dev/null
+++ b/src/test/Example.Extension/ExampleTupleDefinitions.cs
@@ -0,0 +1,20 @@
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
3namespace Example.Extension
4{
5 using WixToolset.Data;
6
7 public static class ExampleTupleDefinitions
8 {
9 public const string ExampleName = "Example";
10
11 public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition(
12 ExampleName,
13 new[]
14 {
15 new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String),
16 new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String),
17 },
18 typeof(ExampleTuple));
19 }
20}
diff --git a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs
new file mode 100644
index 00000000..f00a5102
--- /dev/null
+++ b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.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
3namespace Example.Extension
4{
5 using WixToolset.Data;
6 using WixToolset.Data.WindowsInstaller;
7 using WixToolset.Extensibility;
8
9 internal class ExampleWindowsInstallerBackendExtension : BaseWindowsInstallerBackendExtension
10 {
11 public override bool TryAddTupleToOutput(IntermediateTuple tuple, Output output)
12 {
13#if ALTERNATIVE_TO_USING_HELPER
14 switch (tuple.Definition.Name)
15 {
16 case TupleDefinitions.ExampleName:
17 {
18 var table = output.EnsureTable(ExampleTableDefinitions.ExampleTable);
19 var row = table.CreateRow(tuple.SourceLineNumbers);
20 row[0] = tuple[0].AsString();
21 row[1] = tuple[1].AsString();
22 }
23 return true;
24 }
25
26 return false;
27#else
28 return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, ExampleTableDefinitions.All);
29#endif
30 }
31 }
32}