Stores information an element in the DA server address space.
コード例 #1
0
        /// <summary>
        /// Adds a read request for the specified property.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <returns>The new request.</returns>
        private ReadRequest Add(string itemId, DaProperty property)
        {
            if (m_index == null)
            {
                m_index = new Dictionary <string, ReadRequest>();
            }

            if (!String.IsNullOrEmpty(property.ItemId))
            {
                return(Add(property.ItemId));
            }

            return(Add(itemId, property.PropertyId));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DaPropertyState"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        public DaPropertyState(
            ISystemContext context,
            string itemId,
            DaProperty property,
            ushort namespaceIndex)
            :
            base(null)
        {
            this.TypeDefinitionId = Opc.Ua.VariableTypeIds.DataItemType;
            this.Description      = null;
            this.WriteMask        = 0;
            this.UserWriteMask    = 0;

            if (property != null)
            {
                Initialize(context, itemId, property, namespaceIndex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes the node from the element.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        public void Initialize(ISystemContext context, string itemId, DaProperty property, ushort namespaceIndex)
        {
            m_itemId   = itemId;
            m_property = property;

            if (property == null)
            {
                return;
            }

            this.NodeId           = DaModelUtils.ConstructIdForDaElement(m_itemId, property.PropertyId, namespaceIndex);
            this.BrowseName       = new QualifiedName(property.Name, namespaceIndex);
            this.DisplayName      = new LocalizedText(property.Name);
            this.TypeDefinitionId = Opc.Ua.VariableTypeIds.PropertyType;
            this.Value            = null;
            this.StatusCode       = StatusCodes.BadWaitingForInitialData;
            this.Timestamp        = DateTime.UtcNow;

            bool isArray = false;

            this.DataType        = ComUtils.GetDataTypeId(property.DataType, out isArray);
            this.ValueRank       = (isArray)?ValueRanks.OneOrMoreDimensions:ValueRanks.Scalar;
            this.ArrayDimensions = null;

            // assume that properties with item ids are writeable. the server may still reject the write.
            if (String.IsNullOrEmpty(property.ItemId))
            {
                this.AccessLevel = AccessLevels.CurrentRead;
            }
            else
            {
                this.AccessLevel = AccessLevels.CurrentReadOrWrite;
            }

            this.UserAccessLevel         = this.AccessLevel;
            this.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate;
            this.Historizing             = false;

            // add a reference to the parent node.
            NodeId parentNodeId = DaModelUtils.ConstructIdForDaElement(itemId, -1, namespaceIndex);

            this.AddReference(ReferenceTypeIds.HasProperty, true, parentNodeId);
        }
コード例 #4
0
 /// <summary>
 /// Constructs a property node for a DA property.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="parentId">The parent id.</param>
 /// <param name="property">The property.</param>
 /// <param name="namespaceIndex">Index of the namespace.</param>
 /// <returns>The property node.</returns>
 public static PropertyState ConstructProperty(ISystemContext context, string parentId, DaProperty property, ushort namespaceIndex)
 {
     return new DaPropertyState(context, parentId, property, namespaceIndex);
 }
コード例 #5
0
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            NodeState target = null;

            // check if already in the cache.
            if (cache != null)
            {
                if (cache.TryGetValue(handle.NodeId, out target))
                {
                    // nulls mean a NodeId which was previously found to be invalid has been referenced again.
                    if (target == null)
                    {
                        return(null);
                    }

                    handle.Node      = target;
                    handle.Validated = true;
                    return(handle.Node);
                }

                target = null;
            }

            try
            {
                // check if the node id has been parsed.
                DaParsedNodeId parsedNodeId = handle.ParsedNodeId as DaParsedNodeId;

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

                NodeState   root    = null;
                DaElement   element = null;
                ComDaClient client  = m_system.SelectClient(context, false);

                // validate a branch or item.
                if (parsedNodeId.RootType == DaModelUtils.DaElement)
                {
                    element = client.FindElement(parsedNodeId.RootId);

                    // branch does not exist.
                    if (element == null)
                    {
                        return(null);
                    }

                    // create a temporary object to use for the operation.
                    root        = DaModelUtils.ConstructElement(context, element, NamespaceIndex);
                    root.Handle = element;

                    AddAdditionalElementReferences(SystemContext, root);
                }

                // validate an property.
                else if (parsedNodeId.RootType == DaModelUtils.DaProperty)
                {
                    element = client.FindElement(parsedNodeId.RootId);

                    // branch does not exist.
                    if (element == null)
                    {
                        return(null);
                    }

                    // validate the property.
                    DaProperty property = client.FindProperty(parsedNodeId.RootId, parsedNodeId.PropertyId);

                    // property does not exist.
                    if (property == null)
                    {
                        return(null);
                    }

                    // create a temporary object to use for the operation.
                    root        = DaModelUtils.ConstructProperty(context, element.ItemId, property, NamespaceIndex);
                    root.Handle = property;

                    AddAdditionalElementReferences(SystemContext, root);
                }

                // unknown root type.
                else
                {
                    return(null);
                }

                // all done if no components to validate.
                if (String.IsNullOrEmpty(parsedNodeId.ComponentPath))
                {
                    handle.Validated = true;
                    handle.Node      = target = root;
                    return(handle.Node);
                }

                // validate component.
                NodeState component = root.FindChildBySymbolicName(context, parsedNodeId.ComponentPath);

                // component does not exist.
                if (component == null)
                {
                    return(null);
                }

                // found a valid component.
                handle.Validated = true;
                handle.Node      = target = component;
                return(handle.Node);
            }
            finally
            {
                // store the node in the cache to optimize subsequent lookups.
                if (cache != null)
                {
                    cache.Add(handle.NodeId, target);
                }
            }
        }