Exemplo n.º 1
0
        private IEnumerable <int> GetTagsInLevelRenge(int[] tagIds, int levelRange)
        {
            var tagIdsInRange = new HashSet <int>();

            using (var db = new InnosixEntities())
            {
                var relationTable = db.GetTagHierarchy().ToList();

                foreach (var tagId in tagIds)
                {
                    var nodes = relationTable.Where(x => x.Node.Contains($"/{tagId}/") || (x.TagId == tagId && x.Level > 0));

                    foreach (var node in nodes)
                    {
                        var nodeTagIds = node.Node.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                        var tagIndex = nodeTagIds.IndexOf(tagId.ToString());

                        var indexStart = tagIndex - levelRange;
                        indexStart = indexStart > 0 ? indexStart : 0;

                        var indexEnd = tagIndex + levelRange;
                        indexEnd = indexEnd < nodeTagIds.Length - 1 ? indexEnd : nodeTagIds.Length - 1;

                        for (var i = indexStart; i <= indexEnd; i++)
                        {
                            tagIdsInRange.Add(int.Parse(nodeTagIds[i]));
                        }
                    }
                }
            }
            return(tagIdsInRange);
        }
Exemplo n.º 2
0
        private IEnumerable <int> GetParentTags(int[] tagIds)
        {
            var parentTagIds = new HashSet <int>();

            using (var db = new InnosixEntities())
            {
                var relationTable = db.GetTagHierarchy().ToList();
                var parents       = relationTable.Where(x => tagIds.Any(y => y == x.TagId && x.Level > 0)).ToList();
                foreach (var parent in parents)
                {
                    var node     = parent.Node.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    var parentId = int.Parse(node[node.Length - 2]);
                    parentTagIds.Add(parentId);
                }
            }
            return(parentTagIds);
        }
Exemplo n.º 3
0
        private IEnumerable <int> GetSiblingTags(int[] tagIds)
        {
            var parents = GetParentTags(tagIds);

            var siblingsTagIds = new HashSet <int>();

            using (var db = new InnosixEntities())
            {
                var relationTable = db.GetTagHierarchy().ToList();

                foreach (var parent in parents)
                {
                    var siblings = relationTable.Where(x => x.Node.Contains($"/{parent}/")).ToList();
                    foreach (var sibling in siblings)
                    {
                        var siblingId = GetSiblingIdFromNode(sibling.Node, parent);
                        siblingsTagIds.Add(siblingId);
                    }
                }
            }
            return(siblingsTagIds);
        }