/// <summary> /// Adds a node to the component cache. /// </summary> protected NodeState AddNodeToComponentCache(ISystemContext context, NodeHandle handle, NodeState node) { lock (Lock) { if (handle == null) { return node; } if (m_componentCache == null) { m_componentCache = new Dictionary<NodeId, CacheEntry>(); } // check if a component is actually specified. if (!String.IsNullOrEmpty(handle.ComponentPath)) { CacheEntry entry = null; if (m_componentCache.TryGetValue(handle.RootId, out entry)) { entry.RefCount++; if (!String.IsNullOrEmpty(handle.ComponentPath)) { return entry.Entry.FindChildBySymbolicName(context, handle.ComponentPath); } return entry.Entry; } NodeState root = node.GetHierarchyRoot(); if (root != null) { entry = new CacheEntry(); entry.RefCount = 1; entry.Entry = root; m_componentCache.Add(handle.RootId, entry); } } // simply add the node to the cache. else { CacheEntry entry = null; if (m_componentCache.TryGetValue(handle.NodeId, out entry)) { entry.RefCount++; return entry.Entry; } entry = new CacheEntry(); entry.RefCount = 1; entry.Entry = node; m_componentCache.Add(handle.NodeId, entry); } return node; } }