Resolve dynamically the ObjectModel to be used for each new node
Posted: 11 Oct 2021, 15:24
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:
But as my object model types are dynamic I can't just call it that way.
I need something like this:
Could you please guide my in how to resolve dinamically the object Model used in the LinkModelToNode method?
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);
I need something like this:
Code: Select all
NodeId myNodeId = new NodeId("mynewnodename", DefaultNamespaceIndex);
BaseObjectModel myNodeModelType = ResolveObjectModelToBeUsed("nameofthemodeltype");
LinkModelToNode(myNodeId, myNodeModelType, null, null, 0);