diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-03-27 13:54:56 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-03-30 21:30:04 +1000 |
| commit | 0baf6e26ec7ab2ff0b6ad36e9d44f3d68819b5d6 (patch) | |
| tree | 1ef577d0246b662f4a8bda0ed935e987f03562a0 /src/test/Example.Extension/ExampleCompilerExtension.cs | |
| parent | afbc6889c73d58136cb8851858ca3c17f41dc2c5 (diff) | |
| download | wix-0baf6e26ec7ab2ff0b6ad36e9d44f3d68819b5d6.tar.gz wix-0baf6e26ec7ab2ff0b6ad36e9d44f3d68819b5d6.tar.bz2 wix-0baf6e26ec7ab2ff0b6ad36e9d44f3d68819b5d6.zip | |
Add ability for extensions to create custom bundle searches.
This required creating BundleExtensionData.xml.
Diffstat (limited to 'src/test/Example.Extension/ExampleCompilerExtension.cs')
| -rw-r--r-- | src/test/Example.Extension/ExampleCompilerExtension.cs | 104 |
1 files changed, 104 insertions, 0 deletions
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 | |||
| 11 | internal class ExampleCompilerExtension : BaseCompilerExtension | 11 | internal class ExampleCompilerExtension : BaseCompilerExtension |
| 12 | { | 12 | { |
| 13 | public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs"; | 13 | public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs"; |
| 14 | public string BundleExtensionId => "ExampleBundleExtension"; | ||
| 14 | 15 | ||
| 15 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) | 16 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
| 16 | { | 17 | { |
| @@ -18,6 +19,20 @@ namespace Example.Extension | |||
| 18 | 19 | ||
| 19 | switch (parentElement.Name.LocalName) | 20 | switch (parentElement.Name.LocalName) |
| 20 | { | 21 | { |
| 22 | case "Bundle": | ||
| 23 | case "Fragment": | ||
| 24 | switch (element.Name.LocalName) | ||
| 25 | { | ||
| 26 | case "ExampleSearch": | ||
| 27 | this.ParseExampleSearchElement(intermediate, section, element); | ||
| 28 | processed = true; | ||
| 29 | break; | ||
| 30 | case "ExampleSearchRef": | ||
| 31 | this.ParseExampleSearchRefElement(intermediate, section, element); | ||
| 32 | processed = true; | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | break; | ||
| 21 | case "Component": | 36 | case "Component": |
| 22 | switch (element.Name.LocalName) | 37 | switch (element.Name.LocalName) |
| 23 | { | 38 | { |
| @@ -77,5 +92,94 @@ namespace Example.Extension | |||
| 77 | tuple.Set(1, value); | 92 | tuple.Set(1, value); |
| 78 | } | 93 | } |
| 79 | } | 94 | } |
| 95 | |||
| 96 | private void ParseExampleSearchElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
| 97 | { | ||
| 98 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
| 99 | Identifier id = null; | ||
| 100 | string searchFor = null; | ||
| 101 | string variable = null; | ||
| 102 | string condition = null; | ||
| 103 | string after = null; | ||
| 104 | |||
| 105 | foreach (var attrib in element.Attributes()) | ||
| 106 | { | ||
| 107 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
| 108 | { | ||
| 109 | switch (attrib.Name.LocalName) | ||
| 110 | { | ||
| 111 | case "Id": | ||
| 112 | id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
| 113 | break; | ||
| 114 | case "Variable": | ||
| 115 | variable = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 116 | break; | ||
| 117 | case "Condition": | ||
| 118 | condition = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 119 | break; | ||
| 120 | case "After": | ||
| 121 | after = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 122 | break; | ||
| 123 | case "SearchFor": | ||
| 124 | searchFor = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 125 | break; | ||
| 126 | |||
| 127 | default: | ||
| 128 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
| 129 | break; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | else | ||
| 133 | { | ||
| 134 | this.ParseAttribute(intermediate, section, element, attrib, null); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | if (null == id) | ||
| 139 | { | ||
| 140 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); | ||
| 141 | } | ||
| 142 | |||
| 143 | if (!this.Messaging.EncounteredError) | ||
| 144 | { | ||
| 145 | this.ParseHelper.CreateWixSearchTuple(section, sourceLineNumbers, element.Name.LocalName, id, variable, condition, after, this.BundleExtensionId); | ||
| 146 | } | ||
| 147 | |||
| 148 | if (!this.Messaging.EncounteredError) | ||
| 149 | { | ||
| 150 | |||
| 151 | var tuple = new ExampleSearchTuple(sourceLineNumbers, id); | ||
| 152 | section.Tuples.Add(tuple); | ||
| 153 | tuple.SearchFor = searchFor; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | private void ParseExampleSearchRefElement(Intermediate intermediate, IntermediateSection section, XElement element) | ||
| 158 | { | ||
| 159 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | ||
| 160 | |||
| 161 | foreach (var attrib in element.Attributes()) | ||
| 162 | { | ||
| 163 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | ||
| 164 | { | ||
| 165 | switch (attrib.Name.LocalName) | ||
| 166 | { | ||
| 167 | case "Id": | ||
| 168 | var refId = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | ||
| 169 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "ExampleSearch", refId); | ||
| 170 | break; | ||
| 171 | default: | ||
| 172 | this.ParseHelper.UnexpectedAttribute(element, attrib); | ||
| 173 | break; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | else | ||
| 177 | { | ||
| 178 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | ||
| 183 | } | ||
| 80 | } | 184 | } |
| 81 | } | 185 | } |
