Ejemplo n.º 1
0
        public DataFlowGraphData GetData()
        {
            var data = new DataFlowGraphData {
                nodes = new List <NodeData>(), edges = new List <EdgeData>()
            };

            foreach (var n in nodes)
            {
                data.nodes.Add(n.GetData());
            }

            foreach (var n in nodes)
            {
                foreach (var e in n.inputEdges)
                {
                    data.edges.Add(new EdgeData
                    {
                        fromIndex = nodes.IndexOf(e.FromNode),
                        fromField = e.FromField.Name,
                        toIndex   = nodes.IndexOf(e.ToNode),
                        toField   = e.ToField.Name
                    });
                }
            }

            return(data);
        }
Ejemplo n.º 2
0
        public void LoadData(DataFlowGraphData data, XLander xLander)
        {
            var ns = new List <Node>();

            foreach (var nodeData in data.nodes)
            {
                var n = Node.Create(xLander, nodeData);
                ns.Add(n);
            }

            var nCnt = ns.Count;

            foreach (var edgeData in data.edges)
            {
                var fi = edgeData.fromIndex;
                var ti = edgeData.toIndex;
                if (fi >= nCnt || ti >= nCnt)
                {
                    continue;
                }
                var fromNode = ns[fi];
                var toNode   = ns[ti];
                if (fromNode == null || toNode == null)
                {
                    continue;
                }
                var fromField = fromNode.GetType().GetField(edgeData.fromField);
                var toField   = toNode.GetType().GetField(edgeData.toField);
                if (fromField == null || toField == null)
                {
                    continue;
                }
                AddEdge(fromNode, fromField, toNode, toField);
            }

            nodes.Clear();
            foreach (var node in ns)
            {
                if (node == null)
                {
                    continue;
                }
                nodes.Add(node);
            }
        }