Esempio n. 1
0
        public static List <GlossaryItem> ArrangeGlossaryItems(List <GlossaryItem> glossaryTerms)
        {
            Queue <GlossaryItem> queue = new Queue <GlossaryItem>();
            List <GlossaryItem>  arrangedGlossaryItems = new List <GlossaryItem>();

            if (glossaryTerms == null)
            {
                return(arrangedGlossaryItems);
            }

            // Enqueue all root terms
            foreach (var term in glossaryTerms)
            {
                if (term.ParentId == null)
                {
                    queue.Enqueue(term);
                }
            }

            // Iterate all terms using breath-first search
            while (queue.Count != 0)
            {
                GlossaryItem term = queue.Dequeue();
                foreach (var t in glossaryTerms)
                {
                    if (t.ParentId != null && t.ParentId.Equals(term.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        queue.Enqueue(t);
                    }
                }
                arrangedGlossaryItems.Add(term);
            }

            return(arrangedGlossaryItems);
        }
Esempio n. 2
0
        public static List <GlossaryItem> GetGlossaries(string csvPath)
        {
            List <GlossaryItem> glossaries = new List <GlossaryItem>();

            using (TextFieldParser parser = new TextFieldParser(csvPath))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                while (!parser.EndOfData)
                {
                    // Process row
                    string[] fields = parser.ReadFields();

                    // Skip the first row and empty rows
                    if (fields == null || fields[0].Equals("ID", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    GlossaryItem glossaryItem = new GlossaryItem
                    {
                        Id           = fields[0],
                        Name         = fields[1],
                        ParentId     = fields[2] == string.Empty ? null : fields[2],
                        Definition   = fields[3],
                        Description  = fields[4],
                        Stakeholders = GetStakeholders(fields[5].Split(';'))
                    };

                    glossaries.Add(glossaryItem);
                }
            }

            return(glossaries);
        }
Esempio n. 3
0
        static bool TermAlreadyExists(GlossaryItem term, out string termLocation)
        {
            termLocation = null;

            if (_existingTermsParentChildrenDictionary.Count == 0)
            {
                return(false);
            }

            List <string> path         = GetNamePathForNewTerms(term.Id);
            List <string> currentLevel = _existingTermsParentChildrenDictionary[string.Empty];

            foreach (string name in path)
            {
                bool match = false;
                if (currentLevel == null)
                {
                    termLocation = null;
                    return(false);
                }

                foreach (var id in currentLevel)
                {
                    if (_existingTermsIdNameDictionary[id].Equals(name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        currentLevel = _existingTermsParentChildrenDictionary.ContainsKey(id) ? _existingTermsParentChildrenDictionary[id] : null;
                        match        = true;
                        termLocation = id;
                        break;
                    }
                }

                if (!match)
                {
                    termLocation = null;
                    return(false);
                }
            }

            return(true);
        }