예제 #1
0
        /// <summary>
        /// Assigns the handles to the requests.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="requests">The requests.</param>
        private void AssignHandles(ComHdaClient client, Dictionary <string, HdaSubscribeAttributeRequest> requests)
        {
            List <string> itemIds = null;

            lock (m_lock)
            {
                foreach (KeyValuePair <string, HdaSubscribeAttributeRequest> entry in requests)
                {
                    if (entry.Value.ServerHandle == null)
                    {
                        if (itemIds == null)
                        {
                            itemIds = new List <string>();
                        }

                        itemIds.Add(entry.Key);
                    }
                }
            }

            if (itemIds == null)
            {
                return;
            }

            HdaItem[] items = client.GetItems(itemIds.ToArray());

            lock (m_lock)
            {
                for (int ii = 0; ii < items.Length; ii++)
                {
                    HdaSubscribeAttributeRequest request = null;

                    if (!requests.TryGetValue(itemIds[ii], out request))
                    {
                        continue;
                    }

                    if (items[ii].Error < 0)
                    {
                        request.ServerHandle = null;
                        continue;
                    }

                    request.ServerHandle = items[ii].ServerHandle;
                }
            }
        }
        /// <summary>
        /// Initializes the next stage of browsing.
        /// </summary>
        private void NextStage()
        {
            ComHdaClientManager system = (ComHdaClientManager)this.SystemContext.SystemHandle;
            ComHdaClient        client = (ComHdaClient)system.SelectClient((ServerSystemContext)SystemContext, false);

            // determine which stage is next based on the reference types requested.
            for (Stage next = m_stage + 1; next <= Stage.Done; next++)
            {
                if (next == Stage.Browse)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Children)
                {
                    if (IsRequired(ReferenceTypeIds.HasProperty, false) || IsRequired(ReferenceTypeIds.HasHistoricalConfiguration, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Parents)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, true) || IsRequired(ReferenceTypeIds.HasHistoricalConfiguration, true))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Done)
                {
                    m_stage = next;
                    break;
                }
            }

            // start enumerating areas.
            if (m_stage == Stage.Browse)
            {
                m_browser = null;

                if (m_sourceTypeDefinitionId == Opc.Ua.ObjectTypeIds.FolderType)
                {
                    m_browser = new ComHdaBrowserClient(client, m_itemId);
                }

                return;
            }

            // start enumerating attributes.
            if (m_stage == Stage.Children)
            {
                m_position = 0;
                m_children = null;

                if (m_sourceTypeDefinitionId == Opc.Ua.ObjectTypeIds.FolderType)
                {
                    return;
                }

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

                // check if browsing aggregate functions.
                if (m_sourceBrowseName == Opc.Ua.BrowseNames.AggregateFunctions)
                {
                    if (IsRequired(ReferenceTypeIds.HasComponent, false))
                    {
                        BaseObjectState[] aggregates = client.GetSupportedAggregates(m_namespaceIndex);

                        if (aggregates != null)
                        {
                            children.AddRange(aggregates);
                        }

                        m_children = children.ToArray();
                    }

                    return;
                }

                // must be browsing children of an item.
                HdaItem[] items = client.GetItems(m_itemId);

                if (items[0].Error < 0)
                {
                    return;
                }

                try
                {
                    HdaAttributeValue[] attributes = client.ReadAvailableAttributes(items[0]);

                    if (m_sourceTypeDefinitionId == Opc.Ua.VariableTypeIds.DataItemType)
                    {
                        FindChildrenForHdaItem(client, children, attributes);
                    }

                    if (m_sourceTypeDefinitionId == Opc.Ua.ObjectTypeIds.HistoricalDataConfigurationType)
                    {
                        FindChildrenForHdaItemConfiguration(client, children, attributes);
                    }
                }
                finally
                {
                    client.ReleaseItemHandles(items);
                }

                m_children = children.ToArray();
                return;
            }

            // start enumerating parents.
            if (m_stage == Stage.Parents)
            {
                return;
            }

            // all done.
        }