| 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.Extensibility |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Xml.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Extensibility.Data; |
| 10 | using WixToolset.Extensibility.Services; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// Base class for creating a compiler extension. |
| 14 | /// </summary> |
| 15 | public abstract class BaseCompilerExtension : ICompilerExtension |
| 16 | { |
| 17 | /// <summary> |
| 18 | /// Context for use by the extension. |
| 19 | /// </summary> |
| 20 | protected ICompileContext Context { get; private set; } |
| 21 | |
| 22 | /// <summary> |
| 23 | /// Messaging for use by the extension. |
| 24 | /// </summary> |
| 25 | protected IMessaging Messaging { get; private set; } |
| 26 | |
| 27 | /// <summary> |
| 28 | /// ParserHelper for use by the extension. |
| 29 | /// </summary> |
| 30 | protected IParseHelper ParseHelper { get; private set; } |
| 31 | |
| 32 | /// <summary> |
| 33 | /// Gets the schema namespace for this extension. |
| 34 | /// </summary> |
| 35 | /// <value>Schema namespace supported by this extension.</value> |
| 36 | public abstract XNamespace Namespace { get; } |
| 37 | |
| 38 | /// <summary> |
| 39 | /// Creates a component key path. |
| 40 | /// </summary> |
| 41 | protected IComponentKeyPath CreateComponentKeyPath() => this.Context.ServiceProvider.GetService<IComponentKeyPath>(); |
| 42 | |
| 43 | /// <summary> |
| 44 | /// Called at the beginning of the compilation of a source file. |
| 45 | /// </summary> |
| 46 | public virtual void PreCompile(ICompileContext context) |
| 47 | { |
| 48 | this.Context = context; |
| 49 | |
| 50 | this.Messaging = context.ServiceProvider.GetService<IMessaging>(); |
| 51 | |
| 52 | this.ParseHelper = context.ServiceProvider.GetService<IParseHelper>(); |
| 53 | } |
| 54 | |
| 55 | /// <summary> |
| 56 | /// See <see cref="ICompilerExtension.ParseAttribute(Intermediate, IntermediateSection, XElement, XAttribute, IDictionary{String, String})"/> |
| 57 | /// </summary> |
| 58 | public virtual void ParseAttribute(Intermediate intermediate, IntermediateSection section, XElement parentElement, XAttribute attribute, IDictionary<string, string> context) |
| 59 | { |
| 60 | this.ParseHelper.UnexpectedAttribute(parentElement, attribute); |
| 61 | } |
| 62 | |
| 63 | /// <summary> |
| 64 | /// See <see cref="ICompilerExtension.ParseElement(Intermediate, IntermediateSection, XElement, XElement, IDictionary{String, String})"/> |
| 65 | /// </summary> |
| 66 | public virtual void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
| 67 | { |
| 68 | this.ParseHelper.UnexpectedElement(parentElement, element); |
| 69 | } |
| 70 | |
| 71 | /// <summary> |
| 72 | /// See <see cref="ICompilerExtension.ParsePossibleKeyPathElement(Intermediate, IntermediateSection, XElement, XElement, IDictionary{String, String})"/> |
| 73 | /// </summary> |
| 74 | public virtual IComponentKeyPath ParsePossibleKeyPathElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
| 75 | { |
| 76 | this.ParseElement(intermediate, section, parentElement, element, context); |
| 77 | return null; |
| 78 | } |
| 79 | |
| 80 | /// <summary> |
| 81 | /// Called at the end of the compilation of a source file. |
| 82 | /// </summary> |
| 83 | public virtual void PostCompile(Intermediate intermediate) |
| 84 | { |
| 85 | } |
| 86 | } |
| 87 | } |