Class GmlPortrayalCatalogueBase
- Namespace
- EncDotNet.S100.Portrayals
- Assembly
- EncDotNet.S100.Portrayals.dll
Base class for XSLT-based GML portrayal catalogues. Provides all the
shared infrastructure — palette loading, rule discovery, XSLT compilation
with caching, symbol/line-style/area-fill asset loading, and the XML
resolver for xsl:include resolution.
public abstract class GmlPortrayalCatalogueBase : IVectorPortrayalCatalogue, IPortrayalCatalogue, IXsltRuleSource, ILuaRuleSource, IPortrayalAssetSource
- Inheritance
-
GmlPortrayalCatalogueBase
- Implements
- Derived
- Inherited Members
Remarks
Subclasses typically only need to supply Spec and, where necessary, override CreateXmlResolver(IReadOnlyDictionary<string, byte[]>) (for specs whose XSLT includes reference unregistered sub-templates) or GetCompiledRuleAsync(string, CancellationToken) (for specs that inject an adapter rule).
Constructors
GmlPortrayalCatalogueBase(PortrayalCatalogueProvider)
Initializes a new GmlPortrayalCatalogueBase backed by the given provider.
protected GmlPortrayalCatalogueBase(PortrayalCatalogueProvider provider)
Parameters
providerPortrayalCatalogueProvider
Properties
ActivePalette
Gets the currently active color palette.
public ColorPalette ActivePalette { get; }
Property Value
CatalogueRef
The identity (name + version) of the underlying portrayal catalogue XML, when populated. Used to surface mismatches between the dataset's declared Spec edition and the catalogue version actually resolved for it.
public CatalogueRef? CatalogueRef { get; }
Property Value
ContextParameters
GML portrayal catalogues declare no Lua context parameters.
public IReadOnlyList<LuaContextParameter> ContextParameters { get; }
Property Value
DisplayModes
Tracks the active S-100 Part 9 §11.7 display mode.
public DisplayModeController DisplayModes { get; }
Property Value
DisplayPlanes
Controls which S-100 Part 9 §11.6 display planes are visible.
public DisplayPlaneController DisplayPlanes { get; }
Property Value
Edition
Gets the edition of the portrayal catalogue.
public string Edition { get; }
Property Value
Provider
Gets the underlying portrayal catalogue provider.
protected PortrayalCatalogueProvider Provider { get; }
Property Value
Rules
Gets the ordered list of portrayal rules.
public IReadOnlyList<PortrayalRule> Rules { get; }
Property Value
Spec
The product specification (name + edition) this catalogue targets.
public abstract SpecRef Spec { get; }
Property Value
ViewingGroups
Gets the controller for viewing group visibility.
public ViewingGroupController ViewingGroups { get; }
Property Value
Methods
BuildRules()
Builds the list of portrayal rules from the catalogue's rule files. Override to change rule selection (e.g. restrict to a single named rule).
protected virtual IReadOnlyList<PortrayalRule> BuildRules()
Returns
CacheCompiledRule(string, XslCompiledTransform)
Caches a compiled transform under the given rule name. Useful for subclasses that load adapter rules from embedded resources.
protected void CacheCompiledRule(string ruleName, XslCompiledTransform transform)
Parameters
ruleNamestringtransformXslCompiledTransform
CreateXmlResolver(IReadOnlyDictionary<string, byte[]>)
Creates an XmlResolver used to resolve
xsl:include/xsl:import URIs during XSLT compilation.
protected virtual XmlResolver CreateXmlResolver(IReadOnlyDictionary<string, byte[]> registeredBytes)
Parameters
registeredBytesIReadOnlyDictionary<string, byte[]>
Returns
Remarks
The default implementation resolves filenames against the pre-fetched rule-file bytes dictionary. Override to add fallback resolution strategies (e.g. FetchRuleAsync(string, CancellationToken) for specs whose sub-templates are not registered as rule files).
GetAreaFillAsync(string, CancellationToken)
Returns the area fill with the given name, loading and caching it on first access.
public ValueTask<AreaFill> GetAreaFillAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringcancellationTokenCancellationToken
Returns
Exceptions
- PortrayalAssetNotFoundException
No such area fill in the catalogue.
GetCompiledRuleAsync(string, CancellationToken)
Returns the compiled XSLT transform for the given rule name, loading and caching it on first access. Override to intercept specific rules (e.g. inject an adapter transform).
public virtual ValueTask<XslCompiledTransform> GetCompiledRuleAsync(string ruleName, CancellationToken cancellationToken = default)
Parameters
ruleNamestringThe rule identifier.
cancellationTokenCancellationTokenCancellation token.
Returns
- ValueTask<XslCompiledTransform>
The compiled XSLT transform.
Exceptions
- PortrayalAssetNotFoundException
No such rule in the catalogue.
GetLineStyleAsync(string, CancellationToken)
Returns the line style with the given name, loading and caching it on first access.
public ValueTask<LineStyle> GetLineStyleAsync(string name, CancellationToken cancellationToken = default)
Parameters
namestringcancellationTokenCancellationToken
Returns
Exceptions
- PortrayalAssetNotFoundException
No such line style in the catalogue.
GetLuaSourceAsync(string, CancellationToken)
GML portrayal catalogues ship no Lua rules, so this always returns null (honouring the module loader's "missing module → null" contract).
public ValueTask<string?> GetLuaSourceAsync(string fileName, CancellationToken cancellationToken = default)
Parameters
fileNamestringcancellationTokenCancellationToken
Returns
GetLuaSourceNamesAsync(CancellationToken)
GML portrayal catalogues use XSLT only and ship no Lua rules, so this always returns an empty list.
public ValueTask<IReadOnlyList<string>> GetLuaSourceNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
GetSymbolAsync(string, CancellationToken)
Returns the SVG symbol with the given name, loading and caching it on first access.
public ValueTask<SvgSymbol> GetSymbolAsync(string symbolName, CancellationToken cancellationToken = default)
Parameters
symbolNamestringcancellationTokenCancellationToken
Returns
Exceptions
- PortrayalAssetNotFoundException
No such symbol in the catalogue.
LoadAdapterXsltAsync(Stream, string, CancellationToken)
Compiles an adapter stylesheet that is not part of the catalogue
against the catalogue's rule files, so the adapter can
xsl:import or xsl:include them by file name (for example
<xsl:import href="main.xsl"/>). Lets a subclass wrap an
upstream rule without editing the bundled catalogue.
protected Task<XslCompiledTransform> LoadAdapterXsltAsync(Stream adapter, string adapterFileName, CancellationToken cancellationToken)
Parameters
adapterStreamThe adapter stylesheet.
adapterFileNamestringThe adapter's file name, used as its base URI; it must not collide with a catalogue rule file name.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<XslCompiledTransform>
The compiled adapter.
LoadPalettesAsync(Dictionary<PaletteType, ColorPalette>, CancellationToken)
Loads colour palettes from the catalogue's colour profiles. Override to change the palette loading strategy (e.g. skip the multi-palette-in-one-file fallback for specs that don't use it).
protected virtual Task LoadPalettesAsync(Dictionary<PaletteType, ColorPalette> palettes, CancellationToken cancellationToken)
Parameters
palettesDictionary<PaletteType, ColorPalette>cancellationTokenCancellationToken
Returns
LoadXsltRuleAsync(RuleFile, CancellationToken)
Loads and compiles an XSLT rule file with telemetry.
protected Task<XslCompiledTransform> LoadXsltRuleAsync(RuleFile ruleFile, CancellationToken cancellationToken)
Parameters
ruleFileRuleFilecancellationTokenCancellationToken
Returns
Remarks
Pre-fetches every registered rule file's bytes into a memory dict before invoking Load(XmlReader, XsltSettings, XmlResolver), because GetEntity(Uri, string, Type) is a synchronous .NET API contract during XSLT compile and we cannot await inside it. The pre-fetch is bounded to the (small) set of declared rule files; GmlPortrayalCatalogueBase.FetchRuleFallbackXmlResolver handles the unregistered-include case via a documented sync bridge.
SwitchPaletteAsync(PaletteType, CancellationToken)
Switches the active colour palette to type.
public ValueTask SwitchPaletteAsync(PaletteType type, CancellationToken cancellationToken = default)
Parameters
typePaletteTypeThe palette mood (Day, Dusk, or Night).
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Asynchronous because catalogues that load palettes lazily from
IAssetSource may need to fetch the colour profile
XML on first access. Cached implementations complete
synchronously through the ValueTask fast path.
When the catalogue has no palette for type,
implementations keep a usable palette active (the current one, or
Day) rather than failing. Coverage catalogues also use this call to
pre-load the assets their synchronous resolve methods need, so it must
be awaited before those are called (see
SwitchPaletteAsync(PaletteType, CancellationToken)).