diff options
Diffstat (limited to 'src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs')
| -rw-r--r-- | src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs new file mode 100644 index 00000000..4963c941 --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs | |||
| @@ -0,0 +1,77 @@ | |||
| 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 ForTestingUseOnly | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Xml.Linq; | ||
| 8 | using ForTestingUseOnly.Symbols; | ||
| 9 | using WixToolset.Data; | ||
| 10 | using WixToolset.Extensibility; | ||
| 11 | |||
| 12 | /// <summary> | ||
| 13 | /// Extension for doing completely unsupported things in the name of testing. | ||
| 14 | /// </summary> | ||
| 15 | public sealed class ForTestingUseOnlyCompiler : BaseCompilerExtension | ||
| 16 | { | ||
| 17 | public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/fortestinguseonly"; | ||
| 18 | |||
| 19 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) | ||
| 20 | { | ||
| 21 | switch (element.Name.LocalName) | ||
| 22 | { | ||
| 23 | case "ForTestingUseOnlyBundle": | ||
| 24 | this.ParseForTestingUseOnlyBundleElement(intermediate, section, element); | ||
| 25 | break; | ||
| 26 | default: | ||
| 27 | this.ParseHelper.UnexpectedElement(parentElement, element); | ||
| 28 | break; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | private void ParseForTestingUseOnlyBundleElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
| 33 | { | ||
| 34 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
| 35 | string bundleId = null; | ||
| 36 | |||
| 37 | foreach (var attrib in element.Attributes()) | ||
| 38 | { | ||
| 39 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
| 40 | { | ||
| 41 | switch (attrib.Name.LocalName) | ||
| 42 | { | ||
| 43 | case "Id": | ||
| 44 | bundleId = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 45 | break; | ||
| 46 | default: | ||
| 47 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | else | ||
| 52 | { | ||
| 53 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | if (null == bundleId) | ||
| 58 | { | ||
| 59 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | bundleId = Guid.Parse(bundleId).ToString("B").ToUpperInvariant(); | ||
| 64 | } | ||
| 65 | |||
| 66 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | ||
| 67 | |||
| 68 | if (!this.Messaging.EncounteredError) | ||
| 69 | { | ||
| 70 | section.AddSymbol(new ForTestingUseOnlyBundleSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "ForTestingUseOnlyBundle")) | ||
| 71 | { | ||
| 72 | BundleId = bundleId, | ||
| 73 | }); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
