Beispiel #1
0
        /// <summary>
        /// Assigns node ids to the children based on the parent node id.
        /// </summary>
        public void AssignChildNodeIds(ISystemContext context, NodeState parent)
        {
            NodeId parentId = parent.NodeId;

            // check for valid node id.
            if (parentId == null || parentId.IdType != IdType.String)
            {
                return;
            }

            List <BaseInstanceState> children = new List <BaseInstanceState>();

            parent.GetChildren(context, children);

            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState child = children[ii];

                if (child.SymbolicName == null)
                {
                    continue;
                }

                StringBuilder builder = new StringBuilder();

                builder.Append(parentId.Identifier);
                builder.Append(':');
                builder.Append(child.SymbolicName);

                child.NodeId = new NodeId(builder.ToString(), parentId.NamespaceIndex);

                AssignChildNodeIds(context, child);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks if the the child is for its parent.
        /// </summary>
        public bool ValidateChild(ISystemContext context, NodeState node)
        {
            // only need to validate once.
            node.OnValidate = null;

            BaseInstanceState child = node as BaseInstanceState;

            if (child == null)
            {
                return(true);
            }

            // validate the root node.
            NodeState parent = child.Parent;

            while (parent != null)
            {
                BaseInstanceState instance = parent as BaseInstanceState;

                if (instance == null || instance.Parent == null)
                {
                    return(parent.Validate(context));
                }

                parent = instance.Parent;
            }

            return(true);
        }
/// <summary>
/// Finds the child with the specified browse name.
/// </summary>
    protected override BaseInstanceState FindChild(
        ISystemContext context,
        QualifiedName browseName,
        bool createOrReplace,
        BaseInstanceState replacement)
    {
        if (QualifiedName.IsNull(browseName))
        {
            return(null);
        }

        BaseInstanceState instance = null;

        switch (browseName.Name)
        {
            // ListOfFindChildCase
        }

        if (instance != null)
        {
            return(instance);
        }

        return(base.FindChild(context, browseName, createOrReplace, replacement));
    }
 public void FindChildTest()
 {
     using (TestBaseInstanceState _nodeState = new TestBaseInstanceState(null, nameof(_nodeState)))
     {
         BaseInstanceState _child = _nodeState.FindChildTest(new TestSystemContext(), null, true, null);
         Assert.IsNull(_child);
     }
 }
 /// <summary>
 /// Determines whether the specified passive node is in the nodes identifiers collection.
 /// </summary>
 /// <param name="passiveNode">The node to check.</param>
 /// <returns>
 ///     <c>true</c> if the collection contains identifier for the specified passive node; otherwise <c>false</c>.
 /// </returns>
 private bool ContainsKey(BaseInstanceState passiveNode)
 {
     if (m_NodesIdentifiers == null || passiveNode == null)
     {
         return(false);
     }
     return(m_NodesIdentifiers.ContainsKey(Convert.ToUInt32(passiveNode.NodeId.Identifier)));
 }
Beispiel #6
0
 public NodeSelector(nodeSelected method, SystemContext context, BaseInstanceState root)
 {
     this.context    = context;
     this.onSelected = method;
     this.rootNode   = root;
     InitializeComponent();
     this.serverBrowseNodeCTRL1.InitializeView(this.context, new BaseInstanceState[] { this.rootNode });
 }
        void LoadDataSourceAccessRules(ISystemContext context, ToolState tool, DsatsDemo.DataSource.DeclarationType declaration)
        {
            if (declaration == null || declaration.AccessRules == null)
            {
                return;
            }

            BaseInstanceState folder = tool.FindChildBySymbolicName(context, DsatsDemo.BrowseNames.AccessRules);

            if (folder == null)
            {
                return;
            }

            foreach (DsatsDemo.DataSource.AccessRuleType rule in declaration.AccessRules)
            {
                NodeId phaseId = new NodeId("Phases/" + rule.Phase, NamespaceIndex);
                NodeId lockId  = new NodeId("Locks/" + rule.Lock, NamespaceIndex);

                AccessRuleState node = new AccessRuleState(null);
                node.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasComponent;

                node.Create(
                    context,
                    new NodeId(declaration.Path + "/" + declaration.BrowseName + "/AccessRules/" + rule.Phase, NamespaceIndex),
                    new QualifiedName(rule.Phase, NamespaceIndex),
                    null,
                    true);

                node.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, true, folder.NodeId);
                folder.AddReference(Opc.Ua.ReferenceTypeIds.Organizes, false, node.NodeId);

                AddPredefinedNode(context, node);

                NodeState target = FindPredefinedNode(phaseId, typeof(NodeState));

                if (target != null)
                {
                    NodeId referenceTypeId = new NodeId(DsatsDemo.ReferenceTypes.HasPhase, NamespaceIndex);
                    node.AddReference(referenceTypeId, false, target.NodeId);
                    target.AddReference(referenceTypeId, true, node.NodeId);
                }

                target = (DsatsDemo.LockConditionState)FindPredefinedNode(lockId, typeof(DsatsDemo.LockConditionState));

                if (target != null)
                {
                    NodeId referenceTypeId = new NodeId(DsatsDemo.ReferenceTypes.HasLock, NamespaceIndex);
                    node.AddReference(referenceTypeId, false, target.NodeId);
                    target.AddReference(referenceTypeId, true, node.NodeId);
                }

                tool.SetPhaseLock(phaseId, lockId);
            }
        }
        /// <summary>
        /// get all children of a specific node in a server context
        /// </summary>
        /// <param name="parent">node to get children of</param>
        /// <returns>List of children nodes from parent node</returns>
        private IList <BaseInstanceState> getChildren(BaseInstanceState parent)
        {
            IList <BaseInstanceState> children = new List <BaseInstanceState>();

            if (this.context == null)
            {
                throw new Exception("ServerBrowseNodeCTRL: Systemcontext is null");
            }

            parent.GetChildren(this.context, children);
            return(children);
        }
