-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[WotCon] Materialize WoT Thing Descriptions into the server address space #4154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcschier
merged 74 commits into
marcschier/wot-15-client
from
marcschier/wot-14-materialization
Aug 5, 2026
Merged
Changes from 23 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
1e9c38c
Merge remote-tracking branch 'origin/marcschier/wot-05-lifecycle' int…
marcschier 61c6544
Merge remote-tracking branch 'origin/marcschier/wot-01-core-types' in…
marcschier a3ff604
Materialize WoT Thing Descriptions into the server address space
marcschier 689e194
Add WoT registry materialization tests
marcschier b2bf36f
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 9c1b75d
Merge branch 'marcschier/wot-13-registry' into marcschier/wot-14-mate…
marcschier 35df526
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier 4ce3d98
Merge branch 'marcschier/wot-12-executors' into marcschier/wot-16-sam…
marcschier 7567c9e
Add the WoT Connectivity samples and complete the documentation
marcschier 5c0006b
Add the remaining WoT binding and aggregation tests
marcschier 1018d78
Cover the DI transfer service binding extensions
marcschier 45689f9
Merge branch 'marcschier/wot-13-registry' into marcschier/wot-14-mate…
marcschier 22f7486
Merge branch 'marcschier/wot-05-lifecycle' into marcschier/wot-14-mat…
marcschier 15aedb2
Merge branch 'marcschier/wot-01-core-types' into marcschier/wot-14-ma…
marcschier 588799c
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier 0845948
Merge branch 'marcschier/wot-15-client' into marcschier/wot-16-samples
marcschier 95bead1
Merge branch 'marcschier/wot-12-executors' into marcschier/wot-16-sam…
marcschier 7a2074e
Merge branch 'marcschier/wot-13-registry' into marcschier/wot-14-mate…
marcschier 507f750
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier cd84294
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier 777e0a8
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier 9e5c9c5
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier 1387294
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier 9bce9c4
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier cd61d63
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier b3f594d
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier ce7dc6f
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier b9ddcb1
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier cdc7064
Merge branch 'marcschier/wot-15-client' into marcschier/wot-14-materi…
marcschier 30d4259
Merge branch 'marcschier/wot-14-materialization' into marcschier/wot-…
marcschier 36c3389
Address WoT materialization review feedback
marcschier 3966144
Address WoT samples review feedback
marcschier f0a69ad
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 182d905
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 01d58cb
Allow loopback endpoints in the aggregation sample
marcschier 237730a
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier eaa7081
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 571eaf4
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 598644f
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier eca062a
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 27ba9cd
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier bb60d87
Align the new WoT documentation links
marcschier 7fc33ad
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 478110f
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 7498344
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier f093746
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 54a6f73
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 7b00194
Treat the registry management minimum security mode as a floor
marcschier 4fc98de
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 7f5cca0
Keep WoT materialization dry runs side-effect free
marcschier 66fe980
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 5a1aca1
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 7c24898
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 76498d8
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier c63d712
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier a3eae58
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier a238381
Fix WoT materialization shutdown ordering
marcschier 9edb995
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 98a5070
Skip projection lifecycle removal during shutdown
marcschier b139d1a
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier ab8c175
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier f1993c9
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 33c2900
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 0377e13
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier 3d6b808
Pass an explicit caller context to the NodeManager lifecycle
marcschier 39f5042
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier cd5b72c
Pass an explicit caller context in the WoT live server tests
marcschier cb6d517
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 0726236
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier a3cb074
Restore WoT asset registry bridge (#4171)
marcschier 6d7bd53
Merge remote-tracking branch 'origin/marcschier/wot-15-client' into m…
marcschier 58f0f9f
Merge remote-tracking branch 'origin/marcschier/wot-14-materializatio…
marcschier e41c0e3
Merge remote-tracking branch 'origin/marcschier/wot-16-samples' into …
marcschier 39f655f
[WotCon] Add the WoT Connectivity samples and complete the documentat…
marcschier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
src/Opc.Ua.WotCon.Server/Hosting/OpcUaWotRegistryServerBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| /* ======================================================================== | ||
| * Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved. | ||
| * | ||
| * OPC Foundation MIT License 1.00 | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person | ||
| * obtaining a copy of this software and associated documentation | ||
| * files (the "Software"), to deal in the Software without | ||
| * restriction, including without limitation the rights to use, | ||
| * copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the | ||
| * Software is furnished to do so, subject to the following | ||
| * conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be | ||
| * included in all copies or substantial portions of the Software. | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| * OTHER DEALINGS IN THE SOFTWARE. | ||
| * | ||
| * The complete license agreement can be found here: | ||
| * http://opcfoundation.org/License/MIT/1.00/ | ||
| * ======================================================================*/ | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
| using Microsoft.Extensions.Options; | ||
| using Opc.Ua; | ||
| using Opc.Ua.Server; | ||
| using Opc.Ua.Server.Hosting; | ||
| using Opc.Ua.Wot; | ||
| using Opc.Ua.WotCon.Bindings; | ||
| using Opc.Ua.WotCon.Server; | ||
| using Opc.Ua.WotCon.Server.Materialization; | ||
| using Opc.Ua.WotCon.Server.Registry; | ||
| using Opc.Ua.XRegistry.Server; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection | ||
| { | ||
| /// <summary> | ||
| /// <see cref="IOpcUaBuilder"/> extensions that host the WoT Connectivity 1.1 | ||
| /// registry (<c>WoTRegistry</c>) on the OPC UA server registered via | ||
| /// <c>.AddServer(...)</c>. The registry service, materialization coordinator, | ||
| /// binder registry and projection host are registered as singletons; the | ||
| /// stable <see cref="WotRegistryNodeManager"/> is attached at server start. | ||
| /// </summary> | ||
| public static class OpcUaWotRegistryServerBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Default configuration section for the registry options. | ||
| /// </summary> | ||
| public const string DefaultConfigurationSection = "OpcUa:WotConRegistry:Server"; | ||
|
|
||
| /// <summary> | ||
| /// Registers the WoT Connectivity 1.1 registry NodeManager configured by | ||
| /// <paramref name="configure"/>. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| public static IOpcUaBuilder AddWotRegistryServer( | ||
| this IOpcUaBuilder builder, | ||
| Action<WotRegistryServerOptions>? configure = null) | ||
| { | ||
| if (builder is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(builder)); | ||
| } | ||
| if (configure is not null) | ||
| { | ||
| builder.Services.AddOptions<WotRegistryServerOptions>().Configure(configure); | ||
| } | ||
| else | ||
| { | ||
| builder.Services.AddOptions<WotRegistryServerOptions>(); | ||
| } | ||
| RegisterCommonServices(builder.Services); | ||
| return builder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers the WoT Connectivity 1.1 registry NodeManager with options | ||
| /// bound from the supplied configuration section. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| public static IOpcUaBuilder AddWotRegistryServer( | ||
| this IOpcUaBuilder builder, | ||
| IConfiguration configuration) | ||
| { | ||
| if (builder is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(builder)); | ||
| } | ||
| if (configuration is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(configuration)); | ||
| } | ||
| return builder.AddWotRegistryServer( | ||
| configuration.GetSection(DefaultConfigurationSection)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Registers the WoT Connectivity 1.1 registry NodeManager with options | ||
| /// bound from the supplied configuration section. | ||
| /// </summary> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| /// <exception cref="ArgumentNullException"></exception> | ||
| public static IOpcUaBuilder AddWotRegistryServer( | ||
| this IOpcUaBuilder builder, | ||
| IConfigurationSection section) | ||
| { | ||
| if (builder is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(builder)); | ||
| } | ||
| if (section is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(section)); | ||
| } | ||
| builder.Services.AddOptions<WotRegistryServerOptions>().Bind(section); | ||
| RegisterCommonServices(builder.Services); | ||
| return builder; | ||
| } | ||
|
|
||
| private static void RegisterCommonServices(IServiceCollection services) | ||
| { | ||
| services.TryAddSingleton(sp => | ||
| sp.GetRequiredService<IOptions<WotRegistryServerOptions>>().Value | ||
| ?? new WotRegistryServerOptions()); | ||
|
|
||
| services.EnsureWotBinderRegistry(); | ||
|
|
||
| services.TryAddSingleton<IWotTargetVariableResolver>(new WotTargetVariableResolver()); | ||
|
|
||
| services.TryAddSingleton<IWotProjectionBindingRuntimeFactory>(sp => | ||
| new WotProjectionBindingRuntimeFactory( | ||
| sp.GetRequiredService<IWotBindingChannelFactory>(), | ||
| sp.GetRequiredService<IWotTargetVariableResolver>())); | ||
|
|
||
| services.TryAddSingleton<IWotRegistryService>(sp => | ||
| { | ||
| WotRegistryServerOptions options = | ||
| sp.GetRequiredService<WotRegistryServerOptions>(); | ||
| // A store registered in DI wins over one set on the options, so a deployment can | ||
| // supply a shared store the same way the xRegistry server does. | ||
| IXRegistryResourceStore? resourceStore = | ||
| sp.GetService<IXRegistryResourceStore>() ?? options.ResourceStore; | ||
| IWotRegistryStore store = string.IsNullOrEmpty(options.StorageFolder) | ||
| ? new InMemoryWotRegistryStore() | ||
| : resourceStore is null | ||
| ? new FileWotRegistryStore(options.StorageFolder!) | ||
| : new FileWotRegistryStore(options.StorageFolder!, resourceStore); | ||
| return new WotRegistryService(store, options.Bounds); | ||
| }); | ||
|
|
||
| services.TryAddSingleton<IWotProjectionHost>(sp => | ||
| new LifecycleWotProjectionHost( | ||
| sp.GetRequiredService<INodeManagerLifecycle>(), | ||
| sp.GetRequiredService<IWotProjectionBindingRuntimeFactory>())); | ||
|
|
||
| services.TryAddSingleton(sp => | ||
| { | ||
| WotRegistryServerOptions options = | ||
| sp.GetRequiredService<WotRegistryServerOptions>(); | ||
| var converterOptions = new WotNodeSetConverterOptions | ||
| { | ||
| MaxJsonDocumentSize = options.Bounds.MaxDocumentBytes, | ||
| MaxResolverDocumentBytes = options.Bounds.MaxDocumentBytes | ||
| }; | ||
| return new WotMaterializationCoordinator( | ||
| sp.GetRequiredService<IWotRegistryService>(), | ||
| sp.GetRequiredService<IWotProjectionHost>(), | ||
| sp.GetRequiredService<IWotBinderRegistry>(), | ||
| converterOptions, | ||
| // Both seams are optional: a deployment that registers neither gets exactly | ||
| // the previous behaviour. Registering an IWotDocumentConverter replaces the | ||
| // Thing Description to NodeSet conversion; registering IWotNodeSetContributor | ||
| // instances adds nodes (typically controller-specific StructureType DataTypes) | ||
| // to the converted NodeSet before it is materialized. | ||
| sp.GetService<IWotDocumentConverter>(), | ||
| sp.GetServices<IWotNodeSetContributor>(), | ||
| sp.GetService<IWotNodeSetResolver>()); | ||
| }); | ||
|
|
||
| services.TryAddSingleton(sp => | ||
| new WotRegistryNodeManagerFactory( | ||
| sp.GetRequiredService<WotRegistryServerOptions>(), | ||
| sp.GetRequiredService<IWotRegistryService>(), | ||
| sp.GetRequiredService<WotMaterializationCoordinator>())); | ||
|
|
||
| services.AddSingleton(sp => | ||
| new OpcUaServerNodeManagerRegistration( | ||
| sp.GetRequiredService<WotRegistryNodeManagerFactory>())); | ||
|
|
||
| services.AddOpcUa(); | ||
| } | ||
| } | ||
| } | ||
180 changes: 180 additions & 0 deletions
180
src/Opc.Ua.WotCon.Server/Materialization/IWotDocumentConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /* ======================================================================== | ||
| * Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved. | ||
| * | ||
| * OPC Foundation MIT License 1.00 | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person | ||
| * obtaining a copy of this software and associated documentation | ||
| * files (the "Software"), to deal in the Software without | ||
| * restriction, including without limitation the rights to use, | ||
| * copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the | ||
| * Software is furnished to do so, subject to the following | ||
| * conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be | ||
| * included in all copies or substantial portions of the Software. | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| * OTHER DEALINGS IN THE SOFTWARE. | ||
| * | ||
| * The complete license agreement can be found here: | ||
| * http://opcfoundation.org/License/MIT/1.00/ | ||
| * ======================================================================*/ | ||
|
|
||
| using System; | ||
| using System.Collections.Immutable; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Opc.Ua.Export; | ||
| using Opc.Ua.Wot; | ||
| using Opc.Ua.WotCon.Server.Registry; | ||
|
|
||
| namespace Opc.Ua.WotCon.Server.Materialization | ||
| { | ||
| /// <summary> | ||
| /// The result of converting one registry document to a NodeSet2 model. | ||
| /// </summary> | ||
| public sealed class WotConversionOutput | ||
| { | ||
| /// <summary> | ||
| /// Initializes a successful or failed conversion output. | ||
| /// </summary> | ||
| public WotConversionOutput( | ||
| UANodeSet? nodeSet, | ||
| ImmutableArray<string> errors, | ||
| ExpandedNodeId rootNodeId = default) | ||
| { | ||
| NodeSet = nodeSet; | ||
| Errors = errors.IsDefault ? [] : errors; | ||
| RootNodeId = rootNodeId; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the produced NodeSet2, or <c>null</c> on failure. | ||
| /// </summary> | ||
| public UANodeSet? NodeSet { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the conversion error messages. | ||
| /// </summary> | ||
| public ImmutableArray<string> Errors { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the root node of the projection (the type a Thing Model | ||
| /// materializes or the top-level instance a Thing Description projects), | ||
| /// as an absolute <see cref="ExpandedNodeId"/> whose namespace URI is | ||
| /// resolved from the produced NodeSet, or <c>ExpandedNodeId.Null</c> | ||
| /// when the document has no identifiable root. | ||
| /// </summary> | ||
| public ExpandedNodeId RootNodeId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets whether the conversion succeeded. | ||
| /// </summary> | ||
| public bool Succeeded => NodeSet is not null && Errors.IsEmpty; | ||
|
|
||
| /// <summary> | ||
| /// Creates a successful output. | ||
| /// </summary> | ||
| public static WotConversionOutput Success(UANodeSet nodeSet) | ||
| { | ||
| return new WotConversionOutput( | ||
| nodeSet, | ||
| [], | ||
| WotNodeSetConverter.TrySelectProjectionRoot(nodeSet)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a failed output. | ||
| /// </summary> | ||
| public static WotConversionOutput Failure(params string[] errors) | ||
| { | ||
| return new WotConversionOutput(null, [.. errors]); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a stored registry document to a NodeSet2 model. The default | ||
| /// implementation delegates to <see cref="WotNodeSetConverter"/> and resolves | ||
| /// TM references from the registry snapshot; a test double can substitute a | ||
| /// deterministic conversion. | ||
| /// </summary> | ||
| public interface IWotDocumentConverter | ||
| { | ||
| /// <summary> | ||
| /// Converts a resource's default document to a NodeSet2 model. | ||
| /// </summary> | ||
| ValueTask<WotConversionOutput> ConvertAsync( | ||
| WotResource resource, | ||
| ReadOnlyMemory<byte> content, | ||
| WotRegistrySnapshot snapshot, | ||
| CancellationToken cancellationToken); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The production converter over <see cref="WotNodeSetConverter"/>. | ||
| /// </summary> | ||
| public sealed class WotNodeSetDocumentConverter : IWotDocumentConverter | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new converter with the supplied options. | ||
| /// </summary> | ||
| public WotNodeSetDocumentConverter(WotNodeSetConverterOptions? options = null) | ||
| { | ||
| m_options = options ?? new WotNodeSetConverterOptions(); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public async ValueTask<WotConversionOutput> ConvertAsync( | ||
| WotResource resource, | ||
| ReadOnlyMemory<byte> content, | ||
| WotRegistrySnapshot snapshot, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| using var document = WotDocument.Parse(content, m_options); | ||
| var resolver = new SnapshotThingResolver(snapshot); | ||
| // One resolution context per top-level conversion, seeded from | ||
| // the configured converter options, so depth/document/byte | ||
| // bounds and cycle detection apply across every link resolved | ||
| // while converting this resource. | ||
| var resolution = new WotResolutionContext(m_options.ToResolverOptions()); | ||
| WotConversionResult<UANodeSet> result = await WotNodeSetConverter.ToNodeSetResultAsync( | ||
| document, m_options, resolver, resolution, cancellationToken).ConfigureAwait(false); | ||
| ImmutableArray<string>.Builder errors = ImmutableArray.CreateBuilder<string>(); | ||
| foreach (WotDiagnostic diagnostic in result.Diagnostics) | ||
| { | ||
| if (diagnostic.Severity == WotDiagnosticSeverity.Error) | ||
| { | ||
| errors.Add(diagnostic.ToString()); | ||
| } | ||
| } | ||
| if (result.Value is null && errors.Count == 0) | ||
| { | ||
| errors.Add("The document could not be converted to a NodeSet."); | ||
| } | ||
| if (errors.Count != 0 || result.Value is null) | ||
| { | ||
| return new WotConversionOutput(null, errors.ToImmutable()); | ||
| } | ||
| return new WotConversionOutput( | ||
| result.Value, | ||
| [], | ||
| WotNodeSetConverter.TrySelectProjectionRoot(result.Value)); | ||
| } | ||
| catch (Exception ex) when (ex is System.Text.Json.JsonException or FormatException) | ||
| { | ||
| return WotConversionOutput.Failure(ex.Message); | ||
| } | ||
| } | ||
|
|
||
| private readonly WotNodeSetConverterOptions m_options; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.