Exemplo n.º 1
0
        private void AddNode(BoCapsule capsule, ObjectNode rootNode)
        {
            var businessObject = capsule.BoModel;

            var uaObject = businessObject.GetType().GetCustomAttribute <UaObject>();

            if (!capsule.IsRegistered())
            {
                var uaObjectName = uaObject.Name ?? businessObject.GetType().Name;
                var nodeIdName   = $"{uaObjectName}_{IncrementCounter()}";
                capsule.BoId = new NodeId(nodeIdName, InstanceNamespaceIndex);

                var node = CreateObject(Server.DefaultRequestContext, new CreateObjectSettings
                {
                    ParentNodeId     = rootNode.NodeId,
                    ReferenceTypeId  = ReferenceTypeIds.Organizes,
                    RequestedNodeId  = new NodeId(nodeIdName, InstanceNamespaceIndex),
                    BrowseName       = new QualifiedName(uaObjectName, InstanceNamespaceIndex),
                    TypeDefinitionId = ObjectTypeIds.BaseObjectType,
                    ParentAsOwner    = true
                });
                Logger.Info($"Created node ... {node.NodeId.Identifier}.");

                foreach (var property in businessObject.GetType().GetProperties())
                {
                    AddVariable(businessObject, property, node);
                    AddUaNodes(businessObject, property, node);
                }

                foreach (var method in businessObject.GetType().GetMethods())
                {
                    AddMethod(businessObject, method, node);
                }
            }
        }
Exemplo n.º 2
0
        public static bool ContainsUaNodes(BoCapsule bo, ref ICollection <object> uaNodeItems)
        {
            foreach (var property in bo.BoModel.GetType().GetProperties())
            {
                var uaObjectListAttribute = property.GetCustomAttribute <UaObjectList>();
                if (uaObjectListAttribute == null)
                {
                    continue;
                }

                uaNodeItems = property.GetValue(bo) as ICollection <object>;
                if (uaNodeItems == null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        internal void CollectAllNodesFromRoot(BoCapsule item, ref List <BoCapsule> allSubNodeIds)
        {
            allSubNodeIds.Add(item);

            ICollection <object> uaNodeItems = null;

            if (!UaReflectionHelper.ContainsUaNodes(item, ref uaNodeItems))
            {
                return;
            }

            foreach (var subItem in uaNodeItems)
            {
                foreach (var bo in BusinessModel)
                {
                    if (subItem != bo.BoModel)
                    {
                        continue;
                    }
                    CollectAllNodesFromRoot(bo, ref allSubNodeIds);
                }
            }
        }
Exemplo n.º 4
0
 protected bool Equals(BoCapsule other)
 {
     return(Equals(BoId, other.BoId));
 }