From 0baf6e26ec7ab2ff0b6ad36e9d44f3d68819b5d6 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 27 Mar 2020 13:54:56 +1000 Subject: Add ability for extensions to create custom bundle searches. This required creating BundleExtensionData.xml. --- .../Example.Extension/ExampleCompilerExtension.cs | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'src/test/Example.Extension/ExampleCompilerExtension.cs') diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs index 5efb428f..543b4165 100644 --- a/src/test/Example.Extension/ExampleCompilerExtension.cs +++ b/src/test/Example.Extension/ExampleCompilerExtension.cs @@ -11,6 +11,7 @@ namespace Example.Extension internal class ExampleCompilerExtension : BaseCompilerExtension { public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs"; + public string BundleExtensionId => "ExampleBundleExtension"; public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) { @@ -18,6 +19,20 @@ namespace Example.Extension switch (parentElement.Name.LocalName) { + case "Bundle": + case "Fragment": + switch (element.Name.LocalName) + { + case "ExampleSearch": + this.ParseExampleSearchElement(intermediate, section, element); + processed = true; + break; + case "ExampleSearchRef": + this.ParseExampleSearchRefElement(intermediate, section, element); + processed = true; + break; + } + break; case "Component": switch (element.Name.LocalName) { @@ -77,5 +92,94 @@ namespace Example.Extension tuple.Set(1, value); } } + + private void ParseExampleSearchElement(Intermediate intermediate, IntermediateSection section, XElement element) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + Identifier id = null; + string searchFor = null; + string variable = null; + string condition = null; + string after = null; + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + case "Variable": + variable = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "Condition": + condition = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "After": + after = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + case "SearchFor": + searchFor = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseAttribute(intermediate, section, element, attrib, null); + } + } + + if (null == id) + { + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); + } + + if (!this.Messaging.EncounteredError) + { + this.ParseHelper.CreateWixSearchTuple(section, sourceLineNumbers, element.Name.LocalName, id, variable, condition, after, this.BundleExtensionId); + } + + if (!this.Messaging.EncounteredError) + { + + var tuple = new ExampleSearchTuple(sourceLineNumbers, id); + section.Tuples.Add(tuple); + tuple.SearchFor = searchFor; + } + } + + private void ParseExampleSearchRefElement(Intermediate intermediate, IntermediateSection section, XElement element) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + var refId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "ExampleSearch", refId); + break; + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); + } + } + + this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); + } } } -- cgit v1.2.3-55-g6feb