/// <summary> /// Validates an emphermal node. /// </summary> private NodeState ValidateExternalNode(ISystemContext context, NodeHandle handle) { string uniqueId = handle.RootId.Identifier as string; if (String.IsNullOrEmpty(uniqueId)) { return(null); } // lookup in persistent cache (nodes that are being monitored are in the cache). NodeState target = LookupNodeInComponentCache(context, handle); if (target != null) { return(target); } // validate the external node (normally this means look it up in underlying system). switch (uniqueId) { case "Alpha": case "Omega": { // create the variable. AnalogItemState <double> target2 = new AnalogItemState <double>(null); // instantiate based on the type model. assigns ids automatically using SystemContext.NodeIdFactory target2.Create( SystemContext, handle.RootId, new QualifiedName(uniqueId, NamespaceIndex), null, true); // always allow read/write. target2.AccessLevel = AccessLevels.CurrentReadOrWrite; target2.UserAccessLevel = AccessLevels.CurrentReadOrWrite; target2.StatusCode = StatusCodes.BadWaitingForInitialData; #region Task #D4 - Add Support for Access Control target2.OnReadUserAccessLevel = OnReadUserAccessLevel; #endregion target = target2; break; } default: { return(null); } } // validate component. if (!String.IsNullOrEmpty(handle.ComponentPath)) { NodeState component = target.FindChildBySymbolicName(context, handle.ComponentPath); // component does not exist. if (component == null) { return(null); } target = component; } return(target); }
/// <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 area. if (handle.ParsedNodeId.RootType == ModelUtils.Area) { AreaState area = null; if (!m_areas.TryGetValue(handle.ParsedNodeId.RootId, out area)) { return(null); } root = area; } // validate soucre. else if (handle.ParsedNodeId.RootType == ModelUtils.Source) { SourceState source = null; if (!m_sources.TryGetValue(handle.ParsedNodeId.RootId, out source)) { return(null); } root = source; } // 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> /// 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. DaParsedNodeId parsedNodeId = handle.ParsedNodeId as DaParsedNodeId; if (parsedNodeId == null) { return(null); } NodeState root = null; DaElement element = null; ComDaClient client = m_system.SelectClient(context, false); // validate a branch or item. if (parsedNodeId.RootType == DaModelUtils.DaElement) { element = client.FindElement(parsedNodeId.RootId); // branch does not exist. if (element == null) { return(null); } // create a temporary object to use for the operation. root = DaModelUtils.ConstructElement(context, element, NamespaceIndex); root.Handle = element; AddAdditionalElementReferences(SystemContext, root); } // validate an property. else if (parsedNodeId.RootType == DaModelUtils.DaProperty) { element = client.FindElement(parsedNodeId.RootId); // branch does not exist. if (element == null) { return(null); } // validate the property. DaProperty property = client.FindProperty(parsedNodeId.RootId, parsedNodeId.PropertyId); // property does not exist. if (property == null) { return(null); } // create a temporary object to use for the operation. root = DaModelUtils.ConstructProperty(context, element.ItemId, property, NamespaceIndex); root.Handle = property; AddAdditionalElementReferences(SystemContext, root); } // unknown root type. else { return(null); } // all done if no components to validate. if (String.IsNullOrEmpty(parsedNodeId.ComponentPath)) { handle.Validated = true; handle.Node = target = root; return(handle.Node); } // validate component. NodeState component = root.FindChildBySymbolicName(context, 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); } } }