Esempio n. 1
0
        /// <summary>
        /// Returns a copy of the node
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>A copy of the source node</returns>
        public static Node Copy(ILocalNode source)
        {
            if (source == null)
            {
                return null;
            }

            switch (source.NodeClass)
            {
                case NodeClass.Object: return new ObjectNode(source);
                case NodeClass.Variable: return new VariableNode(source);
                case NodeClass.ObjectType: return new ObjectTypeNode(source);
                case NodeClass.VariableType: return new VariableTypeNode(source);
                case NodeClass.DataType: return new DataTypeNode(source);
                case NodeClass.ReferenceType: return new ReferenceTypeNode(source);
                case NodeClass.Method: return new MethodNode(source);
                case NodeClass.View: return new ViewNode(source);
            }
       
            if (source is IObject) return new ObjectNode(source);
            if (source is IVariable) return new VariableNode(source);
            if (source is IObjectType) return new ObjectTypeNode(source);
            if (source is IVariableType) return new VariableTypeNode(source);
            if (source is IDataType) return new DataTypeNode(source);
            if (source is IReferenceType) return new ReferenceTypeNode(source);
            if (source is IMethod) return new MethodNode(source);
            if (source is IView) return new ViewNode(source);  

            return new Node(source);
        }
Esempio n. 2
0
 public SetPropertyMessageHandler(
     ILocalNode localNode,
     IObjectStorage objectStorage,
     IObjectWithTypeSerializer objectWithTypeSerializer,
     IMessageConstructor messageConstructor,
     IClientLookup clientLookup)
 {
     this.m_LocalNode = localNode;
     this.m_ObjectStorage = objectStorage;
     this.m_ObjectWithTypeSerializer = objectWithTypeSerializer;
     this.m_MessageConstructor = messageConstructor;
     this.m_ClientLookup = clientLookup;
 }
