Stores information about a segment in the system.
Пример #1
0
        /// <summary>
        /// Finds the segments for block.
        /// </summary>
        /// <param name="blockId">The block id.</param>
        /// <returns>The list of segments.</returns>
        public IList <UnderlyingSystemSegment> FindSegmentsForBlock(string blockId)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (String.IsNullOrEmpty(blockId))
                {
                    return(null);
                }

                List <UnderlyingSystemSegment> segments = new List <UnderlyingSystemSegment>();

                // look up the segment in the block path database.
                int length = blockId.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    if (length >= blockPath.Length || blockPath[blockPath.Length - length] != '/')
                    {
                        continue;
                    }

                    if (!blockPath.EndsWith(blockId))
                    {
                        continue;
                    }

                    string segmentPath = blockPath.Substring(0, blockPath.Length - length - 1);

                    // construct segment.
                    UnderlyingSystemSegment segment = new UnderlyingSystemSegment();

                    segment.Id          = segmentPath;
                    segment.SegmentType = null;

                    int index = segmentPath.LastIndexOf('/');

                    if (index == -1)
                    {
                        segment.Name = segmentPath;
                    }
                    else
                    {
                        segment.Name = segmentPath.Substring(0, index);
                    }

                    segments.Add(segment);
                }

                return(segments);
            }
        }
Пример #2
0
        /// <summary>
        /// Returns the segment
        /// </summary>
        /// <param name="segmentPath">The path to the segment.</param>
        /// <returns>The segment. Null if the segment path does not exist.</returns>
        public UnderlyingSystemSegment FindSegment(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (string.IsNullOrEmpty(segmentPath))
                {
                    return(null);
                }

                // extract the seqment name from the path.
                string segmentName = segmentPath;

                int index = segmentPath.LastIndexOf('/');

                if (index != -1)
                {
                    segmentName = segmentName.Substring(index + 1);
                }

                if (string.IsNullOrEmpty(segmentName))
                {
                    return(null);
                }

                // see if there is a block path that includes the segment.
                index = segmentPath.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    if (index >= blockPath.Length || blockPath[index] != '/')
                    {
                        continue;
                    }

                    // segment found - return the info.
                    if (blockPath.StartsWith(segmentPath))
                    {
                        UnderlyingSystemSegment segment = new UnderlyingSystemSegment();

                        segment.Id          = segmentPath;
                        segment.Name        = segmentName;
                        segment.SegmentType = null;

                        return(segment);
                    }
                }

                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SegmentState"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="segment">The segment.</param>
        public SegmentState(ISystemContext context, NodeId nodeId, UnderlyingSystemSegment segment) : base(null)
        {
            m_segmentPath = segment.Id;

            this.TypeDefinitionId = ObjectTypeIds.FolderType;
            this.SymbolicName     = segment.Name;
            this.NodeId           = nodeId;
            this.BrowseName       = new QualifiedName(segment.Name, nodeId.NamespaceIndex);
            this.DisplayName      = new LocalizedText(segment.Name);
            this.Description      = null;
            this.WriteMask        = 0;
            this.UserWriteMask    = 0;
            this.EventNotifier    = EventNotifiers.None;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SegmentState"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="segment">The segment.</param>
        public SegmentState(ISystemContext context, NodeId nodeId, UnderlyingSystemSegment segment) : base(null)
        {
            m_segmentPath = segment.Id;

            this.TypeDefinitionId = ObjectTypeIds.FolderType;
            this.SymbolicName = segment.Name;
            this.NodeId = nodeId;
            this.BrowseName = new QualifiedName(segment.Name, nodeId.NamespaceIndex);
            this.DisplayName = new LocalizedText(segment.Name);
            this.Description = null;
            this.WriteMask = 0;
            this.UserWriteMask = 0;
            this.EventNotifier = EventNotifiers.None;
        }
Пример #5
0
        /// <summary>
        /// Finds the parent segment for the specified segment.
        /// </summary>
        /// <param name="segmentPath">The segment path.</param>
        /// <returns>The segment path for the the parent.</returns>
        public UnderlyingSystemSegment FindParentForSegment(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid segment.
                UnderlyingSystemSegment segment = FindSegment(segmentPath);

                if (segment == null)
                {
                    return(null);
                }

                // check for root segment.
                int index = segmentPath.LastIndexOf('/');

                if (index == -1)
                {
                    return(null);
                }

                // construct the parent.
                UnderlyingSystemSegment parent = new UnderlyingSystemSegment();

                parent.Id          = segmentPath.Substring(0, index);
                parent.SegmentType = null;

                index = parent.Id.LastIndexOf('/');

                if (index == -1)
                {
                    parent.Name = parent.Id;
                }
                else
                {
                    parent.Name = parent.Id.Substring(0, index);
                }


                return(parent);
            }
        }
