/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { // find the top level segments and link them to the ObjectsFolder. IList <UnderlyingSystemSegment> segments = m_system.FindSegments(null); for (int ii = 0; ii < segments.Count; ii++) { // Top level areas need a reference from the Server object. // These references are added to a list that is returned to the caller. // The caller will update the Objects folder node. IList <IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } // construct the NodeId of a segment. NodeId segmentId = ModelUtils.ConstructIdForSegment(segments[ii].Id, NamespaceIndex); // add an organizes reference from the ObjectsFolder to the area. references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, segmentId)); } // start the simulation. m_system.StartSimulation(); } }
/// <summary> /// Populates the browser with references that meet the criteria. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="browser">The browser to populate.</param> protected override void PopulateBrowser(ISystemContext context, NodeBrowser browser) { base.PopulateBrowser(context, browser); // check if the parent segments need to be returned. if (browser.IsRequired(ReferenceTypeIds.Organizes, true)) { UnderlyingSystem system = context.SystemHandle as UnderlyingSystem; if (system == null) { return; } // add reference for parent segment. UnderlyingSystemSegment segment = system.FindParentForSegment(m_segmentPath); if (segment != null) { browser.Add(ReferenceTypeIds.Organizes, true, ModelUtils.ConstructIdForSegment(segment.Id, this.NodeId.NamespaceIndex)); } } }
/// <summary> /// Populates the browser with references that meet the criteria. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="browser">The browser to populate.</param> protected override void PopulateBrowser(ISystemContext context, NodeBrowser browser) { base.PopulateBrowser(context, browser); // check if the parent segments need to be returned. if (browser.IsRequired(ReferenceTypeIds.Organizes, true)) { UnderlyingSystem system = context.SystemHandle as UnderlyingSystem; if (system == null) { return; } // add reference for each segment. IList <UnderlyingSystemSegment> segments = system.FindSegmentsForBlock(m_blockId); for (int ii = 0; ii < segments.Count; ii++) { browser.Add(ReferenceTypeIds.Organizes, true, ModelUtils.ConstructIdForSegment(segments[ii].Id, this.NodeId.NamespaceIndex)); } } }
/// <summary> /// Returns the next child. /// </summary> private IReference NextChild() { UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle; NodeId targetId = null; // check if a specific browse name is requested. if (!QualifiedName.IsNull(base.BrowseName)) { // check if match found previously. if (m_position == Int32.MaxValue) { return(null); } // browse name must be qualified by the correct namespace. if (m_source.BrowseName.NamespaceIndex != base.BrowseName.NamespaceIndex) { return(null); } // look for matching segment. if (m_stage == Stage.Segments && m_segments != null) { for (int ii = 0; ii < m_segments.Count; ii++) { if (base.BrowseName.Name == m_segments[ii].Name) { targetId = ModelUtils.ConstructIdForSegment(m_segments[ii].Id, m_source.NodeId.NamespaceIndex); break; } } } // look for matching block. if (m_stage == Stage.Blocks && m_blocks != null) { for (int ii = 0; ii < m_blocks.Count; ii++) { UnderlyingSystemBlock block = system.FindBlock(m_blocks[ii]); if (block != null && base.BrowseName.Name == block.Name) { targetId = ModelUtils.ConstructIdForBlock(m_blocks[ii], m_source.NodeId.NamespaceIndex); break; } } } m_position = Int32.MaxValue; } // return the child at the next position. else { // look for next segment. if (m_stage == Stage.Segments && m_segments != null) { if (m_position >= m_segments.Count) { return(null); } targetId = ModelUtils.ConstructIdForSegment(m_segments[m_position++].Id, m_source.NodeId.NamespaceIndex); } // look for next block. else if (m_stage == Stage.Blocks && m_blocks != null) { if (m_position >= m_blocks.Count) { return(null); } targetId = ModelUtils.ConstructIdForBlock(m_blocks[m_position++], m_source.NodeId.NamespaceIndex); } } // create reference. if (targetId != null) { return(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId)); } return(null); }
/// <summary> /// Verifies that the specified node exists. /// </summary> protected override NodeState ValidateNode( ServerSystemContext context, NodeHandle handle, IDictionary <NodeId, NodeState> cache) { // not valid if no root. if (handle == null) { return(null); } // check if previously validated. if (handle.Validated) { return(handle.Node); } NodeState target = null; // check if already in the cache. if (cache != null) { if (cache.TryGetValue(handle.NodeId, out target)) { // nulls mean a NodeId which was previously found to be invalid has been referenced again. if (target == null) { return(null); } handle.Node = target; handle.Validated = true; return(handle.Node); } target = null; } try { // check if the node id has been parsed. if (handle.ParsedNodeId == null) { return(null); } NodeState root = null; // validate a segment. if (handle.ParsedNodeId.RootType == ModelUtils.Segment) { UnderlyingSystemSegment segment = m_system.FindSegment(handle.ParsedNodeId.RootId); // segment does not exist. if (segment == null) { return(null); } NodeId rootId = ModelUtils.ConstructIdForSegment(segment.Id, NamespaceIndex); // create a temporary object to use for the operation. root = new SegmentState(context, rootId, segment); } // validate segment. else if (handle.ParsedNodeId.RootType == ModelUtils.Block) { // validate the block. UnderlyingSystemBlock block = m_system.FindBlock(handle.ParsedNodeId.RootId); // block does not exist. if (block == null) { return(null); } NodeId rootId = ModelUtils.ConstructIdForBlock(block.Id, NamespaceIndex); // check for check for blocks that are being currently monitored. BlockState node = null; if (m_blocks.TryGetValue(rootId, out node)) { root = node; } // create a temporary object to use for the operation. else { root = new BlockState(this, rootId, block); } } // unknown root type. else { return(null); } // all done if no components to validate. if (String.IsNullOrEmpty(handle.ParsedNodeId.ComponentPath)) { handle.Validated = true; handle.Node = target = root; return(handle.Node); } // validate component. NodeState component = root.FindChildBySymbolicName(context, handle.ParsedNodeId.ComponentPath); // component does not exist. if (component == null) { return(null); } // found a valid component. handle.Validated = true; handle.Node = target = component; return(handle.Node); } finally { // store the node in the cache to optimize subsequent lookups. if (cache != null) { cache.Add(handle.NodeId, target); } } }
/// <summary> /// Creates the NodeId for the specified node. /// </summary> /// <param name="context">The context.</param> /// <param name="node">The node.</param> /// <returns>The new NodeId.</returns> /// <remarks> /// This method is called by the NodeState.Create() method which initializes a Node from /// the type model. During initialization a number of child nodes are created and need to /// have NodeIds assigned to them. This implementation constructs NodeIds by constructing /// strings. Other implementations could assign unique integers or Guids and save the new /// Node in a dictionary for later lookup. /// </remarks> public override NodeId New(ISystemContext context, NodeState node) { return(ModelUtils.ConstructIdForComponent(node, NamespaceIndex)); }