コード例 #1
0
        private JsonItem GetDeepNode(Person person)
        {
            if (_processed.ContainsKey(person))
            {
                return(new JsonItem(_processed[person]));
            }

            var personNode = new JsonItem(Utils.GetPersonDescription(person));

            _processed.Add(person, personNode);

            var marriages = _marriages
                            .Where(x => x.husband_id == person.id || x.wife_id == person.id)
                            .ToList();

            foreach (var marriage in marriages)
            {
                var marriageNode = GetMarriageNode(person, marriage);

                var childrenNodes = GetChildrenNodes(marriage);
                if (childrenNodes != null)
                {
                    marriageNode.AddChildren(childrenNodes.ToArray());
                }

                personNode.AddChildren(marriageNode);
            }

            return(personNode);
        }
コード例 #2
0
        // https://github.com/ErikGartner/dTree
        public JsonItem GetResult()
        {
            Init();

            var topLevelPersonIds   = GetTopLevelPersonIds();
            var topLevelPersonNodes = new List <JsonItem>();

            foreach (var id in topLevelPersonIds)
            {
                var person = _persons.Where(x => x.id == id).Single();
                topLevelPersonNodes.Add(GetDeepNode(person));
            }

            var topNode = new JsonItem("results");

            topNode.AddChildren(topLevelPersonNodes.ToArray());

            var totalDepth = AssignNodeDepthsRecursivelly(topNode);

            return(topNode);
        }