Files
Marc Schier 724757122b Add recycling simulator and plastics/rubber companion packages (#4772)
# Description

Add a generic, company-neutral recycling simulation sample and reusable
plastics/rubber companion-model packages. One durable causal coordinator
and ten separately launched OPC UA process views provide deterministic
material balances, finite buffers, genealogy, utilities, quality
holds/disposition, authenticated controls and crash recovery. Process
views consume committed state instead of running independent
simulations.

Real companion-model equipment instances use DI/Machinery/AMB discovery,
Machine Vision, Pumps/Scales, granulate drying, extrusion, filtration
and pelletizing. Vendor/process extensions remain sample-local.
Connectors and WoT conversion are out of scope. **External
source-contract parity and complete deployment qualification are not
claimed complete.**

The sample and managed tests target **.NET 8, 9 and 10**. The
consolidated [recycling guide](samples/Recycling/README.md) explains the
actual composition, simulation, observation paths and exposed data; the
application-directory README points to that guide.

Typed client member extensions are emitted at build time through the
default-false `ModelSourceGeneratorClientAccessorsOnly` opt-in.
Extrusion uses it for all twelve parts instead of checked-in generated
C# and a Python generator. The shared client runtime retains typed
values, quality, timestamps and streaming behavior.

### Package layout

Six packages contain fourteen models in two model-producing assemblies:

| Specifications | Model | Typed client | Server runtime |
| --- | --- | --- | --- |
| OPC 40083 and OPC 40082-6 | `Opc.Ua.PlasticsRubber` |
`Opc.Ua.PlasticsRubber.Client` | `Opc.Ua.PlasticsRubber.Server` |
| OPC 40084 parts 1–12 | `Opc.Ua.Extrusion` | `Opc.Ua.Extrusion.Client`
| `Opc.Ua.Extrusion.Server` |

NuGet IDs use the `OPCFoundation.NetStandard.` prefix. All six packages
are registered in `.azurepipelines/expected-packages.txt` and the
generated preview-pack solution. Granulate-drying code lives in
`GranulateDrying` folders in the PlasticsRubber projects; extrusion uses
per-part folders. There are no standalone granulate-drying or per-part
extrusion packages. Published model identities and CLR namespaces remain
distinct and unchanged.

The common 1.03 interface is independently authored on the explicitly
MIT-licensed 1.02 implementation basis; the official 1.03 XML is not
redistributed. The other imported models retain their individual MIT
notices. All 42 pinned model, identifier and basis files retain their
manifest-backed bytes, including their staged Git blobs. No formal
companion certification is claimed; the disputed Filter profile is not
advertised.

## Related Issues

No tracking issue is currently linked.

## Checklist

_Put an `x` in the boxes that apply. You can complete these step by step
after opening the PR._

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [x] I have addressed **all** PR feedback received.

Current-head CI and coverage remain pending; the full local `UA.slnx`
test matrix is not claimed complete.
2026-10-15 07:00:58 +02:00

206 lines
11 KiB
C#

/* ========================================================================
* 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.Generic;
using System.Collections.Immutable;
using System.Globalization;
using System.IO;
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NUnit.Framework;
namespace Opc.Ua.SourceGeneration
{
/// <summary>
/// Keeps published nested placeholder declarations without creating concrete placeholder instances.
/// </summary>
[TestFixture]
[Category("SourceGeneration")]
[SetCulture("en-us")]
[SetUICulture("en-us")]
public sealed class NestedPlaceholderDeclarationTests
{
/// <summary>
/// Executes the generated loader and factory, rather than inspecting emitted implementation text.
/// </summary>
[TestCase(11508u)]
[TestCase(11510u)]
public void NestedPlaceholderDeclarationsRetainPublishedIdentifiers(uint modellingRule)
{
const string path = "NestedPlaceholders.NodeSet2.xml";
CSharpCompilation compilation = OptimizationLevel.Release.CreateCompilation()
.AddCode(new Dictionary<string, string>().WithOpcUaGeneratedStack(), LanguageVersion.CSharp13)
.AddSyntaxTrees(CSharpSyntaxTree.ParseText(kProbe, new CSharpParseOptions(LanguageVersion.CSharp13)));
var options = new AnalyzerOptionsProvider(new Dictionary<string, string>
{
["build_property.ModelSourceGeneratorOmitFluentApi"] = "true",
["build_property.ModelSourceGeneratorOmitEventRecords"] = "true",
["build_property.ModelSourceGeneratorOmitObjectTypeProxies"] = "true"
});
options.TextOptions[path] = new Dictionary<string, string>
{
["build_metadata.AdditionalFiles.ModelSourceGeneratorModelUri"] = "urn:test:nested-placeholders",
["build_metadata.AdditionalFiles.ModelSourceGeneratorName"] = "PlaceholderTest",
["build_metadata.AdditionalFiles.ModelSourceGeneratorPrefix"] = "Opc.Ua.PlaceholderTest"
};
GeneratorDriver driver = CSharpGeneratorDriver.Create(new ModelSourceGenerator())
.WithUpdatedParseOptions(new CSharpParseOptions(LanguageVersion.CSharp13))
.WithUpdatedAnalyzerConfigOptions(options)
.AddAdditionalTexts(
[
EmbeddedText.Create(
path,
kNodeSet.Replace(
"__RuleId__",
modellingRule.ToString(CultureInfo.InvariantCulture),
StringComparison.Ordinal))
]);
driver.RunGeneratorsAndUpdateCompilation(
compilation, out Compilation output, out ImmutableArray<Diagnostic> diagnostics);
Assert.That(diagnostics, Is.Empty, string.Join("\n", diagnostics));
using var stream = new MemoryStream();
var emitted = output.Emit(stream);
Assert.That(emitted.Success, Is.True, string.Join("\n", emitted.Diagnostics));
Assembly assembly = Assembly.Load(stream.ToArray());
MethodInfo probe = assembly.GetType("PlaceholderProbe")!.GetMethod("Run")!;
string result = (string)probe.Invoke(null, null)!;
Assert.That(result, Is.EqualTo("declaration=1302/1303;factory=none;predefined=none"));
}
/// <summary>The compiled public-API probe for declaration and concrete-instance behavior.</summary>
private const string kProbe =
"""
using System.Linq;
using Opc.Ua;
using Opc.Ua.PlaceholderTest;
public static class PlaceholderProbe
{
public static string Run()
{
var context = new SystemContext(null);
context.NamespaceUris = new NamespaceTable();
context.NamespaceUris.GetIndexOrAppend("urn:test:application");
ushort index = context.NamespaceUris.GetIndexOrAppend("urn:test:nested-placeholders");
var nodes = new NodeStateCollection();
nodes.AddOpcUaPlaceholderTest(context);
NodeState declaration = nodes.Single(node => node.NodeId == new NodeId(1002, index));
NodeState group = declaration.FindChild(context, new QualifiedName("Stage", index))
?.FindChild(context, new QualifiedName("Group", index));
NodeState placeholder = group?.FindChild(context, new QualifiedName("<Item>", index));
NodeState reading = placeholder?.FindChild(context, new QualifiedName("Reading", index));
string declared = placeholder == null ? "placeholder missing" : "reading missing";
if (placeholder != null && reading != null &&
placeholder.NodeId.TryGetValue(out uint placeholderId) &&
reading.NodeId.TryGetValue(out uint readingId))
{
declared = placeholderId + "/" + readingId;
}
DeviceState instance = context.CreateInstanceOfDeviceType();
NodeState predefined = nodes.Single(node => node.NodeId == new NodeId(2000, index));
return "declaration=" + declared +
";factory=" + GetPlaceholder(context, instance, index) +
";predefined=" + GetPlaceholder(context, predefined, index);
}
private static string GetPlaceholder(ISystemContext context, NodeState instance, ushort index)
{
NodeState instanceGroup = instance.FindChild(context, new QualifiedName("Stage", index))
?.FindChild(context, new QualifiedName("Group", index));
return instanceGroup == null ? "group missing" :
instanceGroup.FindChild(context, new QualifiedName("<Item>", index)) == null
? "none" : "placeholder";
}
}
""";
/// <summary>A small synthetic namespace reproducing the nested GDD declaration shape.</summary>
private const string kNodeSet =
"""
<UANodeSet xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
<NamespaceUris><Uri>urn:test:nested-placeholders</Uri></NamespaceUris>
<Models>
<Model ModelUri="urn:test:nested-placeholders" Version="1.0.0"
PublicationDate="2026-01-01T00:00:00Z">
<RequiredModel ModelUri="http://opcfoundation.org/UA/" />
</Model>
</Models>
<UAObjectType NodeId="ns=1;i=1002" BrowseName="1:DeviceType">
<References>
<Reference ReferenceType="i=45" IsForward="false">i=58</Reference>
<Reference ReferenceType="i=47">ns=1;i=1300</Reference>
</References>
</UAObjectType>
<UAObject NodeId="ns=1;i=1300" ParentNodeId="ns=1;i=1002" BrowseName="1:Stage">
<References>
<Reference ReferenceType="i=47" IsForward="false">ns=1;i=1002</Reference>
<Reference ReferenceType="i=40">i=58</Reference>
<Reference ReferenceType="i=37">i=78</Reference>
<Reference ReferenceType="i=47">ns=1;i=1301</Reference>
</References>
</UAObject>
<UAObject NodeId="ns=1;i=1301" ParentNodeId="ns=1;i=1300" BrowseName="1:Group">
<References>
<Reference ReferenceType="i=47" IsForward="false">ns=1;i=1300</Reference>
<Reference ReferenceType="i=40">i=58</Reference>
<Reference ReferenceType="i=37">i=78</Reference>
<Reference ReferenceType="i=47">ns=1;i=1302</Reference>
</References>
</UAObject>
<UAObject NodeId="ns=1;i=1302" ParentNodeId="ns=1;i=1301"
BrowseName="1:&lt;Item&gt;" SymbolicName="Item">
<References>
<Reference ReferenceType="i=47" IsForward="false">ns=1;i=1301</Reference>
<Reference ReferenceType="i=40">i=58</Reference>
<Reference ReferenceType="i=37">i=__RuleId__</Reference>
<Reference ReferenceType="i=47">ns=1;i=1303</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=1;i=1303" ParentNodeId="ns=1;i=1302"
BrowseName="1:Reading" DataType="i=7">
<References>
<Reference ReferenceType="i=47" IsForward="false">ns=1;i=1302</Reference>
<Reference ReferenceType="i=40">i=63</Reference>
<Reference ReferenceType="i=37">i=78</Reference>
</References>
</UAVariable>
<UAObject NodeId="ns=1;i=2000" BrowseName="1:InstalledDevice">
<References>
<Reference ReferenceType="i=35" IsForward="false">i=85</Reference>
<Reference ReferenceType="i=40">ns=1;i=1002</Reference>
</References>
</UAObject>
</UANodeSet>
""";
}
}