Opc.Ua.Com.Server.ComDaBrowseCache.GetPropertyValues C# (CSharp) Method

GetPropertyValues() public method

Gets the properties.
public GetPropertyValues ( Session session, ComDaReadPropertiesRequest requests ) : IList
session Opc.Ua.Client.Session The session.
requests ComDaReadPropertiesRequest The requests.
return IList
        public IList<DaProperty> GetPropertyValues(Session session, ComDaReadPropertiesRequest[] requests, params int[] propertyIds)
        {
            TraceState("GetPropertyValues", requests.Length);

            // select all supported properties if none provided
            IList<DaProperty> properties = s_SupportedProperties;

            if (propertyIds == null || propertyIds.Length == 0)
            {
                propertyIds = new int[s_SupportedProperties.Length];

                for (int ii = 0; ii < propertyIds.Length; ii++)
                {
                    propertyIds[ii] = s_SupportedProperties[ii].PropertyId;
                }
            }

            // return the descriptions that match the requested properties.
            else
            {
                properties = new DaProperty[propertyIds.Length];

                for (int ii = 0; ii < propertyIds.Length; ii++)
                {
                    for (int jj = 0; jj < s_SupportedProperties.Length; jj++)
                    {
                        if (propertyIds[ii] == s_SupportedProperties[jj].PropertyId)
                        {
                            properties[ii] = s_SupportedProperties[jj];
                            break;
                        }
                    }
                }
            }

            // build a list of elements to create.
            BrowseElement[] elements = new BrowseElement[requests.Length];
            int[] indexes = new int[requests.Length];

            BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();

            for (int ii = 0; ii < requests.Length; ii++)
            {
                BrowseElement element = null;

                // lookup element in cache.
                lock (m_lock)
                {
                    string itemId = requests[ii].ItemId;

                    if (String.IsNullOrEmpty(itemId))
                    {
                        requests[ii].Error = ResultIds.E_INVALIDITEMID;
                        elements[ii] = null;
                        continue;
                    }

                    // if (m_cache.TryGetValue(itemId, out element))
                    // {
                    //    UpdateReadPropertyRequest(requests[ii], element, propertyIds);
                    //    continue;
                    // }

                    // create a new element.
                    elements[ii] = element = new BrowseElement();
                }

                element.ItemId = requests[ii].ItemId;
                element.NodeId = m_mapper.GetRemoteNodeId(element.ItemId);

                // prepare a request to browse the children.
                indexes[ii] = PrepareBrowseElementBrowseRequest(element.NodeId, nodesToBrowse);
            }

            // check if nothing more to do.
            if (nodesToBrowse.Count == 0)
            {
                return properties;
            }

            // browse all elements at once.
            BrowseResultCollection results = Browse(session, nodesToBrowse);

            // validate results and prepare read requests.
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < elements.Length; ii++)
            {
                BrowseElement element = elements[ii];

                if (element == null)
                {
                    continue;
                }

                // update the element with the children found.
                if (!UpdateBrowseElement(element, nodesToBrowse, results, indexes[ii]))
                {
                    requests[ii].Error = ResultIds.E_UNKNOWNITEMID;
                    elements[ii] = null;
                    continue;
                }

                // prepare to read the properties from the server.
                indexes[ii] = PrepareBrowseElementReadRequest(
                    element.NodeId, 
                    element.ReferencesByName, 
                    nodesToRead, 
                    NodeClass.Unspecified,
                    false);
            }

            // check if nothing to do.
            if (nodesToRead.Count == 0)
            {
                return properties;
            }

            // read all child properties at once.
            DataValueCollection values = Read(session, nodesToRead);

            // process results and build final table.
            for (int ii = 0; ii < elements.Length; ii++)
            {
                BrowseElement element = elements[ii];

                if (element == null)
                {
                    continue;
                }

                // update the browse element with the property values.
                if (!UpdateBrowseElement(session.TypeTree, element, nodesToRead, values, NodeClass.Unspecified, false, indexes[ii]))
                {
                    requests[ii].Error = ResultIds.E_UNKNOWNITEMID;
                    continue;
                }

                UpdateReadPropertyRequest(requests[ii], element, propertyIds);

                // save element in cache.
                lock (m_lock)
                {
                    element.CacheTimestamp = DateTime.UtcNow;
                    m_cache[element.ItemId] = element;
                }
            }

            // return the descriptions.
            return properties;
        }
        #endregion