Opc.Ua.Com.Server.ComHdaProxy.UpdateAggregateMappings C# (CSharp) Method

UpdateAggregateMappings() private method

Updates the aggregate mappings.
private UpdateAggregateMappings ( Session session ) : void
session Opc.Ua.Client.Session The session.
return void
        private void UpdateAggregateMappings(Session session)
        {
            // get the list of supported aggregates.
            NodeId objectId = GetAggregateFunctionsObjectId(session);

            // create the updated mapping set.
            NodeIdMappingSet mappingSet = new NodeIdMappingSet();
            mappingSet.MappingType = Opc.Ua.BrowseNames.AggregateFunctions;
            mappingSet.Mappings = new NodeIdMappingCollection();

            List<HdaAggregate> aggregates = GetAggregateFunctions(session, objectId);

            // check for unassigned aggregate ids.
            uint maxId = 0x80000000;

            for (int ii = 0; ii < aggregates.Count; ii++)
            {
                if (aggregates[ii].LocalId != 0)
                {
                    if (maxId < aggregates[ii].LocalId)
                    {
                        maxId = aggregates[ii].LocalId;
                    }

                    continue;
                }
            }

            // assign aggregate ids.
            for (int ii = 0; ii < aggregates.Count; ii++)
            {
                // assign a new id.
                if (aggregates[ii].LocalId == 0)
                {
                    aggregates[ii].LocalId = maxId++;
                }

                // do not add mapping for built-in annotations.
                if (aggregates[ii].LocalId <= (uint)OpcRcw.Hda.OPCHDA_AGGREGATE.OPCHDA_ANNOTATIONS)
                {
                    continue;
                }

                NodeIdMapping mapping = new NodeIdMapping();

                mapping.NodeId = m_mapper.GetLocalItemId(aggregates[ii].RemoteId);
                mapping.IntegerId = aggregates[ii].LocalId;

                mappingSet.Mappings.Add(mapping);
            }

            // update descriptions.
            UpdateAggregateDescriptions(session, aggregates);

            // update configuration.
            if (m_configuration.MappingSets == null)
            {
                m_configuration.MappingSets = new NodeIdMappingSetCollection();
            }

            // replace existing set.
            for (int ii = 0; ii <  m_configuration.MappingSets.Count; ii++)
            {
                if (m_configuration.MappingSets[ii].MappingType == Opc.Ua.BrowseNames.AggregateFunctions)
                {
                    m_configuration.MappingSets[ii] = mappingSet;
                    mappingSet = null;
                    break;
                }
            }

            // add a new set.
            if (mappingSet != null)
            {
                // update the configuration.
                m_configuration.MappingSets.Add(mappingSet);

                // update the mapping table.
                m_mapper.UpdateMappingSet(mappingSet);
            }

            m_aggregates = aggregates;
        }