Beispiel #9
0
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            // generate a numeric node id if the node has a parent and no node id assigned.
            BaseInstanceState instance = node as BaseInstanceState;

            if (instance != null && instance.Parent != null)
            {
                return(GenerateNodeId());
            }

            return(node.NodeId);
        }
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            BaseInstanceState instance = node as BaseInstanceState;

            if (instance != null && instance.Parent != null)
            {
                if (instance.Parent.NodeId.IdType == IdType.String)
                {
                    return(ParsedNodeId.CreateIdForComponent(instance, instance.Parent.NodeId.NamespaceIndex));
                }
            }

            return(node.NodeId);
        }
        private bool InstanceDeclaration(BaseInstanceState node)
        {
            if (node.Parent == null)
            {
                return(true);
            }
            BaseInstanceState parent = node.Parent as BaseInstanceState;

            if (parent == null)
            {
                return(false);
            }
            return(InstanceDeclaration(parent));
        }
Beispiel #12
0
        private void addSelectedNodeAsChild(BaseInstanceState parentNode)
        {
            ReferenceDescription selectedNode = this.BrowseCTRL.SelectedNode;

            if (selectedNode.NodeClass == NodeClass.Variable)
            {
                ReadValueId nodeToRead = new ReadValueId();
                nodeToRead.NodeId      = (NodeId)selectedNode.NodeId;
                nodeToRead.AttributeId = Attributes.Value;
                nodeToRead.Handle      = selectedNode;
                ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
                nodesToRead.Add(nodeToRead);

                DataValueCollection      results         = null;
                DiagnosticInfoCollection diagnosticInfos = null;

                this.connectServerCtrl1.Session.Read(null, 0, TimestampsToReturn.Neither, nodesToRead, out results, out diagnosticInfos);
                ClientBase.ValidateResponse(results, nodesToRead);
                ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

                TypeInfo varInfo = TypeInfo.Construct(results[0].Value);

                BaseVariableState varNode = new BaseDataVariableState(parentNode);
                varNode.ValueRank    = varInfo.ValueRank;
                varNode.WrappedValue = results[0].WrappedValue;
                varNode.NodeId       = (NodeId)selectedNode.NodeId;
                varNode.BrowseName   = new QualifiedName(selectedNode.DisplayName.Text, (ushort)m_server.getNamespaceIndex(this.connectServerCtrl1.Session.NamespaceUris.GetString(selectedNode.BrowseName.NamespaceIndex)));
                varNode.DisplayName  = varNode.BrowseName.Name;
                m_server.addNode(varNode, parentNode.NodeId);
                m_server.addVariableConnection(varNode, selectedNode, this.connectServerCtrl1.ServerUrl);
            }
            else
            {
                BaseObjectState child = new BaseObjectState(parentNode);
                uint            nodeid_ident;
                if (UInt32.TryParse(selectedNode.NodeId.Identifier.ToString(), out nodeid_ident))
                {
                    child.NodeId = new NodeId(nodeid_ident);
                }
                else
                {
                    child.NodeId = new NodeId(selectedNode.NodeId.Identifier.ToString());
                }
                child.BrowseName  = selectedNode.BrowseName;
                child.DisplayName = child.BrowseName.Name;
                this.m_server.addNode(child, parentNode.NodeId);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Recursively populates the data view.
        /// </summary>
        private void PopulateDataView(
            ISystemContext context,
            NodeState parent,
            string parentPath)
        {
            List <BaseInstanceState> children = new List <BaseInstanceState>();

            parent.GetChildren(context, children);

            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState child = children[ii];

                StringBuilder childPath = new StringBuilder();

                if (!String.IsNullOrEmpty(parentPath))
                {
                    childPath.Append(parentPath);
                    childPath.Append("/");
                }

                childPath.Append(child.GetDisplayText());

                if (child.NodeClass == NodeClass.Variable)
                {
                    BaseVariableState variable = (BaseVariableState)child;

                    if (StatusCode.IsGood(variable.StatusCode))
                    {
                        string dataType = m_session.NodeCache.GetDisplayText(variable.DataType);

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

                        DataRow row = m_dataset.Tables[0].NewRow();
                        row[0] = m_dataset.Tables[0].Rows.Count;
                        row[1] = childPath.ToString();
                        row[2] = dataType;
                        row[3] = variable.WrappedValue;
                        m_dataset.Tables[0].Rows.Add(row);
                    }
                }

                PopulateDataView(context, child, childPath.ToString());
            }
        }
Beispiel #14
0
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            BaseInstanceState instance = node as BaseInstanceState;

            if (instance != null && instance.Parent != null)
            {
                string id = instance.Parent.NodeId.Identifier as string;

                if (id != null)
                {
                    return(new NodeId(id + "_" + instance.SymbolicName, instance.Parent.NodeId.NamespaceIndex));
                }
            }

            return(node.NodeId);
        }
