Resolve dynamically the ObjectModel to be used for each new node

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
jramirez-jh
Jr. Member
Jr. Member
Posts: 4
Joined: 14 Jun 2021, 23:39

Resolve dynamically the ObjectModel to be used for each new node

Post by jramirez-jh »

I'm working on a server that needs to create all the available nodes based on a custom xml file. The xml file basically contains two strings, one for the new node name and other for the name of the model object name that needs to be used for that node.

The client provided me the model .XML file exported from the UAModeler and also the Code classes (ModelClasses.cs ModelIdentifiers.cs ModelTypes.cs) but I'm a little lost trying to find a dynamic way to construct the ObjectModel instance for each specfic node.

Looking the sample code provided by the SDK I can see that the most common way is calling the concrete constructor for the required type (commonly located in the ModelClasses.cs) like this:

Code: Select all

NodeId myNodeId = new NodeId("mynewnodename", DefaultNamespaceIndex);
BaseObjectModel myNodeModelType = new UnifiedAutomation.Demo.Model.BoilerModel(); //This can't be done in my scenario
LinkModelToNode(myNodeId, myNodeModelType, null, null, 0);
But as my object model types are dynamic I can't just call it that way.

I need something like this:

Code: Select all

NodeId myNodeId = new NodeId("mynewnodename", DefaultNamespaceIndex);
BaseObjectModel myNodeModelType = ResolveObjectModelToBeUsed("nameofthemodeltype");
LinkModelToNode(myNodeId, myNodeModelType, null, null, 0);
Could you please guide my in how to resolve dinamically the object Model used in the LinkModelToNode method?

Post Reply