/// <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 (_lock) {
                // check for invalid path.
                if (string.IsNullOrEmpty(blockId))
                {
                    return(null);
                }

                var segments = new List <UnderlyingSystemSegment>();

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

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

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

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

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

                    // construct segment.
                    var segment = new UnderlyingSystemSegment {
                        Id          = segmentPath,
                        SegmentType = null
                    };

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

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

                    segments.Add(segment);
                }

                return(segments);
            }
        }
        /// <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 (_lock) {
                // check for invalid path.
                if (string.IsNullOrEmpty(segmentPath))
                {
                    return(null);
                }

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

                var 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 (var ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    var blockPath = s_BlockPathDatabase[ii];

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

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

                        return(segment);
                    }
                }

                return(null);
            }
        }
Beispiel #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)
        {
            System.Diagnostics.Contracts.Contract.Assume(context != null);
            SegmentPath = segment.Id;

            TypeDefinitionId = ObjectTypeIds.FolderType;
            SymbolicName     = segment.Name;
            NodeId           = nodeId;
            BrowseName       = new QualifiedName(segment.Name, nodeId.NamespaceIndex);
            DisplayName      = new LocalizedText(segment.Name);
            Description      = null;
            WriteMask        = 0;
            UserWriteMask    = 0;
            EventNotifier    = EventNotifiers.None;
        }
        /// <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 (_lock) {
                // check for invalid segment.
                var segment = FindSegment(segmentPath);

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

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

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

                // construct the parent.
                var parent = new UnderlyingSystemSegment {
                    Id          = segmentPath.Substring(0, index),
                    SegmentType = null
                };

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

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


                return(parent);
            }
        }
        /// <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 (_lock) {
                // check for invalid path.
                if (string.IsNullOrEmpty(segmentPath))
                {
                    segmentPath = string.Empty;
                }

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

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

                for (var ii = 0; ii < s_BlockPathDatabase.Length; ii++)
                {
                    var 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, StringComparison.Ordinal))
                        {
                            continue;
                        }

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

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

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

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

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

                            var segment = new UnderlyingSystemSegment {
                                Id          = segmentId,
                                Name        = segmentName,
                                SegmentType = null
                            };

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

                // return list.
                return(new List <UnderlyingSystemSegment>(segments.Values));
            }
        }