Beispiel #15
0
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            BaseInstanceState instance = node as BaseInstanceState;

            if (instance != null && instance.Parent != null)
            {
                ParsedNodeId pnd = ParsedNodeId.Parse(instance.Parent.NodeId);

                if (pnd != null)
                {
                    return(pnd.Construct(instance.SymbolicName));
                }
            }

            return(node.NodeId);
        }
        public void addNode(BaseInstanceState node, NodeId parentId)
        {
            NodeState parent = Find(parentId);

            if (Find(node.NodeId) != null)
            {
                node.NodeId = getFreeNodeId(node.NodeId.NamespaceIndex, node.NodeId.Identifier.GetType() == typeof(int)?(uint)node.NodeId.Identifier:10000);
            }
            parent.AddChild(node);
            AddPredefinedNode(SystemContext, parent);
            parent.AddReference(ReferenceTypes.HasComponent, true, node.NodeId);
            IDictionary <NodeId, List <IReference> > refs = new Dictionary <NodeId, List <IReference> >();
            //IReference iref = parent.ref;
            //refs.Add(parent.NodeId, parent.GetReferences(SystemContext));
            //AddReferences();
        }
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private NodeStateReference NextChild(Stage stage)
        {
            // fetch children.
            if (stage == Stage.Browse)
            {
                if (m_browser == null)
                {
                    return(null);
                }

                BaseInstanceState node = m_browser.Next(SystemContext, m_namespaceIndex);

                if (node != null)
                {
                    return(new NodeStateReference(ReferenceTypeIds.Organizes, false, node));
                }

                // all done.
                return(null);
            }

            // fetch attributes.
            if (stage == Stage.Children)
            {
                if (m_children == null)
                {
                    return(null);
                }

                for (int ii = m_position; ii < m_children.Length;)
                {
                    m_position = ii + 1;
                    return(new NodeStateReference(m_children[ii].ReferenceTypeId, false, m_children[ii]));
                }

                // all done.
                return(null);
            }

            // fetch child parents.
            if (stage == Stage.Parents)
            {
                return(null);
            }

            return(null);
        }
        public ServiceResult OnChangeLockByWrite(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            DsatsDemo.LockConditionState condition = null;

            BaseInstanceState instance = node as BaseInstanceState;

            if (instance.Parent != null)
            {
                condition = instance.Parent as DsatsDemo.LockConditionState;
            }

            if (condition == null)
            {
                return(StatusCodes.BadNotWritable);
            }

            string lockState = value as string;

            if (lockState == null)
            {
                return(StatusCodes.BadTypeMismatch);
            }

            if (lockState == "Locked")
            {
                ServiceResult result = OnRequestLock(context, condition.Request, condition.NodeId, new object[0], new object[0]);
                value = condition.LockStateAsString.Value;
                return(result);
            }

            else if (lockState == "Unlocked")
            {
                ServiceResult result = OnReleaseLock(context, condition.Request, condition.NodeId, new object[0], new object[0]);
                value = condition.LockStateAsString.Value;
                return(result);
            }

            return(StatusCodes.BadTypeMismatch);
        }
