Exemplo n.º 1
0
        public ContentThread GetThread(Guid id)
        {
            if (AllDictionary.ContainsKey(id))
            {
                return(AllDictionary[id]);
            }

            return(null);
        }
Exemplo n.º 2
0
        public List <ContentTag> GetSubTags(Guid tagId, int topLevel = 0, int bottomLevel = int.MaxValue)
        {
            if (tagId == Guid.Empty || !AllDictionary.ContainsKey(tagId))
            {
                return(null);
            }
            ContentTag parentTag = AllDictionary[tagId];

            if (parentTag == null)
            {
                return(null);
            }
            if (topLevel < 0 || bottomLevel < 0 || topLevel > bottomLevel)
            {
                return(null);
            }

            List <ContentTag>  childTags   = new List <ContentTag>();
            Queue <ContentTag> currentTags = new Queue <ContentTag>();

            currentTags.Enqueue(parentTag);
            currentTags.Enqueue(null);
            int currentLevel = 0;

            while (currentTags.Count > 0)
            {
                ContentTag tag = currentTags.Dequeue();
                if (tag == null)
                {
                    currentLevel++;
                    if (currentLevel > bottomLevel || currentTags.Count == 0 || currentTags.Last() == null)
                    {
                        break;
                    }
                    currentTags.Enqueue(null);
                    continue;
                }

                if (currentLevel >= topLevel && currentLevel <= bottomLevel)
                {
                    childTags.Add(tag);
                }
                if (tag.SubTags != null && tag.SubTags.Count > 0)
                {
                    foreach (var subTag in tag.SubTags)
                    {
                        currentTags.Enqueue(subTag);
                    }
                }
            }

            return(childTags);
        }