Пример #6
0
        /// <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));
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Finds the segments belonging to the specified segment.
        /// </summary>
        /// <param name="segmentPath">The path to the segment to search.</param>
        /// <returns>The list of segments found. Null if the segment path does not exist.</returns>
        public IList <UnderlyingSystemSegment> FindSegments(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (String.IsNullOrEmpty(segmentPath))
                {
                    segmentPath = String.Empty;
                }

                Dictionary <string, UnderlyingSystemSegment> segments = new Dictionary <string, UnderlyingSystemSegment>();

                // find all block paths that start with the specified segment.
                int length = segmentPath.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    // check for segment path prefix in block path.
                    if (length > 0)
                    {
                        if (length >= blockPath.Length || blockPath[length] != '/')
                        {
                            continue;
                        }

                        if (!blockPath.StartsWith(segmentPath))
                        {
                            continue;
                        }

                        blockPath = blockPath.Substring(length + 1);
                    }

                    // extract segment name.
                    int index = blockPath.IndexOf('/');

                    if (index != -1)
                    {
                        string segmentName = blockPath.Substring(0, index);

                        if (!segments.ContainsKey(segmentName))
                        {
                            string segmentId = segmentName;

                            if (!String.IsNullOrEmpty(segmentPath))
                            {
                                segmentId  = segmentPath;
                                segmentId += "/";
                                segmentId += segmentName;
                            }

                            UnderlyingSystemSegment segment = new UnderlyingSystemSegment();

                            segment.Id          = segmentId;
                            segment.Name        = segmentName;
                            segment.SegmentType = null;

                            segments.Add(segmentName, segment);
                        }
                    }
                }

                // return list.
                return(new List <UnderlyingSystemSegment>(segments.Values));
            }
        }
Пример #8
0
        /// <summary>
        /// Finds the segments for block.
        /// </summary>
        /// <param name="blockId">The block id.</param>
        /// <returns>The list of segments.</returns>
        public IList<UnderlyingSystemSegment> FindSegmentsForBlock(string blockId)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (String.IsNullOrEmpty(blockId))
                {
                    return null;
                }

                List<UnderlyingSystemSegment> segments = new List<UnderlyingSystemSegment>();

                // look up the segment in the block path database.
                int length = blockId.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    if (length >= blockPath.Length || blockPath[blockPath.Length-length] != '/')
                    {
                        continue;
                    }

                    if (!blockPath.EndsWith(blockId))
                    {
                        continue;
                    }

                    string segmentPath = blockPath.Substring(0, blockPath.Length-length-1);

                    // construct segment.
                    UnderlyingSystemSegment segment = new UnderlyingSystemSegment();

                    segment.Id = segmentPath;
                    segment.SegmentType = null;

                    int index = segmentPath.LastIndexOf('/');

                    if (index == -1)
                    {
                        segment.Name = segmentPath;
                    }
                    else
                    {
                        segment.Name = segmentPath.Substring(0, index);
                    }

                    segments.Add(segment);
                }

                return segments;
            }
        }