Beispiel #19
0
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.
        /// </remarks>
        public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences)
        {
            lock (Lock)
            {
                base.CreateAddressSpace(externalReferences);

                // create the nodes from configuration.
                ushort namespaceIndex = Server.NamespaceUris.GetIndexOrAppend(Namespaces.MemoryBuffer);

                BaseInstanceState root = (BaseInstanceState)FindPredefinedNode(
                    new NodeId(Objects.MemoryBuffers, namespaceIndex),
                    typeof(BaseInstanceState));

                // create the nodes from configuration.
                namespaceIndex = Server.NamespaceUris.GetIndexOrAppend(Namespaces.MemoryBuffer + "/Instance");

                if (m_configuration != null && m_configuration.Buffers != null)
                {
                    for (int ii = 0; ii < m_configuration.Buffers.Count; ii++)
                    {
                        MemoryBufferInstance instance = m_configuration.Buffers[ii];

                        // create a new buffer.
                        MemoryBufferState bufferNode = new MemoryBufferState(SystemContext, instance);

                        // assign node ids.
                        bufferNode.Create(
                            SystemContext,
                            new NodeId(bufferNode.SymbolicName, namespaceIndex),
                            new QualifiedName(bufferNode.SymbolicName, namespaceIndex),
                            null,
                            true);

                        bufferNode.CreateBuffer(instance.DataType, instance.TagCount);
                        bufferNode.InitializeMonitoring(Server, this);

                        // save the buffers for easy look up later.
                        m_buffers[bufferNode.SymbolicName] = bufferNode;

                        // link to root.
                        root.AddChild(bufferNode);
                    }
                }
            }
        }
        /// <summary>
        /// Updates the display name for an instance with the unit label name.
        /// </summary>
        /// <param name="instance">The instance to update.</param>
        /// <param name="unitLabel">The label to apply.</param>
        /// <remarks>This method assumes the DisplayName has the form NameX001 where X0 is the unit label placeholder.</remarks>
        private static void UpdateDisplayName(BaseInstanceState instance, string unitLabel)
        {
            LocalizedText displayName = instance.DisplayName;

            if (displayName != null)
            {
                string text = displayName.Text;

                if (text != null)
                {
                    text = text.Replace("X0", unitLabel);
                }

                displayName = new LocalizedText(displayName.Locale, text);
            }

            instance.DisplayName = displayName;
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case animal.BrowseNames.Weight:
            {
                if (createOrReplace)
                {
                    if (Weight == null)
                    {
                        if (replacement == null)
                        {
                            Weight = new PropertyState <double>(this);
                        }
                        else
                        {
                            Weight = (PropertyState <double>)replacement;
                        }
                    }
                }

                instance = Weight;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case BoilerModel.BrowseNames.BoilerStatus:
            {
                if (createOrReplace)
                {
                    if (BoilerStatus == null)
                    {
                        if (replacement == null)
                        {
                            BoilerStatus = new BaseDataVariableState <BoilerDataType>(this);
                        }
                        else
                        {
                            BoilerStatus = (BaseDataVariableState <BoilerDataType>)replacement;
                        }
                    }
                }

                instance = BoilerStatus;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case VariableTypeTest.BrowseNames.VariableChild:
            {
                if (createOrReplace)
                {
                    if (VariableChild == null)
                    {
                        if (replacement == null)
                        {
                            VariableChild = new PropertyState <int>(this);
                        }
                        else
                        {
                            VariableChild = (PropertyState <int>)replacement;
                        }
                    }
                }

                instance = VariableChild;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Opc.Ua.Di.BrowseNames.ParameterSet:
            {
                if (createOrReplace)
                {
                    if (ParameterSet == null)
                    {
                        if (replacement == null)
                        {
                            ParameterSet = new BaseObjectState(this);
                        }
                        else
                        {
                            ParameterSet = (BaseObjectState)replacement;
                        }
                    }
                }

                instance = ParameterSet;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Opc.Ua.CNC.BrowseNames.CncAxisList:
            {
                if (createOrReplace)
                {
                    if (CncAxisList == null)
                    {
                        if (replacement == null)
                        {
                            CncAxisList = new CncAxisListState(this);
                        }
                        else
                        {
                            CncAxisList = (CncAxisListState)replacement;
                        }
                    }
                }

                instance = CncAxisList;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
Beispiel #26
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case OpcUaChatServer.BrowseNames.ChatLog:
            {
                if (createOrReplace)
                {
                    if (ChatLog == null)
                    {
                        if (replacement == null)
                        {
                            ChatLog = new ChatLogState(this);
                        }
                        else
                        {
                            ChatLog = (ChatLogState)replacement;
                        }
                    }
                }

                instance = ChatLog;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case TutorialModel.BrowseNames.Input:
            {
                if (createOrReplace)
                {
                    if (Input == null)
                    {
                        if (replacement == null)
                        {
                            Input = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            Input = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = Input;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
Beispiel #28
0
        /// <summary>
        /// Constructs the node identifier for a component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        /// <returns>The node identifier for a component.</returns>
        public static NodeId ConstructIdForComponent(NodeState component, ushort namespaceIndex)
        {
            if (component == null)
            {
                return(null);
            }

            // components must be instances with a parent.
            BaseInstanceState instance = component as BaseInstanceState;

            if (instance == null || instance.Parent == null)
            {
                return(component.NodeId);
            }

            // parent must have a string identifier.
            string parentId = instance.Parent.NodeId.Identifier as string;

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

            StringBuilder buffer = new StringBuilder();

            buffer.Append(parentId);

            // check if the parent is another component.
            int index = parentId.IndexOf('?');

            if (index < 0)
            {
                buffer.Append('?');
            }
            else
            {
                buffer.Append('/');
            }

            buffer.Append(component.SymbolicName);

            // return the node identifier.
            return(new NodeId(buffer.ToString(), namespaceIndex));
        }
Beispiel #29
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Quickstarts.SimpleEvents.BrowseNames.Error:
            {
                if (createOrReplace)
                {
                    if (Error == null)
                    {
                        if (replacement == null)
                        {
                            Error = new PropertyState <StatusCode>(this);
                        }
                        else
                        {
                            Error = (PropertyState <StatusCode>)replacement;
                        }
                    }
                }

                instance = Error;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
Beispiel #30
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Quickstarts.SimpleEvents.BrowseNames.Steps:
            {
                if (createOrReplace)
                {
                    if (Steps == null)
                    {
                        if (replacement == null)
                        {
                            Steps = new PropertyState <CycleStepDataType[]>(this);
                        }
                        else
                        {
                            Steps = (PropertyState <CycleStepDataType[]>)replacement;
                        }
                    }
                }

                instance = Steps;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Creates a new instance and assigns unique identifiers to all children.
        /// </summary>
        /// <param name="context">The operation context.</param>
        /// <param name="parentId">An optional parent identifier.</param>
        /// <param name="referenceTypeId">The reference type from the parent.</param>
        /// <param name="browseName">The browse name.</param>
        /// <param name="instance">The instance to create.</param>
        /// <returns>The new node id.</returns>
        public NodeId CreateNode(
            ServerSystemContext context,
            NodeId parentId,
            NodeId referenceTypeId,
            QualifiedName browseName,
            BaseInstanceState instance)
        {
            ServerSystemContext contextToUse = (ServerSystemContext)m_systemContext.Copy(context);

            lock (Lock)
            {
                instance.ReferenceTypeId = referenceTypeId;

                NodeState parent = null;

                if (parentId != null)
                {
                    if (!PredefinedNodes.TryGetValue(parentId, out parent))
                    {
                        throw ServiceResultException.Create(
                            StatusCodes.BadNodeIdUnknown,
                            "Cannot find parent with id: {0}",
                            parentId);
                    }

                    parent.AddChild(instance);
                }

                instance.Create(contextToUse, null, browseName, null, true);
                AddPredefinedNode(contextToUse, instance);

                return instance.NodeId;
            }
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case ObjectTypeTest.BrowseNames.BrowseName4node66:
                {
                    if (createOrReplace)
                    {
                        if (BrowseName4node66 == null)
                        {
                            if (replacement == null)
                            {
                                BrowseName4node66 = new PropertyState<LocalizedText>(this);
                            }
                            else
                            {
                                BrowseName4node66 = (PropertyState<LocalizedText>)replacement;
                            }
                        }
                    }

                    instance = BrowseName4node66;
                    break;
                }

                case ObjectTypeTest.BrowseNames.NameNotSet1109:
                {
                    if (createOrReplace)
                    {
                        if (NameNotSet1109 == null)
                        {
                            if (replacement == null)
                            {
                                NameNotSet1109 = new AnalogItemState(this);
                            }
                            else
                            {
                                NameNotSet1109 = (AnalogItemState)replacement;
                            }
                        }
                    }

                    instance = NameNotSet1109;
                    break;
                }

                case ObjectTypeTest.BrowseNames.ChildMethod:
                {
                    if (createOrReplace)
                    {
                        if (ChildMethod == null)
                        {
                            if (replacement == null)
                            {
                                ChildMethod = new ChildMethodComplexObjectMethodState(this);
                            }
                            else
                            {
                                ChildMethod = (ChildMethodComplexObjectMethodState)replacement;
                            }
                        }
                    }

                    instance = ChildMethod;
                    break;
                }

                case ObjectTypeTest.BrowseNames.NonExecutableMethod:
                {
                    if (createOrReplace)
                    {
                        if (NonExecutableMethod == null)
                        {
                            if (replacement == null)
                            {
                                NonExecutableMethod = new MethodState(this);
                            }
                            else
                            {
                                NonExecutableMethod = (MethodState)replacement;
                            }
                        }
                    }

                    instance = NonExecutableMethod;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }