bool Connect(GraphNodeEdge edge)
        {
            if (edge.input == null || edge.output == null)
            {
                return(false);
            }

            var inputPort  = edge.input as GraphNodePort;
            var outputPort = edge.output as GraphNodePort;
            var inputNode  = inputPort.node as GraphNode;
            var outputNode = outputPort.node as GraphNode;

            if (inputNode == null || outputNode == null)
            {
                return(false);
            }

            owner.AddElement(edge);

            edge.input.Connect(edge);
            edge.output.Connect(edge);

            inputNode.RefreshPorts();
            outputNode.RefreshPorts();

            edge.isConnected = true;

            return(true);
        }
        GraphNodeEdge GetFromCacheOrCreateEdge(GraphNodePort inputPort, GraphNodePort outputPort)
        {
            GraphNodeEdge cacheEdge = graphEdgesCache.FirstOrDefault(e => e.input == inputPort && e.output == outputPort);

            if (cacheEdge != null)
            {
                graphEdgesCache.Remove(cacheEdge);
                graphEdges.Add(cacheEdge);
                return(cacheEdge);
            }
            else
            {
                var edge = new GraphNodeEdge()
                {
                    input  = inputPort,
                    output = outputPort
                };

                Connect(edge);

                graphEdges.Add(edge);
                return(edge);
            }
        }