Opc.Ua.Com.Server.ComAeNamespaceMapper.UpdateEventTypeMappings C# (CSharp) Метод

UpdateEventTypeMappings() приватный Метод

Assigns a locally unique numeric id to each event type.
private UpdateEventTypeMappings ( NodeIdMappingSet mappingSet ) : void
mappingSet NodeIdMappingSet
Результат void
        private void UpdateEventTypeMappings(NodeIdMappingSet mappingSet)
        {
            NodeIdMappingCollection mappingsToKeep = new NodeIdMappingCollection();
            Dictionary<uint, AeEventCategory> categories = new Dictionary<uint, AeEventCategory>();

            for (int ii = 0; ii < mappingSet.Mappings.Count; ii++)
            {
                NodeIdMapping mapping = mappingSet.Mappings[ii];

                try
                {
                    // need to convert the cached type id to a remote id.
                    NodeId localId = NodeId.Parse(mapping.NodeId);
                    NodeId remoteId = this.GetRemoteNodeId(localId);

                    AeEventCategory eventType = null;

                    if (m_eventTypes.TryGetValue(remoteId, out eventType))
                    {
                        // check if the event already has an id.
                        if (eventType.LocalId == 0)
                        {
                            // must update the saved integer id.
                            if (!categories.ContainsKey(mapping.IntegerId))
                            {
                                eventType.LocalId = mapping.IntegerId;
                                categories[eventType.LocalId] = eventType;
                                mappingsToKeep.Add(mapping);
                            }

                            // must assign a new one if a duplicate found.
                            else
                            {
                                eventType.LocalId = 0;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // discard invalid mappings.
                }
            }

            // assign ids to any types which do not have mappings.
            uint nextId = 1;

            foreach (AeEventCategory eventType in m_eventTypes.Values)
            {
                if (eventType.LocalId == 0)
                {
                    // find a unique id.
                    while (categories.ContainsKey(nextId)) nextId++;

                    // assign the id.
                    eventType.LocalId = nextId;
                    categories[eventType.LocalId] = eventType;

                    // save the mapping.
                    NodeIdMapping mapping = new NodeIdMapping();
                    mapping.IntegerId = nextId;
                    mapping.NodeId = this.GetLocalNodeId(eventType.TypeId).ToString();

                    mappingsToKeep.Add(mapping);
                }
            }

            // update mappings.
            mappingSet.Mappings = mappingsToKeep;
            m_categories = categories;
        }