How can I implement the following structure on code?

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

Moderator: uasdknet

Post Reply
NovNJ
Jr. Member
Jr. Member
Posts: 1
Joined: 06 Nov 2018, 01:28

How can I implement the following structure on code?

Post by NovNJ »

Hey Support Team ,

Q1.How can I implement the following structure on code?

Code: Select all

Objects
│
├─SampleA          (ns=4;s="A")
│  └─Items        (ns=4;s="A1")
│      ├─ItemA    (ns=4;s="A1A")
│      │  └─Size (ns=4;s="A1A01")
│      └─ItemB    (ns=4;s="A1B")
│          └─Size (ns=4;s="A1B01")
│
└─SampleB          (ns=4;s="B")
    └─Items        (ns=4;s="B1")
        └─ItemA    (ns=4;s="B1A")
            └─Size (ns=4;s="B1A01")
------------
I am creating it in the following environment.

Code: Select all

[NameSpace Index]
TypeNamespaceIndex=3
InstanceNamespaceIndex=4

["Types" definition]
Types
└─ObjectTypes
   └─BaseObjectType
        │
        ├─ItemType   (ns=3;i=1)
        │  └─Size   (ns=3;i=2)
        │
        ├─ItemsType  (ns=3;i=3)
        │  └─Item   (ns=3;i=4, ItemType, ModellingRule=OptionalPlaceholder)
        │
        └─SampleType (ns=3;i=5)
            └─Items  (ns=3;i=6, ItemsType, ModellingRule=Optional)

The following code was executed in the program (Sample B is omitted))

Code: Select all

// create SampleA
var settings = new CreateObjectSettings()
{
    ParentNodeId = ObjectIds.ObjectsFolder,
    ReferenceTypeId = ReferenceTypeIds.Organizes,
    RequestedNodeId = new NodeId("A", InstanceNamespaceIndex),
    BrowseName = new QualifiedName("SampleA", InstanceNamespaceIndex),
    TypeDefinitionId = new NodeId(5u, TypeNamespaceIndex),
    OptionalBrowsePaths = new string[] { $"{TypeNamespaceIndex}:Items", },  // I do not know how to specify NodeId of items.
};

var sampleA = CreateObject(Server.DefaultRequestContext, settings);

var items = FindMemoryNode(sampleA.NodeId, null, false, new QualifiedName("Items", TypeNamespaceIndex));
if (items.ParentNodeId == null)
{
    Console.WriteLine("ParentNodeId is null.");
    //itema.ParentNodeId = sampleA.NodeId;
}

// create ItemA
settings = new CreateObjectSettings()
{
    ParentNodeId = items.NodeId,
    ReferenceTypeId = ReferenceTypeIds.HasComponent,
    RequestedNodeId = new NodeId("A1A", InstanceNamespaceIndex),
    BrowseName = new QualifiedName("ItemA", InstanceNamespaceIndex),
    TypeDefinitionId = new NodeId(1u, TypeNamespaceIndex),
};

var itema = CreateObject(Server.DefaultRequestContext, settings);  // I do not know how to specify NodeId of Size. 
if (itema.ParentNodeId == null)
{
    Console.WriteLine("ParentNodeId is null.");
    //itema.ParentNodeId = items.NodeId;
}

// create ItemB
settings = new CreateObjectSettings()
{
    ParentNodeId = items.NodeId,
    ReferenceTypeId = ReferenceTypeIds.HasComponent,
    RequestedNodeId = new NodeId("A1B", InstanceNamespaceIndex),
    BrowseName = new QualifiedName("ItemB", InstanceNamespaceIndex),
    TypeDefinitionId = new NodeId(1u, TypeNamespaceIndex),
};

var itemb = CreateObject(Server.DefaultRequestContext, settings);  // I do not know how to specify NodeId of Size. 
if (itemb.ParentNodeId == null)
{
    Console.WriteLine("ParentNodeId is null.");
    //itemb.ParentNodeId = items.NodeId;
}
When checking on UeExpert, it will be configured as shown below.

Code: Select all

Objects
│
└─SampleA          (ns=4;s="A")
    └─Items        (ns=4;s="A.Items")  ...???
        ├─ItemA    (ns=4;s="A1A")
        │  └─Size (ns=4;s="A1A.Size") ...???
        └─ItemB    (ns=4;s="A1B")
            └─Size (ns=4;s="A1B.Size") ...???

Q2.When trying the code of Q1, it may be "Items.ParentNodeId is null."
Should SampleA.NodeId be set to ParentNodeId?

(ItemA.ParentNodeId is null. Should Items.NodeId be set to ParentNodeId?)
(ItemB.ParentNodeId is null. Should Items.NodeId be set to ParentNodeId?)


Many Thanks

Post Reply