Beispiel #1
0
        public override T Convert(freeGraph source, int depthLimit = 500, IEnumerable <freeGraphNodeBase> rootNodes = null)
        {
            T output = new T();

            output.name = source.Id;

            if (!source.Any())
            {
                return(output);
            }

            List <T>      nodes     = new List <T>();
            List <String> nodeNames = new List <string>();

            Dictionary <T, freeGraphNodeBase> next = new Dictionary <T, freeGraphNodeBase>();

            Boolean run = true;

            foreach (var io in rootNodes)
            {
                var tmp = new T();
                tmp.name = io.name;

                next.Add(tmp, io);
                output.Add(tmp);
            }

            //List<Node> next = new List<Node>();

            // next.AddRange(rootNodes.ConvertList<IObjectWithName,Node>());

            Int32 i = 0;

            while (run)
            {
                Dictionary <T, freeGraphNodeBase> newnext = new Dictionary <T, freeGraphNodeBase>();
                // List<T> newT = new ListItemType<();

                foreach (var pair in next)
                {
                    T tNode = new T();

                    tNode.name = pair.Value.name; // g.Id;

                    foreach (var ln in source.GetLinkedNodes(pair.Value.name, false))
                    {
                        if (!nodeNames.Contains(ln.name))
                        {
                            var tmp = new T();
                            tmp.name = ln.name;

                            newnext.Add(tmp, ln);
                            pair.Key.Add(tmp);
                        }
                        nodeNames.Add(ln.name);
                    }
                }
                i++;
                if (i > depthLimit)
                {
                    run = false;
                    break;
                }
                next = newnext;
                run  = next.Any();
            }

            return(output);
        }