/// <summary>
        /// Creates and indexes an area defined for the server.
        /// </summary>
        private AreaState CreateAndIndexAreas(AreaState parent, AreaConfiguration configuration)
        {
            // create a unique path to the area.
            var areaPath = Utils.Format("{0}/{1}", (parent != null) ? parent.SymbolicName : string.Empty, configuration.Name);
            var areaId   = ModelUtils.ConstructIdForArea(areaPath, NamespaceIndex);

            // create the object that will be used to access the area and any variables contained within it.
            var area = new AreaState(SystemContext, parent, areaId, configuration);

            _areas[areaPath] = area;

            if (parent != null)
            {
                parent.AddChild(area);
            }

            // create an index any sub-areas defined for the area.
            if (configuration.SubAreas != null)
            {
                for (var ii = 0; ii < configuration.SubAreas.Count; ii++)
                {
                    CreateAndIndexAreas(area, configuration.SubAreas[ii]);
                }
            }

            // add references to sources.
            if (configuration.SourcePaths != null)
            {
                for (var ii = 0; ii < configuration.SourcePaths.Count; ii++)
                {
                    var sourcePath = configuration.SourcePaths[ii];

                    // check if the source already exists because it is referenced by another area.

                    if (!_sources.TryGetValue(sourcePath, out var source))
                    {
                        var sourceId = ModelUtils.ConstructIdForSource(sourcePath, NamespaceIndex);
                        _sources[sourcePath] = source = new SourceState(this, sourceId, sourcePath);
                    }

                    // HasEventSource and HasNotifier control the propagation of event notifications so
                    // they are not like other references. These calls set up a link between the source
                    // and area that will cause events produced by the source to be automatically
                    // propagated to the area.
                    source.AddNotifier(SystemContext, ReferenceTypeIds.HasEventSource, true, area);
                    area.AddNotifier(SystemContext, ReferenceTypeIds.HasEventSource, false, source);
                }
            }

            return(area);
        }
Example #2
0
        /// <summary>
        /// Initializes the area.
        /// </summary>
        public AreaState(
            ISystemContext context,
            AreaState parent,
            NodeId nodeId,
            AreaConfiguration configuration)
            :
            base(parent)
        {
            Initialize(context);

            // initialize the area with the fixed metadata.
            SymbolicName     = configuration.Name;
            NodeId           = nodeId;
            BrowseName       = new QualifiedName(Utils.Format("{0}", configuration.Name), nodeId.NamespaceIndex);
            DisplayName      = BrowseName.Name;
            Description      = null;
            ReferenceTypeId  = ReferenceTypeIds.HasNotifier;
            TypeDefinitionId = ObjectTypeIds.FolderType;
            EventNotifier    = EventNotifiers.SubscribeToEvents;
        }