Esempio n. 3
0
 public DefaultObjectLookup(
     ILocalNode localNode,
     IObjectStorage objectStorage,
     IClientLookup clientLookup,
     IMessageConstructor messageConstructor,
     IMessageSideChannel messageSideChannel)
 {
     this.m_LocalNode = localNode;
     this.m_ObjectStorage = objectStorage;
     this.m_ClientLookup = clientLookup;
     this.m_MessageConstructor = messageConstructor;
     this.m_MessageSideChannel = messageSideChannel;
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public Node(ILocalNode source)
        {
            Initialize();

            if (source != null)
            {
                this.NodeId        = source.NodeId;
                this.NodeClass     = source.NodeClass;
                this.BrowseName    = source.BrowseName;
                this.DisplayName   = source.DisplayName;
                this.Description   = source.Description;
                this.WriteMask     = (uint)source.WriteMask;
                this.UserWriteMask = (uint)source.UserWriteMask;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Used by instrumented code to assign the local node context before new calls.
        /// </summary>
        /// <param name="obj">
        /// The object.
        /// </param>
        public static void AssignNodeContext(object obj)
        {
            var transparent = obj as ITransparent;

            if (transparent == null)
            {
                throw new InvalidOperationException();
            }

            if (transparent.Node == null)
            {
                throw new InvalidOperationException("Node not set against distributed object.");
            }

            LocalNodeContext = transparent.Node;
        }
        /// <summary>
        /// Follows the reference from the source and returns all target nodes.
        /// </summary>
        /// <param name="sourceId">The source identifier.</param>
        /// <param name="referenceTypeId">The reference type identifier.</param>
        /// <param name="isInverse">if set to <c>true</c>  this is inverse reference.</param>
        /// <param name="includeSubtypes">if set to <c>true</c> subtypes are included.</param>
        /// <returns>
        /// Returns an empty list if the source does not exist or if there are no matching targets.
        /// </returns>
        public IList <INode> Find(
            ExpandedNodeId sourceId,
            NodeId referenceTypeId,
            bool isInverse,
            bool includeSubtypes)
        {
            // create an empty list.
            IList <INode> nodes = new List <INode>();

            // find the source.
            INode source = InternalFind(sourceId);

            if (source == null)
            {
                return(nodes);
            }

            ILocalNode sourceNode = source as ILocalNode;

            // can't follow references for remote nodes.
            if (sourceNode == null)
            {
                return(nodes);
            }

            // find the references.
            ICollection <IReference> references = sourceNode.References.Find(
                referenceTypeId,
                isInverse,
                includeSubtypes,
                m_typeTree);

            // look for the targets.
            foreach (IReference reference in references)
            {
                INode target = InternalFind(reference.TargetId);

                if (target != null)
                {
                    nodes.Add(target);
                }
            }

            // return list of nodes.
            return(nodes);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds a node to the set after translating all namespace/server indexes in attributes or references.
        /// </summary>
        /// <param name="nodeToExport">The node to export.</param>
        /// <param name="namespaceUris">The namespace URIs.</param>
        /// <param name="serverUris">The server URIs.</param>
        /// <returns>The node.</returns>
        /// <remarks>
        /// Does not add references.
        /// </remarks>
        public Node Add(ILocalNode nodeToExport, NamespaceTable namespaceUris, StringTable serverUris)
        {
            Node node = Node.Copy(nodeToExport);

            node.NodeId     = Translate(nodeToExport.NodeId, m_namespaceUris, namespaceUris);
            node.BrowseName = Translate(nodeToExport.BrowseName, m_namespaceUris, namespaceUris);

            VariableNode variableToExport = nodeToExport as VariableNode;

            if (variableToExport != null)
            {
                VariableNode variableNode = (VariableNode)node;

                object value = TranslateValue(variableNode.Value.Value, namespaceUris, serverUris);
                variableNode.Value = new Variant(value);

                variableNode.DataType = Translate(variableToExport.DataType, m_namespaceUris, namespaceUris);
            }

            VariableTypeNode variableTypeToExport = nodeToExport as VariableTypeNode;

            if (variableTypeToExport != null)
            {
                VariableTypeNode variableTypeNode = (VariableTypeNode)node;

                object value = TranslateValue(variableTypeNode.Value.Value, namespaceUris, serverUris);
                variableTypeNode.Value = new Variant(value);

                variableTypeNode.DataType = Translate(variableTypeToExport.DataType, m_namespaceUris, namespaceUris);
            }

            foreach (IReference referenceToExport in nodeToExport.References)
            {
                ReferenceNode reference = new ReferenceNode();

                reference.ReferenceTypeId = Translate(referenceToExport.ReferenceTypeId, m_namespaceUris, namespaceUris);
                reference.IsInverse       = referenceToExport.IsInverse;
                reference.TargetId        = Translate(referenceToExport.TargetId, m_namespaceUris, m_serverUris, namespaceUris, serverUris);

                node.References.Add(reference);
            }

            Add(node);

            return(node);
        }
Esempio n. 8
0
        /// <summary>
        /// Collects all of the nodes in the hierarchies specified in the configuration file.
        /// </summary>
        protected bool GetNodesInHierarchy()
        {
            // get list of starting nodes.
            IList <NodeId> nodesToBrowse = Configuration.GetNodeList(Configuration.BrowseRoots, this.Session.NamespaceUris);

            if (nodesToBrowse.Count == 0)
            {
                nodesToBrowse.Add(Objects.RootFolder);
            }

            // follow tree from each starting node.
            bool success = true;

            double increment = MaxProgress / nodesToBrowse.Count;
            double position  = 0;

            for (int ii = 0; ii < nodesToBrowse.Count; ii++)
            {
                ILocalNode node = Session.NodeCache.Find(nodesToBrowse[ii]) as ILocalNode;

                if (node != null)
                {
                    Log("Browsing children of '{0}'. NodeId = {1}", node, node.NodeId);

                    try
                    {
                        if (!Browse(Node.Copy(node), position, increment))
                        {
                            success = false;
                        }
                    }
                    catch (Exception e)
                    {
                        success = false;
                        Log(e, "HierarchicalBrowseTest Failed for Node '{0}'. NodeId = {1}", node, node.NodeId);
                    }
                }

                position += increment;
                ReportProgress(position);
            }

            Log("HierarchicalBrowseTest found {0} Nodes", m_availableNodes.Values.Count);
            return(success);
        }
Esempio n. 9
0
        /// <inheritdoc/>
        public NodeId FindDataTypeId(NodeId encodingId)
        {
            ILocalNode encoding = Find(encodingId) as ILocalNode;

            if (encoding == null)
            {
                return(NodeId.Null);
            }

            IList <IReference> references = encoding.References.Find(ReferenceTypeIds.HasEncoding, true, true, m_typeTree);

            if (references.Count > 0)
            {
                return(ExpandedNodeId.ToNodeId(references[0].TargetId, m_session.NamespaceUris));
            }

            return(NodeId.Null);
        }
Esempio n. 10
0
 public Graph(IUnitOfWork unitOfWork, ILocalNode localNode, ISerfClient serfClient, IValidator validator,
              ISigning signing, ISync sync, NetworkClient networkClient, ILogger logger)
 {
     _unitOfWork              = unitOfWork;
     _localNode               = localNode;
     _serfClient              = serfClient;
     _validator               = validator;
     _signing                 = signing;
     _sync                    = sync;
     _logger                  = logger;
     _pooledBlockGraphs       = new PooledList <BlockGraph>(MaxBlockGraphs);
     _trackingBlockGraphAdded = Observable.FromEventPattern <BlockGraphEventArgs>(
         ev => _blockGraphAddedEventHandler        += ev, ev => _blockGraphAddedEventHandler -= ev);
     _trackingBlockGraphCompleted                   = Observable.FromEventPattern <BlockGraphEventArgs>(
         ev => _blockGraphAddCompletedEventHandler += ev, ev => _blockGraphAddCompletedEventHandler -= ev);
     TryAddBlockGraphsListener();
     TryAddBlockmaniaListener();
     ReplayLastRound().SafeFireAndForget(exception => { _logger.Here().Error(exception, "Replay error"); });
 }
Esempio n. 11
0
        private void TypeNavigatorCTRL_TypeSelected(object sender, TypeNavigatorEventArgs e)
        {
            try
            {
                m_selectedType = e.Node;

                if (m_selectedType != null)
                {
                    TypeHierarchyCTRL.Initialize(m_session, m_selectedType.NodeId);
                }
                else
                {
                    TypeHierarchyCTRL.Initialize(m_session, null);
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Esempio n. 12
0
        /// <inheritdoc/>
        public bool IsEncodingOf(ExpandedNodeId encodingId, ExpandedNodeId datatypeId)
        {
            ILocalNode encoding = Find(encodingId) as ILocalNode;

            if (encoding == null)
            {
                return(false);
            }

            foreach (IReference reference in encoding.References.Find(ReferenceTypeIds.HasEncoding, true, true, m_typeTree))
            {
                if (reference.TargetId == datatypeId)
                {
                    return(true);
                }
            }

            // no match.
            return(false);
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public IList <NodeId> FindSubTypes(ExpandedNodeId typeId)
        {
            ILocalNode type = Find(typeId) as ILocalNode;

            if (type == null)
            {
                return(new List <NodeId>());
            }

            List <NodeId> subtypes = new List <NodeId>();

            foreach (IReference reference in type.References.Find(ReferenceTypeIds.HasSubtype, false, true, m_typeTree))
            {
                if (!reference.TargetId.IsAbsolute)
                {
                    subtypes.Add((NodeId)reference.TargetId);
                }
            }

            return(subtypes);
        }
Esempio n. 14
0
        /// <summary>
        /// Called to process a transition that was found in the machine.
        /// </summary>
        protected virtual void AddTransition(ILocalNode source)
        {
            Transition transition = new Transition(source);

            // save the transition.
            m_transitions.Add(transition);

            // add the from state.
            ILocalNode fromState = NodeManager.GetTargetNode(source.NodeId, ReferenceTypes.FromState, false, true, null);

            if (fromState != null)
            {
                transition.FromState = m_states[fromState.BrowseName];
            }

            // add the to state.
            ILocalNode toState = NodeManager.GetTargetNode(source.NodeId, ReferenceTypes.ToState, false, true, null);

            if (fromState != null)
            {
                transition.ToState = m_states[toState.BrowseName];
            }

            // find all causes.
            foreach (ILocalNode cause in NodeManager.GetLocalNodes(source.NodeId, ReferenceTypes.HasCause, false, true))
            {
                MethodSource method = null;

                if (m_causes.TryGetValue(cause.BrowseName, out method))
                {
                    transition.Causes.Add(method);
                }
            }

            // find all effects.
            foreach (ILocalNode effect in NodeManager.GetLocalNodes(source.NodeId, ReferenceTypes.HasEffect, false, true))
            {
                transition.Effects.Add(effect.NodeId);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Finds the specified node. Returns null if the node does node exist.
        /// </summary>
        /// <param name="nodeId">The node identifier.</param>
        /// <returns></returns>
        private INode InternalFind(ExpandedNodeId nodeId)
        {
            if (nodeId == null)
            {
                return(null);
            }

            // check for remote node.
            if (nodeId.ServerIndex != 0)
            {
                RemoteNode remoteNode = null;

                if (m_remoteNodes.TryGetValue(nodeId, out remoteNode))
                {
                    return(remoteNode);
                }

                return(null);
            }


            // convert to locale node id.
            NodeId localId = ExpandedNodeId.ToNodeId(nodeId, m_namespaceUris);

            if (localId == null)
            {
                return(null);
            }

            ILocalNode node = null;

            if (m_localNodes.TryGetValue(localId, out node))
            {
                return(node);
            }

            // node not found.
            return(null);
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        public void Initialize(Session session, NodeId typeId)
        {
            if (session == null)
            {
                RootBTN.Visible = false;
                return;
            }

            ILocalNode root = session.NodeCache.Find(typeId) as ILocalNode;

            if (root == null)
            {
                RootBTN.Visible = false;
                return;
            }

            m_session = session;

            RootBTN.Text    = Utils.Format("{0}", root.DisplayName);
            RootBTN.Visible = true;
            RootBTN.Tag     = root;
        }
Esempio n. 17
0
        private void RootBTN_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripDropDownButton button = sender as ToolStripDropDownButton;

                if (button == null)
                {
                    return;
                }

                ILocalNode node = button.Tag as ILocalNode;

                if (node == null)
                {
                    return;
                }

                bool found = false;

                for (int ii = 0; ii < TypePathCTRL.Items.Count; ii++)
                {
                    if (Object.ReferenceEquals(TypePathCTRL.Items[ii].Tag, node))
                    {
                        found = true;
                        continue;
                    }

                    if (found)
                    {
                        TypePathCTRL.Items.Remove(TypePathCTRL.Items[ii]);
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Contructs the machine by reading the address space.
        /// </summary>
        protected void ConstructMachine(object configuration)
        {
            m_causes           = new Dictionary <QualifiedName, MethodSource>();
            m_substateMachines = new List <StateMachine>();

            foreach (ILocalNode source in NodeManager.GetLocalNodes(this.NodeId, ReferenceTypeIds.HasComponent, false, true))
            {
                StateMachine substate = source as StateMachine;

                if (substate != null)
                {
                    // substate machines always report events to their parent.
                    substate.ReportEventsToParent = true;
                    m_substateMachines.Add(substate);
                    continue;
                }

                MethodSource cause = source as MethodSource;

                if (cause != null)
                {
                    m_causes.Add(cause.BrowseName, cause);
                    continue;
                }
            }

            ConstructMachineFromType(this.TypeDefinitionId);

            // get the parent state.
            ILocalNode parentState = NodeManager.GetTargetNode(this.NodeId, ReferenceTypes.HasSubStateMachine, false, true, null);

            if (parentState != null)
            {
                m_parentState = parentState.BrowseName;
            }

            GotoInitialState();
        }
Esempio n. 19
0
 public static void Apply(object result, ILocalNode localNode)
 {
     if (result != null)
     {
         if (result is ITransparent)
             (result as ITransparent).Node = localNode;
         else if (result.GetType().IsArray)
         {
             if (typeof(ITransparent).IsAssignableFrom(result.GetType().GetElementType()))
             {
                 foreach (var elem in (IEnumerable)result)
                 {
                     if (elem != null)
                         (elem as ITransparent).Node = localNode;
                 }
             }
             else if (!result.GetType().GetElementType().IsValueType && result.GetType() != typeof(string))
                 throw new InvalidOperationException("Unable to assign local node to result data for " + result.GetType().GetElementType().FullName);
         }
         else if (!result.GetType().IsValueType && result.GetType() != typeof(string))
             throw new InvalidOperationException("Unable to assign local node to result data for " + result.GetType().FullName);
     }
 }
Esempio n. 20
0
        /// <see cref="BaseListCtrl.SelectItems" />
        protected override void SelectItems()
        {
            base.SelectItems();

            ILocalNode node = GetSelectedTag(0) as ILocalNode;

            if (node == null)
            {
                return;
            }

            // update attributes control.
            if (AttributesCTRL != null)
            {
                AttributesCTRL.Initialize(m_session, node.NodeId);
            }

            // update references control.
            if (ReferencesCTRL != null)
            {
                ReferencesCTRL.Initialize(m_session, node.NodeId);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Adds a select clause to the control.
        /// </summary>
        public void AddSelectClause(ReferenceDescription reference)
        {
            if (reference == null)
            {
                return;
            }

            ILocalNode node = m_session.NodeCache.Find(reference.NodeId) as ILocalNode;

            if (node == null)
            {
                return;
            }

            SimpleAttributeOperand clause = new SimpleAttributeOperand();

            clause.TypeDefinitionId = m_session.NodeCache.BuildBrowsePath(node, clause.BrowsePath);
            clause.AttributeId      = Attributes.Value;

            AddItem(clause, "Property", -1);

            AdjustColumns();
        }
Esempio n. 22
0
        /// <summary>
        /// Handles a drop event.
        /// </summary>
        protected override void ItemsLV_DragDrop(object sender, DragEventArgs e)
        {
            try {
                ReferenceDescription reference = e.Data.GetData(typeof(ReferenceDescription)) as ReferenceDescription;

                if (reference == null)
                {
                    return;
                }

                ILocalNode node = m_session.NodeCache.Find(reference.NodeId) as ILocalNode;

                if (node == null)
                {
                    return;
                }

                AddItem(node);

                AdjustColumns();
            } catch (Exception exception) {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <summary cref="NodeSource.UpdateAttributes" />
        protected override void UpdateAttributes(ILocalNode source)
        {
            base.UpdateAttributes(source);

            IVariableType type = source as IVariableType;

            if (type != null)
            {
                if (typeof(T).IsInstanceOfType(type.Value))
                {
                    Value = (T)type.Value;
                }

                DataType        = type.DataType;
                ValueRank       = type.ValueRank;
                ArrayDimensions = null;
                IsAbstract      = type.IsAbstract;

                if (type.ArrayDimensions != null && type.ArrayDimensions.Count > 0)
                {
                    ArrayDimensions = (IList <uint>)Utils.Clone(type.ArrayDimensions);
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Initializes the control with a set of items.
        /// </summary>
        public void Initialize(Session session, ExpandedNodeId nodeId)
        {
            ItemsLV.Items.Clear();
            m_session = session;

            if (m_session == null)
            {
                return;
            }

            ILocalNode node = m_session.NodeCache.Find(nodeId) as ILocalNode;

            if (node == null)
            {
                return;
            }

            IList <IReference> references = null;

            references =
                node.References.Find(ReferenceTypes.NonHierarchicalReferences, false, true, m_session.TypeTree);

            for (int ii = 0; ii < references.Count; ii++)
            {
                AddItem(references[ii]);
            }

            references = node.References.Find(ReferenceTypes.NonHierarchicalReferences, true, true, m_session.TypeTree);

            for (int ii = 0; ii < references.Count; ii++)
            {
                AddItem(references[ii]);
            }

            AdjustColumns();
        }
Esempio n. 25
0
        /// <summary>
        /// Called to process a transition that was found in the machine.
        /// </summary>
        protected virtual void AddTransition(ILocalNode source)
        {
            Transition transition = new Transition(source);

            // save the transition.
            m_transitions.Add(transition);
            
            // add the from state.
            ILocalNode fromState = NodeManager.GetTargetNode(source.NodeId, ReferenceTypes.FromState, false, true, null);
            
            if (fromState != null)
            {
                transition.FromState = m_states[fromState.BrowseName];
            }

            // add the to state.
            ILocalNode toState = NodeManager.GetTargetNode(source.NodeId, ReferenceTypes.ToState, false, true, null);
            
            if (fromState != null)
            {
                transition.ToState = m_states[toState.BrowseName];
            }

            // find all causes.
            foreach (ILocalNode cause in NodeManager.GetLocalNodes(source.NodeId, ReferenceTypes.HasCause, false, true))
            {
                MethodSource method = null;
 
                if (m_causes.TryGetValue(cause.BrowseName, out method))
                {
                    transition.Causes.Add(method);
                }
            }

            // find all effects.
            foreach (ILocalNode effect in NodeManager.GetLocalNodes(source.NodeId, ReferenceTypes.HasEffect, false, true))
            {
                transition.Effects.Add(effect.NodeId);
            }
        }
Esempio n. 26
0
 public SynchronisationStore GetSynchronisationStore(ILocalNode node, string name)
 {
     if (this.m_SyncStore == null)
         this.m_SyncStore = new Distributed<PreprocessedSyncTest_SynchronisedStore>(node, name);
     return this.m_SyncStore;
 }
        /// <summary>
        /// Updates the attributes of the node.
        /// </summary>
        protected virtual void UpdateAttributes(ILocalNode source)
        {
            if (QualifiedName.IsNull(m_browseName))
            {
                m_browseName = source.BrowseName;
            }

            m_displayName   = source.DisplayName;
            m_description   = source.Description;
            m_writeMask     = source.WriteMask;
            m_userWriteMask = source.UserWriteMask;
        }  
        /// <summary>
        /// Builds the relative path from a type to a node.
        /// </summary>
        public NodeId BuildBrowsePath(ILocalNode node, IList<QualifiedName> browsePath)
        {
            NodeId typeId = null;
           
            browsePath.Add(node.BrowseName);

            return typeId;
        }
        /// <summary>
        /// Adds a node to the type table if it is a type and does not already exist. If it exists references are updated.
        /// </summary>
        /// <param name="node">The node.</param>
        public void Add(ILocalNode node)
        {
            // ignore null.
            if (node == null || NodeId.IsNull(node.NodeId))
            {
                return;
            }
            
            // ignore non-types.
            if ((node.NodeClass & (NodeClass.ObjectType | NodeClass.VariableType | NodeClass.ReferenceType | NodeClass.DataType)) == 0)
            {
                return;
            }

            NodeId localsuperTypeId = null;

            // find the supertype.
            ExpandedNodeId superTypeId = node.References.FindTarget(ReferenceTypeIds.HasSubtype, true, false, null, 0);

            if (superTypeId != null)
            {
                localsuperTypeId = ExpandedNodeId.ToNodeId(superTypeId, m_namespaceUris);
                
                if (localsuperTypeId == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
                }              
            }

            lock (m_lock)
            {
                // lookup the supertype.
                TypeInfo superTypeInfo = null;

                if (localsuperTypeId != null)
                {
                    if (!m_nodes.TryGetValue(localsuperTypeId, out superTypeInfo))
                    {
                        throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
                    }
                }

                // create the type info.
                TypeInfo typeInfo = null;

                if (!m_nodes.TryGetValue(node.NodeId, out typeInfo))
                {
                    typeInfo = new TypeInfo();
                    m_nodes.Add(node.NodeId, typeInfo);
                }
                
                // update the info.
                typeInfo.NodeId = node.NodeId;
                typeInfo.SuperType = superTypeInfo;
                typeInfo.Deleted = false;

                // add to supertype.
                if (superTypeInfo != null)
                {
                    superTypeInfo.AddSubType(typeInfo);
                }
                                
                // remove the encodings.
                if (typeInfo.Encodings != null)
                {
                    foreach (NodeId encoding in typeInfo.Encodings)
                    {
                        m_encodings.Remove(encoding);
                    }
                }

                // any new encodings.            
                IList<IReference> encodings = node.References.Find(ReferenceTypeIds.HasEncoding, false, false, null);

                if (encodings.Count > 0)
                {
                    typeInfo.Encodings = new NodeId[encodings.Count];

                    for (int ii = 0; ii < encodings.Count; ii++)
                    {
                        typeInfo.Encodings[ii] = ExpandedNodeId.ToNodeId(encodings[ii].TargetId, m_namespaceUris);
                        m_encodings[typeInfo.Encodings[ii]] = typeInfo;
                    }
                }
                
                // add reference type.
                if ((node.NodeClass & NodeClass.ReferenceType) != 0)
                {
                    if (!QualifiedName.IsNull(typeInfo.BrowseName))
                    {
                        m_referenceTypes.Remove(typeInfo.BrowseName);
                    }
                    
                    typeInfo.BrowseName = node.BrowseName;

                    m_referenceTypes[node.BrowseName] = typeInfo;
                }
            }
        }
Esempio n. 30
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 public TypeNavigatorEventArgs(ILocalNode node)
 {
     m_node = node;
 }
Esempio n. 31
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public VariableNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.Variable;

            IVariable variable = source as IVariable;

            if (variable != null)
            {
                this.DataType = variable.DataType;
                this.ValueRank = variable.ValueRank;
                this.AccessLevel = variable.AccessLevel;
                this.UserAccessLevel = variable.UserAccessLevel;
                this.MinimumSamplingInterval = variable.MinimumSamplingInterval;
                this.Historizing = variable.Historizing;

                object value = variable.Value;

                if (value == null)
                {
                    value = TypeInfo.GetDefaultValue(variable.DataType, variable.ValueRank);
                }

                this.Value = new Variant(value);

                if (variable.ArrayDimensions != null)
                {
                    this.ArrayDimensions = new UInt32Collection(variable.ArrayDimensions);
                }
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Adds a node to the table (takes ownership of the object passed in).
        /// </summary>
        /// <param name="node">The node.</param>
        /// <remarks>
        /// Any existing node is removed.
        /// </remarks>
        public void Attach(ILocalNode node)
        {
            // remove duplicates.
            if (Exists(node.NodeId))
            {
                Remove(node.NodeId);
            }

            // check if importing a node from a XML source (must copy references from References array to ReferenceTable).
            Node serializedNode = node as Node;

            if (serializedNode != null && serializedNode.References.Count > 0 && serializedNode.ReferenceTable.Count == 0)
            {
                // index references.
                foreach (ReferenceNode reference in node.References)
                {
                    // ignore invalid references.
                    if (NodeId.IsNull(reference.ReferenceTypeId) || NodeId.IsNull(reference.TargetId))
                    {
                        continue;
                    }

                    node.References.Add(reference.ReferenceTypeId, reference.IsInverse, reference.TargetId);

                    // see if a remote node needs to be created.
                    if (reference.TargetId.ServerIndex != 0)
                    {
                        RemoteNode remoteNode = Find(reference.TargetId) as RemoteNode;

                        if (remoteNode == null)
                        {
                            remoteNode = new RemoteNode(this, reference.TargetId);
                            InternalAdd(remoteNode);
                        }

                        remoteNode.AddRef();
                    }
                }

                // clear unindexed reference list.
                node.References.Clear();
            }

            // add the node to the table.
            InternalAdd(node);

            // add reverse references.
            foreach (IReference reference in node.References)
            {
                ILocalNode targetNode = Find(reference.TargetId) as ILocalNode;

                if (targetNode == null)
                {
                    continue;
                }

                // type definition and modelling rule references are one way.
                if (reference.ReferenceTypeId != ReferenceTypeIds.HasTypeDefinition && reference.ReferenceTypeId != ReferenceTypeIds.HasModellingRule)
                {
                    targetNode.References.Add(reference.ReferenceTypeId, !reference.IsInverse, node.NodeId);
                }
            }

            // see if it is a type.
            if (m_typeTree != null)
            {
                m_typeTree.Add(node);
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public ViewNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.View;

            IView node = source as IView;

            if (node != null)
            {
                this.EventNotifier = node.EventNotifier;
                this.ContainsNoLoops = node.ContainsNoLoops;
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public DataTypeNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.DataType;

            IDataType node = source as IDataType;

            if (node != null)
            {
                this.IsAbstract = node.IsAbstract;
            }
        }
Esempio n. 35
0
 /// <summary>
 /// Creates a node from another node (copies attributes - not references).
 /// </summary>
 /// <param name="source">The source.</param>
 public InstanceNode(ILocalNode source) : base(source)
 {
 }
Esempio n. 36
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public ObjectNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.Object;

            IObject node = source as IObject;

            if (node != null)
            {
                this.EventNotifier = node.EventNotifier;
            }
        }
Esempio n. 37
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 public Transition(ILocalNode transition)
 {
     m_nodeId = transition.NodeId;
     m_browseName = transition.BrowseName;
     m_displayName = transition.DisplayName;
     m_effects = new List<NodeId>();
     m_causes = new List<MethodSource>();
 }
Esempio n. 38
0
 private ILocalNode GetTargetNode(
     ILocalNode source,
     NodeId referenceTypeId,
     bool isInverse,
     bool includeSubtypes,
     QualifiedName browseName)
 {
     return null;
 }
        /// <summary>
        /// Recursively subscribes to events for the notifiers in the tree.
        /// </summary>
        private void SubscribeToEvents(
            OperationContext    context,
            ILocalNode          node,
            uint                subscriptionId,
            IEventMonitoredItem monitoredItem,
            bool                unsubscribe)
        {
            // find handle associated with the node.
            IEventSource eventSource = node as IEventSource;
            SourceHandle handle = node.Handle as SourceHandle;

            if (handle != null)
            {
                eventSource = handle.Source as IEventSource;            
            }
            
            if (eventSource != null)
            {
                try
                {
                    eventSource.SubscribeToEvents(context, (handle != null)?handle.Handle:null, subscriptionId, monitoredItem, unsubscribe);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error calling SubscribeToEvents on an EventSource.");
                }
            }
    
            // find the child notifiers.
            IList<IReference> references = node.References.Find(ReferenceTypes.HasNotifier, false, true, m_server.TypeTree);

            for (int ii = 0; ii < references.Count; ii++)
            {
                if (!references[ii].TargetId.IsAbsolute)
                {
                    ILocalNode target = GetManagerHandle(references[ii].TargetId) as ILocalNode;

                    if (target == null)
                    {
                        continue;
                    }
                    
                    // only object or views can produce events.
                    if ((target.NodeClass & (NodeClass.Object | NodeClass.View)) == 0)
                    {
                        continue;
                    }

                    SubscribeToEvents(context, target, subscriptionId, monitoredItem, unsubscribe);
                }
            }       
        }
Esempio n. 40
0
 public void AttachNode(ILocalNode node)
 {
 }
Esempio n. 41
0
        void ChildBTN_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripMenuItem menuItem = sender as ToolStripMenuItem;

                if (menuItem == null)
                {
                    return;
                }

                ILocalNode node = menuItem.Tag as ILocalNode;

                if (node == null)
                {
                    return;
                }

                bool found = false;

                for (int ii = 0; ii < TypePathCTRL.Items.Count; ii++)
                {
                    if (Object.ReferenceEquals(TypePathCTRL.Items[ii], menuItem.OwnerItem))
                    {
                        found = true;
                        continue;
                    }

                    if (found)
                    {
                        TypePathCTRL.Items.Remove(TypePathCTRL.Items[ii]);
                    }
                }

                if (!found)
                {
                    return;
                }

                string text = Utils.Format("{0}", node.DisplayName);

                ToolStripDropDownButton button = new ToolStripDropDownButton(text);

                button.DisplayStyle     = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
                button.Name             = Utils.Format("Type{0}BTN", TypePathCTRL.Items.Count);
                button.Size             = new System.Drawing.Size(48, 21);
                button.Text             = Utils.Format("{0}", node.DisplayName);
                button.DropDownOpening += RootBTN_DropDownOpening;
                button.Click           += RootBTN_Click;
                button.Tag              = node;

                TypePathCTRL.Items.Add(button);

                if (m_TypeSelected != null)
                {
                    m_TypeSelected(this, new TypeNavigatorEventArgs(node));
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public MethodNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.Method;

            IMethod node = source as IMethod;

            if (node != null)
            {
                this.Executable = node.Executable;
                this.UserExecutable = node.UserExecutable;
            }
        }
Esempio n. 43
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public ObjectTypeNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.ObjectType;

            IObjectType node = source as IObjectType;

            if (node != null)
            {
                this.IsAbstract = node.IsAbstract;
            }
        }
Esempio n. 44
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public ReferenceTypeNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.ReferenceType;

            IReferenceType node = source as IReferenceType;

            if (node != null)
            {
                this.IsAbstract = node.IsAbstract;
                this.InverseName = node.InverseName;
                this.Symmetric = node.Symmetric;
            }
        }
        /// <summary>
        /// Reads the EU Range for a variable.
        /// </summary>
        private ServiceResult ReadEURange(OperationContext context, ILocalNode node, out Range range)
        {
            range = null;

            IVariable target = GetTargetNode(node, ReferenceTypes.HasProperty, false, true, BrowseNames.EURange) as IVariable;

            if (target == null)
            {
                return StatusCodes.BadNodeIdUnknown;
            }

            range = target.Value as Range;
            
            if (range == null)
            {
                return StatusCodes.BadTypeMismatch;
            }

            return ServiceResult.Good;
        }
        /// <summary>
        /// Instantiates the hierarchy.
        /// </summary>
        private IList <ILocalNode> InstantiateHierarchy(
            ILocalNode root,
            InstanceDeclarationHierarchy hierarchy,
            ref long counter,
            ushort namespaceIndex)
        {
            List <ILocalNode>          nodesToAdd    = new List <ILocalNode>();
            List <HierarchyBrowsePath> nodesToUpdate = new List <HierarchyBrowsePath>();

            // create an instance for each browse path that does not already have one.
            foreach (HierarchyBrowsePath browsePath in hierarchy.BrowsePaths.Values)
            {
                bool updateReferences = browsePath.BrowsePath == "/";

                // find the instance.
                INode instance = m_nodes.Find(browsePath.InstanceId);

                if (instance == null)
                {
                    // do nothing if optional.
                    if (browsePath.IsOptional)
                    {
                        continue;
                    }

                    // find the declaration.
                    ILocalNode declaration = m_nodes.Find(browsePath.DeclarationId) as ILocalNode;

                    if (declaration == null)
                    {
                        continue;
                    }

                    instance = declaration;

                    // check the creation rule.
                    CreationRule creationRule = GetCreationRule(declaration.ModellingRule);

                    // create a new instance is the creation rule is new.
                    if (creationRule == CreationRule.New)
                    {
                        Node newNode = Node.Copy(declaration);
                        newNode.NodeId = new NodeId(Utils.IncrementIdentifier(ref counter), namespaceIndex);
                        instance       = newNode;
                        nodesToAdd.Add(newNode);
                        updateReferences = true;
                    }
                }

                // update the browse path.
                browsePath.InstanceId = instance.NodeId;
                hierarchy.Instances[(NodeId)instance.NodeId] = instance;

                // check if instance can be traced back to root.
                if (!updateReferences)
                {
                    continue;
                }

                nodesToUpdate.Add(browsePath);
            }

            // create the references.
            foreach (HierarchyBrowsePath browsePath in nodesToUpdate)
            {
                if (browsePath.InstanceId != null)
                {
                    InstantiateReferences(browsePath, hierarchy);
                }
            }

            return(nodesToAdd);
        }
        /// <summary>
        /// Initializes the control with a set of items.
        /// </summary>
        public void Initialize(Session session, ExpandedNodeId nodeId)
        {
            ItemsLV.Items.Clear();
            m_session = session;

            if (m_session == null)
            {
                return;
            }

            ILocalNode node = m_session.NodeCache.Find(nodeId) as ILocalNode;

            if (node == null)
            {
                return;
            }

            uint[] attributesIds = Attributes.GetIdentifiers();

            for (int ii = 0; ii < attributesIds.Length; ii++)
            {
                uint attributesId = attributesIds[ii];

                if (!node.SupportsAttribute(attributesId))
                {
                    continue;
                }

                ItemInfo info = new ItemInfo();

                info.NodeId      = node.NodeId;
                info.AttributeId = attributesId;
                info.Name        = Attributes.GetBrowseName(attributesId);
                info.Value       = new DataValue(StatusCodes.BadWaitingForInitialData);

                ServiceResult result = node.Read(null, attributesId, info.Value);

                if (ServiceResult.IsBad(result))
                {
                    info.Value = new DataValue(result.StatusCode);
                }

                AddItem(info);
            }

            IList <IReference> references = node.References.Find(ReferenceTypes.HasProperty, false, true, m_session.TypeTree);

            for (int ii = 0; ii < references.Count; ii++)
            {
                IReference reference = references[ii];

                ILocalNode property = m_session.NodeCache.Find(reference.TargetId) as ILocalNode;

                if (property == null)
                {
                    return;
                }

                ItemInfo info = new ItemInfo();

                info.NodeId      = property.NodeId;
                info.AttributeId = Attributes.Value;
                info.Name        = Utils.Format("{0}", property.DisplayName);
                info.Value       = new DataValue(StatusCodes.BadWaitingForInitialData);

                ServiceResult result = property.Read(null, Attributes.Value, info.Value);

                if (ServiceResult.IsBad(result))
                {
                    info.Value = new DataValue(result.StatusCode);
                }

                AddItem(info);
            }

            UpdateValues();
        }
        /// <summary>
        /// Recursively collects the nodes within a type hierarchy.
        /// </summary>
        private void UpdateInstanceHierarchyWithInstance(
            HierarchyBrowsePath parent,
            ExpandedNodeId instanceId,
            InstanceDeclarationHierarchy hierarchy)
        {
            INode instance = m_nodes.Find(instanceId) as INode;

            // ignore instances not in the address space.
            if (instance == null)
            {
                return;
            }

            // must be an object, variable or method.
            if ((instance.NodeClass & (NodeClass.Object | NodeClass.Variable | NodeClass.Method)) == 0)
            {
                return;
            }

            // construct the browse path that identifies the node.
            string browsePath = null;

            if (parent.BrowsePath == "/")
            {
                browsePath = Utils.Format("/{0}", instance.BrowseName);
            }
            else
            {
                browsePath = Utils.Format("{0}/{1}", parent.BrowsePath, instance.BrowseName);
            }

            // check if the browse path exists in the hierarchy.
            HierarchyBrowsePath child = null;

            if (!hierarchy.BrowsePaths.TryGetValue(browsePath, out child))
            {
                return;
            }

            // update the instance.
            child.InstanceId = instance.NodeId;

            // check if already followed.
            if (hierarchy.Instances.ContainsKey((NodeId)instance.NodeId))
            {
                return;
            }

            // save child.
            hierarchy.Instances.Add((NodeId)instance.NodeId, instance);

            // check for local node.
            ILocalNode localInstance = instance as ILocalNode;

            if (localInstance == null)
            {
                return;
            }

            // follow children.
            foreach (IReference reference in localInstance.References.Find(ReferenceTypeIds.HierarchicalReferences, false, true, m_nodes.TypeTree))
            {
                UpdateInstanceHierarchyWithInstance(child, reference.TargetId, hierarchy);
            }
        }
        /// <summary>
        /// Copies the references from the source.
        /// </summary>
        protected virtual void UpdateReferences(ILocalNode source)
        {
            foreach (IReference reference in source.References)
            {
                // do not update type definition reference.
                if (!reference.IsInverse && reference.ReferenceTypeId == ReferenceTypeIds.HasTypeDefinition)
                {
                    if (m_references.Find(reference.ReferenceTypeId, false, false, null).Count > 0)
                    {
                        continue;
                    }
                }

                m_references.Add(reference.ReferenceTypeId, reference.IsInverse, reference.TargetId);
            }            
        }
        /// <summary>
        /// Recursively builds the full inhierited type hierarchy starting with the top-level type.
        /// </summary>
        private void GetInstanceHierarchyForType(ExpandedNodeId typeId, InstanceDeclarationHierarchy hierarchy)
        {
            // the type must be local to the address space.
            ILocalNode type = m_nodes.Find(typeId) as ILocalNode;

            if (type == null)
            {
                throw ServiceResultException.Create(
                          StatusCodes.BadNodeIdUnknown,
                          "The type is not in the local address space.\r\nNodeId = {0}",
                          typeId);
            }

            // must be an object or variable type.
            if ((type.NodeClass & (NodeClass.ObjectType | NodeClass.VariableType)) == 0)
            {
                throw ServiceResultException.Create(
                          StatusCodes.BadNodeClassInvalid,
                          "The type node is not an ObjectType or VariableType.\r\nNodeId = {0}\r\nNodeClass = {1}",
                          typeId,
                          type.NodeClass);
            }

            // find hierarchy in supertypes first.
            foreach (IReference reference in type.References.Find(ReferenceTypeIds.HasSubtype, true, false, null))
            {
                GetInstanceHierarchyForType(reference.TargetId, hierarchy);
            }

            string browsePath = "/";

            // check if the browse path already exists in the hierarchy.
            HierarchyBrowsePath parent = null;

            if (!hierarchy.BrowsePaths.TryGetValue(browsePath, out parent))
            {
                parent = new HierarchyBrowsePath();

                parent.BrowsePath    = browsePath;
                parent.DeclarationId = type.NodeId;
                parent.InstanceId    = null;
                parent.IsModelParent = true;
                parent.IsOptional    = false;

                // add new browse path to hierarchy.
                hierarchy.BrowsePaths.Add(browsePath, parent);
            }

            // override any declaration specified in a supertype.
            parent.DeclarationId = type.NodeId;
            hierarchy.Declarations[type.NodeId] = parent;

            // follow hierarchial references to nodes with a naming rule of unique or unique optional.
            foreach (IReference reference in type.References.Find(ReferenceTypeIds.HierarchicalReferences, false, true, m_nodes.TypeTree))
            {
                GetInstanceHierarchyForType(parent, reference.TargetId, hierarchy);
            }

            // update references defined in the type.
            foreach (HierarchyBrowsePath declaration in hierarchy.Declarations.Values)
            {
                // the declaration must be local to the address space.
                ILocalNode declarationNode = m_nodes.Find(declaration.DeclarationId) as ILocalNode;

                if (declarationNode == null)
                {
                    continue;
                }

                // process all references.
                foreach (IReference reference in declarationNode.References)
                {
                    UpdateReferenceDeclaration(declaration, reference, hierarchy);
                }
            }
        }
Esempio n. 51
0
        /// <summary>
        /// Collects the instance declarations to display in the control.
        /// </summary>
        private void CollectInstances(ILocalNode parent, string basePath, SortedDictionary <string, InstanceDeclaration> instances)
        {
            if (parent == null)
            {
                return;
            }

            IList <IReference> supertypes = parent.References.Find(
                ReferenceTypeIds.HasSubtype,
                true,
                false,
                m_session.TypeTree);

            for (int ii = 0; ii < supertypes.Count; ii++)
            {
                ILocalNode supertype = m_session.NodeCache.Find(supertypes[ii].TargetId) as ILocalNode;

                if (supertype == null)
                {
                    continue;
                }

                CollectInstances(supertype, basePath, instances);
            }

            IList <IReference> children = parent.References.Find(
                ReferenceTypeIds.HierarchicalReferences,
                false,
                true,
                m_session.TypeTree);

            for (int ii = 0; ii < children.Count; ii++)
            {
                ILocalNode child = m_session.NodeCache.Find(children[ii].TargetId) as ILocalNode;

                if (child == null)
                {
                    continue;
                }

                if (child.NodeClass != NodeClass.Object && child.NodeClass != NodeClass.Variable)
                {
                    continue;
                }

                if (child.ModellingRule != Objects.ModellingRule_Mandatory && child.ModellingRule != Objects.ModellingRule_Optional)
                {
                    continue;
                }

                string displayPath = Utils.Format("{0}", child);

                if (!String.IsNullOrEmpty(basePath))
                {
                    displayPath = Utils.Format("{0}/{1}", basePath, displayPath);
                }

                InstanceDeclaration declaration = new InstanceDeclaration();

                declaration.Instance    = child;
                declaration.DisplayPath = displayPath;
                declaration.Description = Utils.Format("{0}", child.Description);
                declaration.DataType    = String.Empty;

                IVariableBase variable = child as IVariableBase;

                if (variable != null)
                {
                    INode dataType = m_session.NodeCache.Find(variable.DataType);

                    if (dataType != null)
                    {
                        declaration.DataType = Utils.Format("{0}", dataType);
                    }

                    if (variable.ValueRank >= 0)
                    {
                        declaration.DataType += "[]";
                    }
                }

                IObject objectn = child as IObject;

                if (objectn != null)
                {
                    declaration.DataType = "NodeId";
                }

                instances[displayPath] = declaration;
                CollectInstances(child, displayPath, instances);
            }
        }
        /// <summary>
        /// Adds or updates the references
        /// </summary>
        private void InstantiateReferences(
            HierarchyBrowsePath source,
            InstanceDeclarationHierarchy hierarchy)
        {
            // don't add references to nodes that are not owned.
            if (!source.IsModelParent)
            {
                return;
            }

            // get the instance.
            ILocalNode instance = hierarchy.Instances[(NodeId)source.InstanceId] as ILocalNode;

            if (instance == null)
            {
                return;
            }

            // find references for the source.
            foreach (HierarchyReference reference in hierarchy.References)
            {
                // match source browse path.
                if (reference.SourceBrowsePath != source.BrowsePath)
                {
                    continue;
                }

                // check if the target is in the hierarchy.
                HierarchyBrowsePath targetBrowsePath = null;

                // check declaration.
                if (!reference.TargetDeclarationId.IsAbsolute)
                {
                    if (!hierarchy.Declarations.TryGetValue((NodeId)reference.TargetDeclarationId, out targetBrowsePath))
                    {
                        targetBrowsePath = null;
                    }
                }

                // check browse path.
                if (targetBrowsePath == null && reference.TargetBrowsePath != null)
                {
                    if (!hierarchy.BrowsePaths.TryGetValue(reference.TargetBrowsePath, out targetBrowsePath))
                    {
                        targetBrowsePath = null;
                    }
                }

                // type definition references are never relative to the hierarchy.
                if (m_nodes.TypeTree.IsTypeOf(reference.ReferenceTypeId, ReferenceTypeIds.HasTypeDefinition))
                {
                    targetBrowsePath = null;
                }

                // target outside hierarchy.
                if (targetBrowsePath == null)
                {
                    if (reference.TargetDeclarationId != null)
                    {
                        // check for existing type definition.
                        if (reference.ReferenceTypeId == ReferenceTypeIds.HasTypeDefinition)
                        {
                            IList <IReference> existingReferences = instance.References.Find(reference.ReferenceTypeId, false, true, m_nodes.TypeTree);

                            if (existingReferences.Count > 0)
                            {
                                if (m_nodes.TypeTree.IsTypeOf(existingReferences[0].TargetId, reference.TargetDeclarationId))
                                {
                                    continue;
                                }

                                instance.References.RemoveAll(ReferenceTypeIds.HasTypeDefinition, false);
                            }
                        }

                        instance.References.Add(reference.ReferenceTypeId, false, reference.TargetDeclarationId);
                    }

                    continue;
                }

                // target inside hierarchy.
                if (targetBrowsePath.InstanceId != null)
                {
                    instance.References.Add(reference.ReferenceTypeId, false, targetBrowsePath.InstanceId);
                }
            }
        }
Esempio n. 53
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 public State(ILocalNode state)
 {
     m_nodeId = state.NodeId;
     m_browseName = state.BrowseName;
     m_displayName = state.DisplayName;
 }
        /// <summary>
        /// Recursively collects the nodes within a type hierarchy.
        /// </summary>
        private void GetInstanceHierarchyForType(
            HierarchyBrowsePath parent,
            ExpandedNodeId instanceId,
            InstanceDeclarationHierarchy hierarchy)
        {
            // the instance must be local to the address space.
            ILocalNode instance = m_nodes.Find(instanceId) as ILocalNode;

            if (instance == null)
            {
                return;
            }

            // must be an object, variable or method.
            if ((instance.NodeClass & (NodeClass.Object | NodeClass.Variable | NodeClass.Method)) == 0)
            {
                return;
            }

            // get the naming rule.
            NamingRule namingRule = GetNamingRule(instance.ModellingRule);

            // only include instances with unique browse names in the hierarchy.
            if (namingRule != NamingRule.Unique && namingRule != NamingRule.UniqueOptional)
            {
                return;
            }

            // construct the browse path that identifies the node.
            string browsePath = null;

            if (parent.BrowsePath == "/")
            {
                browsePath = Utils.Format("/{0}", instance.BrowseName);
            }
            else
            {
                browsePath = Utils.Format("{0}/{1}", parent.BrowsePath, instance.BrowseName);
            }

            // check if the browse path already exists in the hierarchy.
            HierarchyBrowsePath child = null;

            if (!hierarchy.BrowsePaths.TryGetValue(browsePath, out child))
            {
                child = new HierarchyBrowsePath();

                child.BrowsePath    = browsePath;
                child.DeclarationId = instance.NodeId;
                child.InstanceId    = null;
                child.IsModelParent = false;
                child.IsOptional    = namingRule != NamingRule.Unique;

                // add new browse path to hierarchy.
                hierarchy.BrowsePaths.Add(browsePath, child);
            }

            // override any declaration specified in a supertype.
            child.DeclarationId = instance.NodeId;

            // check if node has been processed via another path.
            HierarchyBrowsePath alternatePath = null;

            if (hierarchy.Declarations.TryGetValue(instance.NodeId, out alternatePath))
            {
                // keep the model parent path as the primary path.
                if (!alternatePath.IsModelParent && child.IsModelParent)
                {
                    hierarchy.Declarations[instance.NodeId] = child;
                }

                // nothing more to do since node has been processed once.
                return;
            }

            // save child.
            hierarchy.Declarations.Add(instance.NodeId, child);



            // follow children.
            foreach (IReference reference in instance.References.Find(ReferenceTypeIds.HierarchicalReferences, false, true, m_nodes.TypeTree))
            {
                GetInstanceHierarchyForType(child, reference.TargetId, hierarchy);
            }
        }
        /// <summary>
        /// Adds a node to the type table if it is a type and does not already exist. If it exists references are updated.
        /// </summary>
        /// <param name="node">The node.</param>
        public void Add(ILocalNode node)
        {
            // ignore null.
            if (node == null || NodeId.IsNull(node.NodeId))
            {
                return;
            }

            // ignore non-types.
            if ((node.NodeClass & (NodeClass.ObjectType | NodeClass.VariableType | NodeClass.ReferenceType | NodeClass.DataType)) == 0)
            {
                return;
            }

            NodeId localsuperTypeId = null;

            // find the supertype.
            ExpandedNodeId superTypeId = node.References.FindTarget(ReferenceTypeIds.HasSubtype, true, false, null, 0);

            if (superTypeId != null)
            {
                localsuperTypeId = ExpandedNodeId.ToNodeId(superTypeId, m_namespaceUris);

                if (localsuperTypeId == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
                }
            }

            lock (m_lock)
            {
                // lookup the supertype.
                TypeInfo superTypeInfo = null;

                if (localsuperTypeId != null)
                {
                    if (!m_nodes.TryGetValue(localsuperTypeId, out superTypeInfo))
                    {
                        throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
                    }
                }

                // create the type info.
                TypeInfo typeInfo = null;

                if (!m_nodes.TryGetValue(node.NodeId, out typeInfo))
                {
                    typeInfo = new TypeInfo();
                    m_nodes.Add(node.NodeId, typeInfo);
                }

                // update the info.
                typeInfo.NodeId    = node.NodeId;
                typeInfo.SuperType = superTypeInfo;
                typeInfo.Deleted   = false;

                // add to supertype.
                if (superTypeInfo != null)
                {
                    superTypeInfo.AddSubType(typeInfo);
                }

                // remove the encodings.
                if (typeInfo.Encodings != null)
                {
                    foreach (NodeId encoding in typeInfo.Encodings)
                    {
                        m_encodings.Remove(encoding);
                    }
                }

                // any new encodings.
                IList <IReference> encodings = node.References.Find(ReferenceTypeIds.HasEncoding, false, false, null);

                if (encodings.Count > 0)
                {
                    typeInfo.Encodings = new NodeId[encodings.Count];

                    for (int ii = 0; ii < encodings.Count; ii++)
                    {
                        typeInfo.Encodings[ii] = ExpandedNodeId.ToNodeId(encodings[ii].TargetId, m_namespaceUris);
                        m_encodings[typeInfo.Encodings[ii]] = typeInfo;
                    }
                }

                // add reference type.
                if ((node.NodeClass & NodeClass.ReferenceType) != 0)
                {
                    if (!QualifiedName.IsNull(typeInfo.BrowseName))
                    {
                        m_referenceTypes.Remove(typeInfo.BrowseName);
                    }

                    typeInfo.BrowseName = node.BrowseName;

                    m_referenceTypes[node.BrowseName] = typeInfo;
                }
            }
        }
Esempio n. 56
0
        /// <summary>
        /// Creates a node from another node (copies attributes - not references).
        /// </summary>
        /// <param name="source">The source.</param>
        public VariableTypeNode(ILocalNode source) : base(source)
        {
            this.NodeClass = NodeClass.VariableType;

            IVariableType node = source as IVariableType;

            if (node != null)
            {
                this.IsAbstract = node.IsAbstract;
                this.Value = new Variant(node.Value);
                this.DataType = node.DataType;
                this.ValueRank = node.ValueRank;

                if (node.ArrayDimensions != null)
                {
                    this.ArrayDimensions = new UInt32Collection(node.ArrayDimensions);
                }
            }
        }
Esempio n. 57
0
 public void ReplaceNode(ILocalNode existingNode, ILocalNode newNode)
 {
 }
Esempio n. 58
0
 /// <summary>
 /// Creates a node from another node (copies attributes - not references).
 /// </summary>
 /// <param name="source">The source.</param>
 public TypeNode(ILocalNode source) : base(source)
 {
 }
Esempio n. 59
0
 public ILocalNode UnreferenceSharedNode(
     ILocalNode source,
     NodeId referenceTypeId,
     bool isInverse,
     QualifiedName browseName)
 {
     return null;
 }
Esempio n. 60
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 public State(ILocalNode state)
 {
     m_nodeId      = state.NodeId;
     m_browseName  = state.BrowseName;
     m_displayName = state.DisplayName;
 }