Пример #9
0
        /// <summary>
        /// Finds the parent segment for the specified segment.
        /// </summary>
        /// <param name="segmentPath">The segment path.</param>
        /// <returns>The segment path for the the parent.</returns>
        public UnderlyingSystemSegment FindParentForSegment(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid segment.
                UnderlyingSystemSegment segment = FindSegment(segmentPath);

                if (segment == null)
                {
                    return null;
                }

                // check for root segment.
                int index = segmentPath.LastIndexOf('/');

                if (index == -1)
                {
                    return null;
                }
                
                // construct the parent.
                UnderlyingSystemSegment parent = new UnderlyingSystemSegment();

                parent.Id = segmentPath.Substring(0, index);
                parent.SegmentType = null;

                index = parent.Id.LastIndexOf('/');

                if (index == -1)
                {
                    parent.Name = parent.Id;
                }
                else
                {
                    parent.Name = parent.Id.Substring(0, index);
                }


                return parent;
            }
        }
Пример #10
0
        /// <summary>
        /// Finds the segments belonging to the specified segment.
        /// </summary>
        /// <param name="segmentPath">The path to the segment to search.</param>
        /// <returns>The list of segments found. Null if the segment path does not exist.</returns>
        public IList<UnderlyingSystemSegment> FindSegments(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (String.IsNullOrEmpty(segmentPath))
                {
                    segmentPath = String.Empty;
                }

                Dictionary<string,UnderlyingSystemSegment> segments = new Dictionary<string, UnderlyingSystemSegment>();

                // find all block paths that start with the specified segment.
                int length = segmentPath.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    // check for segment path prefix in block path.
                    if (length > 0)
                    {
                        if (length >= blockPath.Length || blockPath[length] != '/')
                        {
                            continue;
                        }

                        if (!blockPath.StartsWith(segmentPath))
                        {
                            continue;
                        }

                        blockPath = blockPath.Substring(length+1);
                    }

                    // extract segment name.
                    int index = blockPath.IndexOf('/');

                    if (index != -1)
                    {
                        string segmentName = blockPath.Substring(0, index);

                        if (!segments.ContainsKey(segmentName))
                        {
                            string segmentId = segmentName;

                            if (!String.IsNullOrEmpty(segmentPath))
                            {
                                segmentId = segmentPath;
                                segmentId += "/";
                                segmentId += segmentName;
                            }

                            UnderlyingSystemSegment segment = new UnderlyingSystemSegment();

                            segment.Id = segmentId;
                            segment.Name = segmentName;
                            segment.SegmentType = null;

                            segments.Add(segmentName, segment);
                        }
                    }
                }

                // return list.
                return new List<UnderlyingSystemSegment>(segments.Values);
            }
        }
Пример #11
0
        /// <summary>
        /// Returns the segment
        /// </summary>
        /// <param name="segmentPath">The path to the segment.</param>
        /// <returns>The segment. Null if the segment path does not exist.</returns>
        public UnderlyingSystemSegment FindSegment(string segmentPath)
        {
            lock (m_lock)
            {
                // check for invalid path.
                if (string.IsNullOrEmpty(segmentPath))
                {
                    return null;
                }

                // extract the seqment name from the path.
                string segmentName = segmentPath;

                int index = segmentPath.LastIndexOf('/');

                if (index != -1)
                {
                    segmentName = segmentName.Substring(index+1);
                }

                if (string.IsNullOrEmpty(segmentName))
                {
                    return null;
                }

                // see if there is a block path that includes the segment.
                index = segmentPath.Length;

                for (int ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    string blockPath = s_BlockPathDatabase[ii];

                    if (index >= blockPath.Length || blockPath[index] != '/')
                    {
                        continue;
                    }

                    // segment found - return the info.
                    if (blockPath.StartsWith(segmentPath))
                    {
                        UnderlyingSystemSegment segment = new UnderlyingSystemSegment();
                        
                        segment.Id = segmentPath;
                        segment.Name = segmentName;
                        segment.SegmentType = null;

                        return segment;
                    }
                }

                return null;
            }
        }
Пример #12
0
        /// <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);
                }
            }
        }